Files
python_bootcamp/018/sandbox.py

52 lines
1.2 KiB
Python

from turtle import Turtle, Screen
import random
def draw_square(turtle):
for _ in range(4):
turtle.forward(100)
turtle.right(90)
def draw_dashed_line(turtle):
for i in range(30):
if i % 2 == 0:
turtle.up()
else:
turtle.down()
turtle.forward(10)
def draw_shapes(turtle):
for sides_number in range(3, 11):
rgb = ()
for _ in range(3):
rgb += (random.random(),)
turtle.pencolor(rgb[0], rgb[1] ,rgb[2])
angle = 360 / sides_number
for _ in range(0, sides_number):
turtle.forward(100)
turtle.right(angle)
def draw_spirograph(turtle, nb_circles):
angle = 360 / nb_circles
for _ in range(0, nb_circles):
rgb = ()
for _ in range(3):
rgb += (random.random(),)
turtle.pencolor(rgb[0], rgb[1] ,rgb[2])
turtle.circle(100)
turtle.left(angle)
turtle = Turtle()
turtle.speed("fastest")
# draw_square(turtle)
# draw_dashed_line(turtle)
# draw_shapes(turtle)
draw_spirograph(turtle, 180)
screen = Screen()
screen.exitonclick()
turtle.pencolor