Introduction
Hello and welcome to the copyassignment, today we will learn how to write the Happy Birthday Python Program In Turtle. Let’s say you want to wish Happy Birthday to someone with your Python skills, in that case, the code below can help you to wish Happy Birthday with Python Program In Turtle.
Complete code for Happy Birthday Python Program In Turtle
# Importing turtle library to draw "Happt Birthday" import turtle # Creating our turtle cursor to draw my_turtle_cursor = turtle.Turtle() # Creating a separate Canvas to draw "Happy Birthday" my_turtle_screen = turtle.Screen() # initializing a variable for co-ordinating y_coordinate = -125 # Creating a function to draw a circle on top of stick def draw_circle_on_top_of_stick(fill_color, border_color, x, y, radius): my_turtle_cursor.penup() my_turtle_cursor.pensize(3) # Changing color of our cursor my_turtle_cursor.color(fill_color) # Changing fill color of the cursor my_turtle_cursor.fillcolor(border_color) my_turtle_cursor.goto(x, y) my_turtle_cursor.pendown() my_turtle_cursor.begin_fill() my_turtle_cursor.circle(radius) my_turtle_cursor.end_fill() my_turtle_cursor.getscreen().update() def draw_candle_for_cake(fill_color, border_color, x, y): my_turtle_cursor.penup() # Changing color of our cursor my_turtle_cursor.color(border_color) # Changing fill color of the cursor my_turtle_cursor.fillcolor(fill_color) my_turtle_cursor.goto(x, y) my_turtle_cursor.pendown() my_turtle_cursor.begin_fill() # Drawing the first side of our Candle my_turtle_cursor.forward(25) my_turtle_cursor.left(90) # Drawing the second side of our Candle my_turtle_cursor.forward(60) my_turtle_cursor.left(90) # Drawing the third side of our Candle my_turtle_cursor.forward(25) my_turtle_cursor.left(90) # Drawing the fourth side of our Candle my_turtle_cursor.forward(60) my_turtle_cursor.left(90) my_turtle_cursor.end_fill() my_turtle_cursor.getscreen().update() # Creating a Function to draw stick on the candle def draw_stick_on_candle(fill_color, x, y, cursor_size): my_turtle_cursor.penup() # Changing color of our cursor my_turtle_cursor.color(fill_color) # Changing fill color of the cursor my_turtle_cursor.fillcolor(fill_color) my_turtle_cursor.goto(x, y) my_turtle_cursor.pensize(cursor_size) my_turtle_cursor.begin_fill() my_turtle_cursor.pendown() my_turtle_cursor.right(90) my_turtle_cursor.forward(12) my_turtle_cursor.end_fill() my_turtle_cursor.getscreen().update() def write_happy_inside_circle(text_color, x, y): my_turtle_cursor.penup() # Changing color of our cursor my_turtle_cursor.color(text_color) # Changing fill color of the cursor my_turtle_cursor.goto(x, y) my_turtle_cursor.begin_fill() my_turtle_cursor.pendown() my_turtle_cursor.write("Happy", font=("sans-serif", 26, "bold")) my_turtle_cursor.getscreen().update() def write_birthday_inside_circle(text_color, x, y): my_turtle_cursor.penup() # Changing color of our cursor my_turtle_cursor.color(text_color) # Changing fill color of the cursor my_turtle_cursor.goto(x, y) my_turtle_cursor.begin_fill() my_turtle_cursor.pendown() my_turtle_cursor.write("Birthday", font=("sans-serif", 26, "bold")) my_turtle_cursor.getscreen().update() def draw_stick(fill_color, border_color, x, y): my_turtle_cursor.penup() my_turtle_cursor.pensize(3) # Changing color of our cursor my_turtle_cursor.color(border_color) # Changing fill color of the cursor my_turtle_cursor.fillcolor(fill_color) my_turtle_cursor.goto(x, y) my_turtle_cursor.begin_fill() my_turtle_cursor.pendown() my_turtle_cursor.left(180) my_turtle_cursor.forward(200) my_turtle_cursor.end_fill() my_turtle_cursor.getscreen().update() # Function to draw topping of our cake def draw_toppings_on_cake(fill_color, border_color, x, y, radius): my_turtle_cursor.penup() # Changing color of our cursor my_turtle_cursor.color(border_color) # Changing fill color of the cursor my_turtle_cursor.fillcolor(fill_color) my_turtle_cursor.goto(x, y) my_turtle_cursor.pendown() my_turtle_cursor.begin_fill() # Drawing a circle using circle function my_turtle_cursor.forward(10) my_turtle_cursor.left(90) my_turtle_cursor.circle(radius, extent = 180) my_turtle_cursor.left(90) my_turtle_cursor.forward(10) my_turtle_cursor.end_fill() my_turtle_cursor.getscreen().update() # Creating a Function to draw different layers of a cake def draw_layer_of_the_cake(fill_color, border_color, cursor_size, x, y, width, height): my_turtle_cursor.hideturtle() my_turtle_cursor.penup() my_turtle_cursor.pensize(cursor_size) # Changing color of our cursor my_turtle_cursor.color(border_color) # Changing fill color of the cursor my_turtle_cursor.fillcolor(fill_color) my_turtle_cursor.goto(x, y) my_turtle_cursor.pendown() # Starting the cursor to fill color my_turtle_cursor.begin_fill() for i in range(2): my_turtle_cursor.forward(width) my_turtle_cursor.left(90) my_turtle_cursor.forward(height) my_turtle_cursor.left(90) my_turtle_cursor.end_fill() my_turtle_cursor.setheading(0) my_turtle_cursor.getscreen().update() # Changing the background color of our canvas my_turtle_screen.bgcolor("#FFFDD0") # # Creating an empty list of different parts of our cake parts_of_cake = [] parts_of_cake.append(["#A020F0", "#000000", 3, 30]) parts_of_cake.append(["#55FF55", "#000000", 3, 20]) parts_of_cake.append(["#B87333", "#000000", 3, 60]) # drawing an plate for our cake using draw_layer_of_the_cake() function draw_layer_of_the_cake("#FFC0CB", "#000000", 3, -220, y_coordinate - 70, 400, 10) # Drawing different parts of our cake for parts in parts_of_cake: draw_layer_of_the_cake(parts[0], parts[1], parts[2], -135, y_coordinate - 60, 240, parts[3]) y_coordinate += parts[3] # drawing top topping of our cake draw_toppings_on_cake("#C20067", "#000000", -120, y_coordinate - 60, 10) draw_toppings_on_cake("#FFFF00", "#000000", -80, y_coordinate - 60, 10) draw_toppings_on_cake("#FF0000", "#000000", 25, y_coordinate - 60, 10) draw_toppings_on_cake("#0000FF", "#000000", 59, y_coordinate - 60, 10) # drawing middle topping of our cakes draw_toppings_on_cake("#FFA500", "#000000", -135, y_coordinate - 80, 10) draw_toppings_on_cake("#E4E6EB", "#000000", -135, y_coordinate - 100, 10) draw_toppings_on_cake("#FFA500", "#000000", -135, y_coordinate - 120, 10) draw_toppings_on_cake("#181A18", "#000000", -80, y_coordinate - 80, 10) draw_toppings_on_cake("#0000FF", "#000000", -65, y_coordinate - 110, 10) draw_toppings_on_cake("#FFD700", "#000000", -95, y_coordinate - 140, 10) draw_toppings_on_cake("#181A18", "#000000", 10, y_coordinate - 80, 10) draw_toppings_on_cake("#E4E6EB", "#000000", -20, y_coordinate - 110, 10) draw_toppings_on_cake("#181418", "#000000", 35, y_coordinate - 140, 10) draw_toppings_on_cake("#FFA500", "#000000", 75, y_coordinate - 80, 10) draw_toppings_on_cake("#E4E6EB", "#000000", 75, y_coordinate - 110, 10) draw_toppings_on_cake("#FFD700", "#000000", 75, y_coordinate - 140, 10) # Drawing candle on of our cake using draw_candle_for_cake() function draw_candle_for_cake("#FFF44F", "#000000", -40, y_coordinate - 60) # Drawing stick on top og uou candle draw_stick_on_candle("#181A18", -26, y_coordinate + 15, 7) # Drawing a stick for writing Happy Birthday draw_stick("#181A18", "#181A18", 0, y_coordinate - 60) # Drawing a circle on top of stick draw_circle_on_top_of_stick("#181A18", "#FFFDD0", 100, y_coordinate + 235, 100) # Writing "Happy" inside of our circle write_happy_inside_circle("#000000", -70, y_coordinate + 240) # Writing "Birthday" inside of our circle write_birthday_inside_circle("#000000", -80, y_coordinate + 190) # Calling done function at the end turtle.done()
Output for Happy Birthday Python Program In Turtle:
Now, we will understand all functions and important statements of the Happy Birthday Python Program In Turtle one-by-one-
Step 1: Importing Turtle Library
# Importing turtle library to draw "Happt Birthday"
import turtle
Step 2: Creating a Cursor and a Separate Canvas
# Creating our turtle cursor to draw
my_turtle_cursor = turtle.Turtle()
# Creating a separate Canvas to draw "Happy Birthday"
my_turtle_screen = turtle.Screen()
Step 3: Changing the Background of our Canvas
# Changing the background color of our canvas
my_turtle_screen.bgcolor("#FFFDD0")
Step 4: Creating a Cake with Topping and a Plate
# initializing a variable for co-ordinating
y_coordinate = -125
def draw_candle_for_cake(fill_color, border_color, x, y):
my_turtle_cursor.penup()
# Changing color of our cursor
my_turtle_cursor.color(border_color)
# Changing fill color of the cursor
my_turtle_cursor.fillcolor(fill_color)
my_turtle_cursor.goto(x, y)
my_turtle_cursor.pendown()
my_turtle_cursor.begin_fill()
# Drawing the first side of our Candle
my_turtle_cursor.forward(25)
my_turtle_cursor.left(90)
# Drawing the second side of our Candle
my_turtle_cursor.forward(60)
my_turtle_cursor.left(90)
# Drawing the third side of our Candle
my_turtle_cursor.forward(25)
my_turtle_cursor.left(90)
# Drawing the fourth side of our Candle
my_turtle_cursor.forward(60)
my_turtle_cursor.left(90)
my_turtle_cursor.end_fill()
my_turtle_cursor.getscreen().update()
# Creating a Function to draw stick on the candle
def draw_stick_on_candle(fill_color, x, y, cursor_size):
my_turtle_cursor.penup()
# Changing color of our cursor
my_turtle_cursor.color(fill_color)
# Changing fill color of the cursor
my_turtle_cursor.fillcolor(fill_color)
my_turtle_cursor.goto(x, y)
my_turtle_cursor.pensize(cursor_size)
my_turtle_cursor.begin_fill()
my_turtle_cursor.pendown()
my_turtle_cursor.right(90)
my_turtle_cursor.forward(12)
my_turtle_cursor.end_fill()
my_turtle_cursor.getscreen().update()
# Function to draw topping of our cake
def draw_toppings_on_cake(fill_color, border_color, x, y, radius):
my_turtle_cursor.penup()
# Changing color of our cursor
my_turtle_cursor.color(border_color)
# Changing fill color of the cursor
my_turtle_cursor.fillcolor(fill_color)
my_turtle_cursor.goto(x, y)
my_turtle_cursor.pendown()
my_turtle_cursor.begin_fill()
# Drawing a circle using circle function
my_turtle_cursor.forward(10)
my_turtle_cursor.left(90)
my_turtle_cursor.circle(radius, extent = 180)
my_turtle_cursor.left(90)
my_turtle_cursor.forward(10)
my_turtle_cursor.end_fill()
my_turtle_cursor.getscreen().update()
# Creating a Function to draw different layers of a cake
def draw_layer_of_the_cake(fill_color, border_color, cursor_size, x, y, width, height):
my_turtle_cursor.hideturtle()
my_turtle_cursor.penup()
my_turtle_cursor.pensize(cursor_size)
# Changing color of our cursor
my_turtle_cursor.color(border_color)
# Changing fill color of the cursor
my_turtle_cursor.fillcolor(fill_color)
my_turtle_cursor.goto(x, y)
my_turtle_cursor.pendown()
# Starting the cursor to fill color
my_turtle_cursor.begin_fill()
for i in range(2):
my_turtle_cursor.forward(width)
my_turtle_cursor.left(90)
my_turtle_cursor.forward(height)
my_turtle_cursor.left(90)
my_turtle_cursor.end_fill()
my_turtle_cursor.setheading(0)
my_turtle_cursor.getscreen().update()
# # Creating an empty list of different parts of our cake
parts_of_cake = []
parts_of_cake.append(["#A020F0", "#000000", 3, 30])
parts_of_cake.append(["#55FF55", "#000000", 3, 20])
parts_of_cake.append(["#B87333", "#000000", 3, 60])
# drawing an plate for our cake using draw_layer_of_the_cake() function
draw_layer_of_the_cake("#FFC0CB", "#000000", 3, -220, y_coordinate - 70, 400, 10)
# Drawing different parts of our cake
for parts in parts_of_cake:
draw_layer_of_the_cake(parts[0], parts[1], parts[2], -135, y_coordinate - 60, 240, parts[3])
y_coordinate += parts[3]
# drawing top topping of our cake
draw_toppings_on_cake("#C20067", "#000000", -120, y_coordinate - 60, 10)
draw_toppings_on_cake("#FFFF00", "#000000", -80, y_coordinate - 60, 10)
draw_toppings_on_cake("#FF0000", "#000000", 25, y_coordinate - 60, 10)
draw_toppings_on_cake("#0000FF", "#000000", 59, y_coordinate - 60, 10)
# drawing middle topping of our cakes
draw_toppings_on_cake("#FFA500", "#000000", -135, y_coordinate - 80, 10)
draw_toppings_on_cake("#E4E6EB", "#000000", -135, y_coordinate - 100, 10)
draw_toppings_on_cake("#FFA500", "#000000", -135, y_coordinate - 120, 10)
draw_toppings_on_cake("#181A18", "#000000", -80, y_coordinate - 80, 10)
draw_toppings_on_cake("#0000FF", "#000000", -65, y_coordinate - 110, 10)
draw_toppings_on_cake("#FFD700", "#000000", -95, y_coordinate - 140, 10)
draw_toppings_on_cake("#181A18", "#000000", 10, y_coordinate - 80, 10)
draw_toppings_on_cake("#E4E6EB", "#000000", -20, y_coordinate - 110, 10)
draw_toppings_on_cake("#181418", "#000000", 35, y_coordinate - 140, 10)
draw_toppings_on_cake("#FFA500", "#000000", 75, y_coordinate - 80, 10)
draw_toppings_on_cake("#E4E6EB", "#000000", 75, y_coordinate - 110, 10)
draw_toppings_on_cake("#FFD700", "#000000", 75, y_coordinate - 140, 10)
# Drawing candle on of our cake using draw_candle_for_cake() function
draw_candle_for_cake("#FFF44F", "#000000", -40, y_coordinate - 60)
# Drawing stick on top of our candle
draw_stick_on_candle("#000000", -26, y_coordinate + 15, 7)
Step 5: Creating a function to Create a Stick
def draw_stick(fill_color, border_color, x, y):
my_turtle_cursor.penup()
my_turtle_cursor.pensize(3)
# Changing color of our cursor
my_turtle_cursor.color(border_color)
# Changing fill color of the cursor
my_turtle_cursor.fillcolor(fill_color)
my_turtle_cursor.goto(x, y)
my_turtle_cursor.begin_fill()
my_turtle_cursor.pendown()
my_turtle_cursor.left(180)
my_turtle_cursor.forward(200)
my_turtle_cursor.end_fill()
my_turtle_cursor.getscreen().update()
Step 6: Creating a Function to Draw a Circle on Top of the Stick
# Creating a function to draw a circle on top of stick
def draw_circle_on_top_of_stick(fill_color, border_color, x, y, radius):
my_turtle_cursor.penup()
my_turtle_cursor.pensize(3)
# Changing color of our cursor
my_turtle_cursor.color(fill_color)
# Changing fill color of the cursor
my_turtle_cursor.fillcolor(border_color)
my_turtle_cursor.goto(x, y)
my_turtle_cursor.pendown()
my_turtle_cursor.begin_fill()
my_turtle_cursor.circle(radius)
my_turtle_cursor.end_fill()
my_turtle_cursor.getscreen().update()
Step 7: Creating a function to write “Happy” Inside of our Circle
def write_happy_inside_circle(text_color, x, y):
my_turtle_cursor.penup()
# Changing color of our cursor
my_turtle_cursor.color(text_color)
# Changing fill color of the cursor
my_turtle_cursor.goto(x, y)
my_turtle_cursor.begin_fill()
my_turtle_cursor.pendown()
my_turtle_cursor.write("Happy", font=("sans-serif", 26, "bold"))
my_turtle_cursor.getscreen().update()
Step 8:Creating a Function to write “Birthday” in Our Circle
def write_birthday_inside_circle(text_color, x, y):
my_turtle_cursor.penup()
# Changing color of our cursor
my_turtle_cursor.color(text_color)
# Changing fill color of the cursor
my_turtle_cursor.goto(x, y)
my_turtle_cursor.begin_fill()
my_turtle_cursor.pendown()
my_turtle_cursor.write("Birthday", font=("sans-serif", 26, "bold"))
my_turtle_cursor.getscreen().update()
Summary
In this article, we learned How to draw a cake and write Happy Birthday using the Turtle library of Python. We hope this article on the Happy Birthday Python Program in Turtle will help you to wish Happy Birthday to your friends with your Python programming skills.
Thank you for reading this article, click here to start learning Python in 2022.
Also Read:
- Radha Krishna using Python Turtle
- Drawing letter A using Python Turtle
- Wishing Happy New Year 2023 in Python Turtle
- Snake and Ladder Game in Python
- Draw Goku in Python Turtle
- Draw Mickey Mouse in Python Turtle
- Happy Diwali in Python Turtle
- Draw Halloween in Python Turtle
- Write Happy Halloween in Python Turtle
- Draw Happy Diwali in Python Turtle
- Extract Audio from Video using Python
- Drawing Application in Python Tkinter
- Draw Flag of USA using Python Turtle
- Draw Iron Man Face with Python Turtle: Tony Stark Face
- Draw TikTok Logo with Python Turtle
- Draw Instagram Logo using Python Turtle
- I Love You Text in ASCII Art
- Python Turtle Shapes- Square, Rectangle, Circle
- Python Turtle Commands and All Methods
- Happy Birthday Python Program In Turtle
- I Love You Program In Python Turtle
- Draw Python Logo in Python Turtle
- Space Invaders game using Python
- Draw Google Drive Logo Using Python
- Draw Instagram Reel Logo Using Python
- Draw The Spotify Logo in Python Turtle
- Draw The CRED Logo Using Python Turtle
- Draw Javascript Logo using Python Turtle
- Draw Dell Logo using Python Turtle
- Draw Spider web using Python Turtle