Draw Happy Diwali in Python Turtle

Draw Happy Diwali in Python Turtle

Introduction

Hello there, In this lesson, we will Draw Happy Diwali in Python Turtle. Turtle is a pre-installed Python module that allows users to draw drawings and shapes on a virtual canvas. The onscreen pen used for doodling is known as the turtle. In summary, the Python turtle library provides novice programmers with a fun and interactive approach to learning about Python programming.

The turtle is mostly utilized to expose students to the computer industry. It’s a simple yet adaptable method for learning Python fundamentals. This makes it an excellent starting point for children to learn Python programming. That being said, the Python turtle library is not just for students! It’s also shown to be highly effective for adults learning Python, making it ideal for Python beginners.

You may draw and generate numerous shapes and pictures with the Python turtle package. In this article, we will write “Happy Diwali” in a beautiful way using custom fonts, sizes, and shapes, as well as create firecrackers on the screen.

Let’s first see the complete code to Draw Happy Diwali in Python Turtle, we will understand the code using comments step-by-step.

Complete code to Draw Happy Diwali in Python Turtle

from tkinter.font import ITALIC
from tkinter.ttk import Style
import turtle
import colorsys
import random

#Create a turtle screen
screen=turtle.Screen()

#Define height and width of screen
screen.setup(1200,600)

#Define Background color of screen
screen.bgcolor('black')

#Initialize a variable for turtle
t=turtle.Turtle()

# Define title of program
turtle.title("Copy Assignment Turtle")

#Defining speed of turtle
t.speed(10)

#To hide the turtle pointer
t.hideturtle()
hue=0.0



size=random.randint(10,200)

# for i in range(36):
#         color=colorsys.hsv_to_rgb(hue,1,1)
#         t.pencolor("orange")
#         t.left(10)
#         hue +=0.1

# Code for writing Happy Diwali on Canvas
def write(message,pos):
        x,y=pos
        # Define color of the text
        t.pencolor("orange")
        t.penup()
        t.goto(x,y)
        # Defining font style and size
        style=('Arial',100)
        t.write(message,font=style)

write('Happy Diwali',(-380,-50))

# Code for drawing firecrackers
#Defining function for drawing firecrackers
def draw_firecrackers(x,y):
    t.penup()
    t.goto(x,y)
    t.pendown()

#color of the firecracker
t.color("red")

#Initializing the pointer
angle=0
for i in range(20):
    #move in forward direction
    t.fd(50)

    #calling the function and initializing the values
    draw_firecrackers(300,180)

    #changing the angle of pointer
    angle+=18

    t.left(angle)
draw_firecrackers(450,180)

#color of the firecracker
t.color("blue")
angle=0
for i in range(20):
    t.fd(50)
    angle+=18
    t.left(angle)
    draw_firecrackers(450,180)
draw_firecrackers(375,300)

#color of the firecracker
t.color("green")
angle=0
for i in range(20):
    t.fd(50)
    angle+=18
    t.left(angle)
    draw_firecrackers(375,300)
draw_firecrackers(375,-300)

#color of the firecracker
t.color("orange")
angle=0
for i in range(20):
    t.fd(50)
    angle+=18
    t.left(angle)
    draw_firecrackers(375,-300)
draw_firecrackers(150,-150)

#color of the firecracker
t.color("violet")
angle=0
for i in range(20):
    t.fd(50)
    angle+=18
    t.left(angle)
    draw_firecrackers(150,-150)
draw_firecrackers(450,-150)

#color of the firecracker
t.color("brown")
angle=0
for i in range(20):
    t.fd(50)
    angle+=18
    t.left(angle)
    draw_firecrackers(450,-150)
draw_firecrackers(-200,-300)

#color of the firecracker
t.color("green")
angle=0
for i in range(20):
    t.fd(50)
    angle+=18
    t.left(angle)
    draw_firecrackers(-200,-300)
draw_firecrackers(125,0)

#color of the firecracker
t.color("pink")
angle=0
draw_firecrackers(-100,-200)
for i in range(20):
    t.fd(50)
    angle+=18
    t.left(angle)
    draw_firecrackers(-100,-200)

#color of the firecracker    
t.color("skyblue")
angle=0
draw_firecrackers(-500,-240)
for i in range(20):
    t.fd(50)
    angle+=18
    t.left(angle)
    draw_firecrackers(-500,-240)

#color of the firecracker    
t.color("orange")
angle=0
draw_firecrackers(-350,-170)
for i in range(20):
    t.fd(50)
    angle+=18
    t.left(angle)
    draw_firecrackers(-350,-170)

#color of the firecracker
t.color("pink")
angle=0
for i in range(20):
    t.fd(50)
    draw_firecrackers(-550,300)
    angle+=18
    t.left(angle)
draw_firecrackers(-450,180)

#color of the firecracker
t.color("green")
angle=0
for i in range(20):
    t.fd(50)
    angle+=18
    t.left(angle)
    draw_firecrackers(-450,180)
draw_firecrackers(-375,300)
t.color("yellow")
angle=0
for i in range(20):
    t.fd(50)
    t.left(angle)
    angle+=18
    draw_firecrackers(-375,300)
draw_firecrackers(-375,-300)

# To hold the screen to display
screen.mainloop()

Output:

Output to Draw Happy Diwali in Python Turtle

Conclusion

In this article, you have learned how to program with the Python turtle library and have mastered several fundamental programming ideas. We learned how to write Happy Diwali using various font styles, colors, and shapes in a beautiful way. We also draw the firecrackers on the canvas to make it look more attractive. Based on this you can now install the Python turtle library and Create a game that you and your friends can play by customizing your turtle and its environment, using fundamental programming concepts.

Things we learned in this tutorial:

  • Learn about the Python turtle library.
  • Become familiar with turtle setup on computers.
  • Implement turtle libraries in Python programs.
  • Learn some key turtle commands and Python concepts
  • Practical implementation variables, loops, conditional statements, indentations, lists, and operators.

This is an excellent place to start, especially if you’re new to Python programming!


Also Read:

Share:

Author: Ayush Purawr