MisterTootor M.S., B.S., A.S., A.S.B
I'm a paragraph. Click here to add your own text and edit me. It's easy.
Example: Drawing a Colorful Spiral with turtle
How to Run:
-
Install Python (if you haven’t already):
-
Download from https://python.org
-
-
Run the script:
-
Save the code to a file called spiral.py
-
Open a terminal or command prompt.
-
Run: python spiral.py
-
-
Watch the magic!
-
A window will open, and you’ll see a colorful spiral being drawn.
-
import turtle
import colorsys
​
# Set up screen
screen = turtle.Screen()
screen.bgcolor("black")
​
# Create turtle
pen = turtle.Turtle()
pen.speed(0)
pen.width(2)
​
# Number of colors and steps
h = 0
n = 36 # number of loops
​
for i in range(360):
c = colorsys.hsv_to_rgb(h, 1, 1) # Generate color
pen.color(c)
pen.forward(i * 3 / n + i)
pen.left(59)
pen.forward(i * 3 / n + i)
pen.left(60)
h += 0.005
​
# Hide turtle and finish
pen.hideturtle()
turtle.done()