Advertisement
johnpentyrch

Ass 1.9

Apr 29th, 2020
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. from turtle import Turtle
  2. def draw_circle(t,r,c,x,y):
  3.     t.penup()
  4.     t.goto(x,y)
  5.     t.color(c)
  6.     t.dot(2*r)
  7.     t.penup()
  8.     t.goto(x,y-5)
  9.     t.pendown()
  10.     t.color('black')
  11.     t.write('circumference: ' +str(circle_circumference(r)), align='center')
  12.     t.penup()
  13.     t.goto(x,y+5) #Assumes circle is at 0,0. How might you adapt if you have x,y parameters?
  14.     t.pendown()
  15.     t.color("black")
  16.     t.write("Area: " + str(circle_area(r)), align="center")
  17.  
  18. def circle_area(r):
  19.     return 3.14*r*r
  20. def circle_circumference(r):
  21.   return 3.14 * 2 * r
  22.  
  23. tut=Turtle()
  24. tut.getscreen().bgcolor('#ffffff')
  25.  
  26. draw_circle(tut,100,'cyan',-100,-100)
  27. ##draw_circle(tut,30,'red',-50,-100)
  28. ##draw_circle(tut,20,'green',-100,-100)
  29. ##draw_circle(tut,25,'blue',0,0)
  30. ##draw_circle(tut,75,'white',100,100)
  31. ##draw_circle(tut,50,'gray',50,100)
  32.  
  33. def rec_area(h,w):
  34.     return h*w
  35. def rec_perimeter(h,w):
  36.   return 2*(h+w)
  37.  
  38.  
  39. def draw_sq(t,h,w,c,bg,x,y):
  40.     t.pensize(5)
  41.     t.penup()
  42.     t.goto(x,y)
  43.     t.color(c,bg)
  44.     t.begin_fill()
  45.     t.pendown()
  46.     t.setheading(0) #east
  47.     t.forward(w) #to right width w
  48.     t.left(90)
  49.     t.forward(h) #draw up the height h
  50.     t.left(90)
  51.     t.forward(w)
  52.     t.left(90)
  53.     t.forward(h)
  54.     t.end_fill()
  55.     t.penup()
  56.     t.goto((x+w/2),(y+h/2))
  57.     t.pendown()
  58.     t.color('black')
  59.     t.write('perimeter: ' +str(rec_perimeter(h,w)), align='center')
  60.     t.penup()
  61.     t.goto((x+w/2),((y+h/2)-10))
  62.     t.pendown()
  63.     t.color("black")
  64.     t.write("Area: " + str(rec_area(h,w)), align="center")
  65.  
  66.  
  67.  
  68. draw_sq(tut,100,200,'gray','#a88cff',-400,300)
  69. draw_sq(tut,100,200,'red','yellow',220,100)
  70. draw_sq(tut,300,200,'black','#8caaff',0,0)
  71. tut.hideturtle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement