In this project, you are going to one hundred random rectangles filled with random colors. You will learn for loop, function, random library, and setting color with (r,g,b). Video demo
In this project, you practice loop and defining custom functions. Draw the following shape with a for loop. Define a function draw_circle(x,y,r), which draws a circle centered at (x,y) and
import turtle
turtle.speed(0)
turtle.up()
turtle.circle(250,270)
turtle.down()
turtle.begin_fill()
turtle.fillcolor(‘limegreen’)
turtle.circle(250,180)
turtle.left(90)
turtle.fd(50)
turtle.left(90)
turtle.circle(-200,180)
turtle.left(90)
turtle.fd(50)
turtle.end_fill()
turtle.left(180)
turtle.fd(50)
turtle.right(90)
turtle.begin_fill()
turtle.fillcolor(‘red’)
turtle.circle(200,180)
turtle.left(90)
turtle.fd(400)
turtle.end_fill()
turtle.up()
turtle.goto(-130,230)
turtle.down()
turtle.begin_fill()
turtle.fillcolor(‘black’)
turtle.circle(25)
turtle.end_fill()
turtle.up()
turtle.goto(-135,220)
turtle.down()
turtle.begin_fill()
turtle.fillcolor(‘white’)
turtle.circle(15)
turtle.end_fill()
turtle.up()
turtle.goto(130,230)
turtle.down()
turtle.begin_fill()
turtle.fillcolor(‘black’)
turtle.circle(25)
turtle.end_fill()
turtle.up()
turtle.goto(125,220)
turtle.down()
turtle.begin_fill()
turtle.fillcolor(‘white’)
turtle.circle(15)
turtle.end_fill()
turtle.up()
turtle.pensize(10)
turtle.goto(15,100)
turtle.circle(15,270)
turtle.down()
turtle.circle(15,-180)
Nice. It works!