Advertisement
g0thy

Turtle2

Nov 29th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. from turtle import Turtle
  2.  
  3. luna = Turtle()
  4.  
  5. def draw_circle(t_name, r, col, Xdir, Ydir):
  6.     t_name.penup()
  7.     t_name.goto(Xdir, Ydir)
  8.     t_name.color(col)
  9.     t_name.dot(r*2)
  10.     t_name.hideturtle()
  11.  
  12. def rectangle_stuff(xDim, yDim):
  13.     area = (xDim * yDim)    #calculate the area
  14.     perimeter = ((xDim + yDim) *2)  #calculate the perimeter
  15.     return(area, perimeter)
  16.  
  17. def draw_rectangle(t_name, col, xLoc, yLoc, xDim, yDim ):
  18.     #input coloUr and corner co-ordinates ^^^
  19.  
  20.  #Draw the rectangle
  21.     t_name.color(col)
  22.     t_name.penup()
  23.     t_name.goto(xLoc,yLoc)
  24.     t_name.setheading(0)    #make sure turtle pointing the right way
  25.     t_name.fillcolor(col)
  26.     t_name.begin_fill()
  27.     t_name.pendown()
  28.     t_name.forward(xDim)
  29.     t_name.right(90)
  30.     t_name.forward(yDim)
  31.     t_name.right(90)
  32.     t_name.forward(xDim)
  33.     t_name.right(90)
  34.     t_name.forward(yDim)
  35.     #move turtle to place the text
  36.     t_name.right(90)
  37.     t_name.forward(xDim/2)
  38.     t_name.right(90)
  39.     t_name.forward(yDim/2)
  40.     t_name.end_fill()
  41.     t_name.color("brown")
  42.     t_name.write("Area, Per'r : " +str(rectangle_stuff(xDim, yDim)), align="center")
  43.     t_name.hideturtle()
  44.  
  45. #call up some circles    
  46. draw_circle(luna, 150, "blue", -110, -20)
  47. draw_circle(luna, 100, "red", 180, 100)
  48. draw_circle(luna, 50, "yellow", 200, -202)
  49.  
  50. #now do some rectangles
  51. draw_rectangle(luna, "green", -350, 360, 100, 150)
  52. draw_rectangle(luna, "magenta", 220, 100, 55, 159)
  53. draw_rectangle(luna, "turquoise", 350, -182, 100, 100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement