Python - Turtle
In this blog post, we're going to see about the Python turtle library, python turtle is a fun way to learn programming by drawing pictures using code
Ok now let's see the project :
project output:
Project code :
'''This line tells the computer to import the
Turtle module, which allows us to create graphics
and draw shapes using Python.'''
import turtle
'''This line sets up a new window for drawing and sets the background color.'''
sc = turtle.Screen()
sc.bgcolor("black")
'''This line creates a pen to draw and sets the drawing speed when the turtle moves.'''
t = turtle.Turtle()
t.speed(10)
'''Set colors for the turtle pen'''
set_colors = ["blue", "yellow", "red", "purple"]
for i in range(180):
t.pencolor(set_colors[i % 4]) # Set the pen color based on the iteration
t.width(i / 100 + 1) # Set the pen width based on the iteration
t.forward(i) # Moves the turtle forward
t.right(40) # Turns the turtle to the right by 40
# Hides the turtle pen after drawing is complete
t.hideturtle()
# Keeps the window open until it is manually closed
turtle.done()
.png)
.png)
.png)
Comments
Post a Comment