please code in python Here's an example created by rotating a square 9 times: Write a Python program that will produce our simplified "spirograph" images from squares. Your program should include a function: spiro(num, side) that takes two arguments: the number of squares to draw in one revolution, and the side length of each square in the figure. Remember: there are 360 degrees in a circle. Here is a function that demonstrates how to draw a randomly colored filled square. You’ll want to copy-paste this function into your program, and call this function from within a loop in your spirograph function, so that it draws multiple squares: import turtle, random turtle.speed(0) turtle.delay(0) def filled_square(side): r = random.random() g = random.random() b = random.random() turtle.color(r,g,b) turtle.begin_fill() for i in range(4): turtle.forward(side) turtle.left(90) turtle.end_fill()
please code in python
Here's an example created by rotating a square 9 times:
Write a Python program that will produce our simplified "spirograph" images from squares. Your program should include a function: spiro(num, side) that takes two arguments: the number of squares to draw in one revolution, and the side length of each square in the figure. Remember: there are 360 degrees in a circle.
Here is a function that demonstrates how to draw a randomly colored filled square. You’ll want to copy-paste this function into your program, and call this function from within a loop in your spirograph function, so that it draws multiple squares:
import turtle, random
turtle.speed(0)
turtle.delay(0)
def filled_square(side):
r = random.random()
g = random.random()
b = random.random()
turtle.color(r,g,b)
turtle.begin_fill()
for i in range(4):
turtle.forward(side)
turtle.left(90)
turtle.end_fill()
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images