Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from turtle import Turtle
- def draw_circle(t,r,c,x,y):
- t.penup()
- t.goto(x,y)
- t.color(c)
- t.dot(2*r)
- t.penup()
- t.goto(x,y-5)
- t.pendown()
- t.color('black')
- t.write('circumference: ' +str(circle_circumference(r)), align='center')
- t.penup()
- t.goto(x,y+5) #Assumes circle is at 0,0. How might you adapt if you have x,y parameters?
- t.pendown()
- t.color("black")
- t.write("Area: " + str(circle_area(r)), align="center")
- def circle_area(r):
- return 3.14*r*r
- def circle_circumference(r):
- return 3.14 * 2 * r
- tut=Turtle()
- tut.getscreen().bgcolor('#ffffff')
- draw_circle(tut,100,'cyan',-100,-100)
- ##draw_circle(tut,30,'red',-50,-100)
- ##draw_circle(tut,20,'green',-100,-100)
- ##draw_circle(tut,25,'blue',0,0)
- ##draw_circle(tut,75,'white',100,100)
- ##draw_circle(tut,50,'gray',50,100)
- def rec_area(h,w):
- return h*w
- def rec_perimeter(h,w):
- return 2*(h+w)
- def draw_sq(t,h,w,c,bg,x,y):
- t.pensize(5)
- t.penup()
- t.goto(x,y)
- t.color(c,bg)
- t.begin_fill()
- t.pendown()
- t.setheading(0) #east
- t.forward(w) #to right width w
- t.left(90)
- t.forward(h) #draw up the height h
- t.left(90)
- t.forward(w)
- t.left(90)
- t.forward(h)
- t.end_fill()
- t.penup()
- t.goto((x+w/2),(y+h/2))
- t.pendown()
- t.color('black')
- t.write('perimeter: ' +str(rec_perimeter(h,w)), align='center')
- t.penup()
- t.goto((x+w/2),((y+h/2)-10))
- t.pendown()
- t.color("black")
- t.write("Area: " + str(rec_area(h,w)), align="center")
- draw_sq(tut,100,200,'gray','#a88cff',-400,300)
- draw_sq(tut,100,200,'red','yellow',220,100)
- draw_sq(tut,300,200,'black','#8caaff',0,0)
- tut.hideturtle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement