Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from turtle import Turtle
- t = Turtle()
- def circleAttributes(radius):
- circumference = 3.14 * 2 * radius
- area = 3.14 * 2 * radius
- return [circumference, area]
- def drawCircle(turtle, radius, color, x, y):
- turtle.hideturtle()
- turtle.penup()
- turtle.color(color)
- turtle.goto(x, y)
- turtle.pendown()
- turtle.dot(radius * 2)
- turtle.penup()
- turtle.color("black")
- turtle.goto(x, y - 14)
- turtle.pendown()
- attributes = circleAttributes(radius)
- turtle.write("Circumference: "
- + str(attributes[0]) + "\nArea: "
- + str(attributes[1]), align="center")
- def rectangleAttributes(w, h):
- perimeter = (2 * w) + (2 * h)
- area = w * h
- return [perimeter, area]
- def drawRectangle(turtle, w, h, color, x, y):
- turtle.hideturtle()
- turtle.home()
- startx = x - (w / 2)
- starty = y - (h / 2)
- turtle.penup()
- turtle.color(color)
- turtle.goto(startx, starty)
- turtle.pendown()
- turtle.begin_fill()
- turtle.fd(w)
- turtle.lt(90)
- turtle.fd(h)
- turtle.lt(90)
- turtle.fd(w)
- turtle.lt(90)
- turtle.fd(h)
- turtle.end_fill()
- turtle.penup()
- turtle.color("black")
- turtle.goto(x, y - 14)
- turtle.pendown()
- attributes = rectangleAttributes(w, h)
- turtle.write("Perimeter: "
- + str(attributes[0]) + "\nArea: "
- + str(attributes[1]), align="center")
- turtle.penup()
- drawRectangle(t, 50, 60, "blue", 0, 0)
- drawRectangle(t, 150, 20, "yellow", 30, 60)
- drawRectangle(t, 80, 40, "red", -20, 50)
- drawCircle(t, 150, "blue", 10, 10)
- drawCircle(t, 100, "red", -20, -20)
- drawCircle(t, 50, "yellow", 40, 30)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement