Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
201
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.  
  3. t = Turtle()
  4.  
  5. def circleAttributes(radius):
  6.     circumference = 3.14 * 2 * radius
  7.     area = 3.14 * 2 * radius
  8.     return [circumference, area]
  9.  
  10. def drawCircle(turtle, radius, color, x, y):
  11.     turtle.hideturtle()
  12.     turtle.penup()
  13.     turtle.color(color)
  14.     turtle.goto(x, y)
  15.     turtle.pendown()
  16.     turtle.dot(radius * 2)
  17.     turtle.penup()
  18.     turtle.color("black")
  19.     turtle.goto(x, y - 14)
  20.     turtle.pendown()
  21.     attributes = circleAttributes(radius)
  22.     turtle.write("Circumference: "
  23.                  + str(attributes[0]) + "\nArea: "
  24.                  + str(attributes[1]), align="center")
  25.  
  26. def rectangleAttributes(w, h):
  27.     perimeter = (2 * w) + (2 * h)
  28.     area = w * h
  29.     return [perimeter, area]
  30.  
  31. def drawRectangle(turtle, w, h, color, x, y):
  32.     turtle.hideturtle()
  33.     turtle.home()
  34.     startx = x - (w / 2)
  35.     starty = y - (h / 2)
  36.     turtle.penup()
  37.     turtle.color(color)
  38.     turtle.goto(startx, starty)
  39.     turtle.pendown()
  40.     turtle.begin_fill()
  41.     turtle.fd(w)
  42.     turtle.lt(90)
  43.     turtle.fd(h)
  44.     turtle.lt(90)
  45.     turtle.fd(w)
  46.     turtle.lt(90)
  47.     turtle.fd(h)    
  48.     turtle.end_fill()
  49.     turtle.penup()
  50.     turtle.color("black")
  51.     turtle.goto(x, y - 14)
  52.     turtle.pendown()
  53.     attributes = rectangleAttributes(w, h)
  54.     turtle.write("Perimeter: "
  55.                  + str(attributes[0]) + "\nArea: "
  56.                  + str(attributes[1]), align="center")
  57.     turtle.penup()
  58.    
  59. drawRectangle(t, 50, 60, "blue", 0, 0)
  60. drawRectangle(t, 150, 20, "yellow", 30, 60)    
  61. drawRectangle(t, 80, 40, "red", -20, 50)
  62.  
  63. drawCircle(t, 150, "blue", 10, 10)
  64. drawCircle(t, 100, "red", -20, -20)
  65. drawCircle(t, 50, "yellow", 40, 30)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement