Advertisement
timpin

Untitled

Aug 24th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. from turtle import Turtle
  2. from random import *
  3. tina = Turtle()
  4.  
  5. def circle_area(r):
  6. return 3.14159 * r * r
  7.  
  8. def circle_circumference(r):
  9. return 3.14159 * 2 * r
  10.  
  11. def draw_circle(t_name, r, col):
  12. t_name.color(col)
  13. t_name.dot(2 * r)
  14.  
  15. t_name.penup()
  16. t_name.goto(0,5) #Assumes circle is at 0,0.
  17. t_name.pendown()
  18. t_name.color("black")
  19. t_name.write("Area: " + str(circle_area(r)), align="center")
  20.  
  21. t_name.penup()
  22. t_name.goto(0,-5)
  23. t_name.pendown()
  24. t_name.color("black")
  25. t_name.write("Circumference: " + str(circle_circumference(r)), align="center")
  26.  
  27. def area_rectangle(x,y):
  28. rec_area = x * y
  29. return rec_area
  30.  
  31. def perimeter_rectangle(x,y):
  32. rec_perimeter = 2 * (x + y)
  33. return rec_perimeter
  34.  
  35. def draw_rectangle(t_name,x,y,col):
  36. t_name.hideturtle
  37. t_name.color(col)
  38. t_name.penup()
  39. t_name.goto(-x/2,y/2)
  40. t_name.pendown()
  41. t_name.begin_fill()
  42. t_name.goto(x/2,y/2)
  43. t_name.goto(x/2,-y/2)
  44. t_name.goto(-x/2,-y/2)
  45. t_name.goto(-x/2,y/2)
  46. t_name.end_fill()
  47.  
  48. t_name.penup()
  49. t_name.goto(0,5) #Assumes rectangle is at 0,0.
  50. t_name.pendown()
  51. t_name.color("black")
  52. t_name.write("Area: " + str(area_rectangle(x,y)), align="center")
  53.  
  54. t_name.penup()
  55. t_name.goto(0,-5)
  56. t_name.pendown()
  57. t_name.color("black")
  58. t_name.write("Circumference: " + str(perimeter_rectangle(x,y)), align="center")
  59.  
  60. draw_rectangle(tina,50,70,"blue")
  61.  
  62.  
  63. #draw_circle(tina,25,"red")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement