Creating Python Logo using Python π
Install dependencies
1. Install dependencies
2. Defining characters to color
3. Defining the data structure for the shape
4. Color the characters
The only dependency we have for this is 2. Defining characters to color
3. Defining the data structure for the shape
4. Color the characters
colorama
. It is used to show text with different colors. For example, if you want to show something really important in the code, you can show it using red.
pip
.
pip install colorama
Defining characters to color
We have to define a good length of characters so that we can print the logo with as much space as we want.fgh ="""ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"""
Defining the data structure for the shape
We will define the data structure with color change information in a dictionary. This will contain information about the colors that we are going to use to print the character color logo.final_dict = {
# row: { "column with color change": "color after this coloum"...}
"0": {
"9": Fore.CYAN,
"16": Fore.BLACK
},
"1": {
"6": Fore.CYAN,
"19": Fore.BLACK
},
"2": {
"6": Fore.CYAN,
"8": Fore.BLACK,
"10": Fore.CYAN,
"19": Fore.BLACK
},
"3": {
"6": Fore.CYAN,
"19": Fore.BLACK
},
"4": {
"6": Fore.CYAN,
"19": Fore.BLACK
},
"5": {
"2": Fore.CYAN,
"19": Fore.YELLOW,
"23": Fore.BLACK
},
"6": {
"1": Fore.CYAN,
"19": Fore.YELLOW,
"24": Fore.BLACK
},
"7": {
"1": Fore.CYAN,
"19": Fore.YELLOW,
"24": Fore.BLACK
},
"8": {
"1": Fore.CYAN,
"19": Fore.YELLOW,
"24": Fore.BLACK
},
"9": {
"1": Fore.CYAN,
"11": Fore.YELLOW,
"24": Fore.BLACK
},
"10": {
"1": Fore.CYAN,
"9": Fore.YELLOW,
"24": Fore.BLACK
},
"11": {
"1": Fore.CYAN,
"9": Fore.YELLOW,
"24": Fore.BLACK
},
"12": {
"2": Fore.CYAN,
"11": Fore.YELLOW,
"24": Fore.BLACK
},
"13": {
"3": Fore.CYAN,
"9": Fore.YELLOW,
"23": Fore.BLACK
},
"14": {
"6": Fore.YELLOW,
"19": Fore.BLACK
},
"15": {
"6": Fore.YELLOW,
"19": Fore.BLACK
},
"16": {
"6": Fore.YELLOW,
"15": Fore.BLACK,
"17": Fore.YELLOW,
"19": Fore.BLACK
},
"17": {
"7": Fore.YELLOW,
"18": Fore.BLACK
}
}
Please use Fore.WHITE
if you are not using dark mode and please tell me why arenβt you using the dark mode.
Donβt worry if this doesnβt make any sense as of now. You will see the usage just in a second.
Color the characters
def get_dict_color(row, column, last_color):
row = str(row)
column = str(column)
if final_dict.get(row).get(column):
return final_dict.get(row).get(column)
return last_color
row = 0
last_color = Fore.BLACK
for b in fgh.split('\n'):
column = 0
for c in b:
last_color = get_dict_color(row, column, last_color)
print(last_color + c, end="")
column += 1
print('\n', end="")
row += 1
if row == 18:
break
fgh
variables which contain all the characters.
In each row of characters for each column of characters, we are calling the get_dict_color
function which either returns the new color if the color is changing according to the defined data structure or returns the last color, we were using.
Run the program. You will get a Python logo of your own.
There might be a lot of implementations that we can use to print something like this, and we would like to hear about it in the comments below.
Please subscribe to the newsletter, if you want to read similar stories every week. Also, we would love to hear your Python story.
About Author
Ranvir Singh
Greetings! Ranvir is an Engineering professional with 3+ years of experience in Software development.
Please share your Feedback:
Did you enjoy reading or think it can be improved? Donβt forget to leave your thoughts in the comments section below! If you liked this article, please share it with your friends, and read a few more!