Advertisement
kevinbocky

circle_rectangle.py

Jan 25th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. #import turtle module
  2. from turtle import Turtle
  3.  
  4.  
  5. #define a function to calculate the circumference of a circle
  6. def circle_circumference(d):
  7. return 3.14 * int(d)
  8.  
  9. #define a function to calculate the surface area of a rectangle
  10. def rectangle_surface(length, height):
  11. return int(length) * int(height)
  12.  
  13. def print_color(color):
  14. return color
  15.  
  16. #define the draw a rectangle function and enter variables, such as color,some random elements in there
  17. def draw_rectangle():
  18. import random
  19. name = input("enter turtle name")
  20. name = Turtle()
  21.  
  22. color = input("enter color ")
  23. name.color(color)
  24. randx = random.randint(-300, 300)
  25. randy = random.randint(-300, 300)
  26. name.penup()
  27. name.goto(randx, randy)
  28. length = random.randint(10, 100)
  29. height = random.randint(10, 100)
  30. name.pendown()
  31. name.begin_fill()
  32. name.forward(length)
  33. name.right(90)
  34. name.forward(height)
  35. name.right(90)
  36. name.forward(length)
  37. name.right(90)
  38. name.forward(height)
  39. name.end_fill()
  40. name.color("black")
  41. name.penup()
  42. name.goto(int(randx + 0.5 * length), int(randy - 0.5 * height +10))
  43. name.pendown()
  44. name.write("surface:" + str(rectangle_surface(length,height)), align = "center")
  45. name.penup()
  46. name.goto(int(randx + 0.5 * length), int(randy - 0.5 * height -10))
  47. name.pendown()
  48. name.write("color:" + str(print_color(color)), align = "center")
  49. name.hideturtle()
  50.  
  51.  
  52.  
  53.  
  54. #define draw_circle function and enter variables, such as diameter, color,coordinates
  55. def draw_circle():
  56. name = input("enter turtle name")
  57. name = Turtle()
  58. d = input("enter diameter")
  59. color = input("enter color")
  60. x = input("enter x coordinate (300/-300)")
  61. y = input("enter y coordinate (300/-300)")
  62. name.penup()
  63. name.goto(int(x), (int(y)))
  64. name.pendown()
  65. name.dot(d , color)
  66. name.color("black")
  67. name.write("Circumference: " + str(circle_circumference(d)), align="center")
  68. name.hideturtle()
  69.  
  70. amount = input("How many circles do you want to draw? ")
  71. for i in range(int(amount)):
  72. draw_circle()
  73.  
  74.  
  75. amount = input("How many rectangles do you want to draw? ")
  76. for i in range(int(amount)):
  77. draw_rectangle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement