Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from turtle import Turtle
- luna = Turtle()
- def draw_circle(t_name, r, col, Xdir, Ydir):
- t_name.penup()
- t_name.goto(Xdir, Ydir)
- t_name.color(col)
- t_name.dot(r*2)
- t_name.hideturtle()
- def rectangle_stuff(xDim, yDim):
- area = (xDim * yDim) #calculate the area
- perimeter = ((xDim + yDim) *2) #calculate the perimeter
- return(area, perimeter)
- def draw_rectangle(t_name, col, xLoc, yLoc, xDim, yDim ):
- #input coloUr and corner co-ordinates ^^^
- #Draw the rectangle
- t_name.color(col)
- t_name.penup()
- t_name.goto(xLoc,yLoc)
- t_name.setheading(0) #make sure turtle pointing the right way
- t_name.fillcolor(col)
- t_name.begin_fill()
- t_name.pendown()
- t_name.forward(xDim)
- t_name.right(90)
- t_name.forward(yDim)
- t_name.right(90)
- t_name.forward(xDim)
- t_name.right(90)
- t_name.forward(yDim)
- #move turtle to place the text
- t_name.right(90)
- t_name.forward(xDim/2)
- t_name.right(90)
- t_name.forward(yDim/2)
- t_name.end_fill()
- t_name.color("brown")
- t_name.write("Area, Per'r : " +str(rectangle_stuff(xDim, yDim)), align="center")
- t_name.hideturtle()
- #call up some circles
- draw_circle(luna, 150, "blue", -110, -20)
- draw_circle(luna, 100, "red", 180, 100)
- draw_circle(luna, 50, "yellow", 200, -202)
- #now do some rectangles
- draw_rectangle(luna, "green", -350, 360, 100, 150)
- draw_rectangle(luna, "magenta", 220, 100, 55, 159)
- draw_rectangle(luna, "turquoise", 350, -182, 100, 100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement