Advertisement
here2share

# turtle_demos.py

May 29th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.17 KB | None | 0 0
  1. # turtle_demos.py
  2.  
  3. '''
  4. Turtle()        None            Creates and returns a new tutrle object
  5. forward()       amount          Moves the turtle forward by the specified amount
  6. backward()      amount          Moves the turtle backward by the specified amount
  7. right()         angle           Turns the turtle clockwise
  8. left()          angle           Turns the turtle counter clockwise
  9. penup()         None            Picks up the turtle's Pen
  10. pendown()       None            Puts down the turtle's Pen
  11. up()            None            Picks up the turtle's Pen
  12. down()          None            Puts down the turtle's Pen
  13. color()         Color name      Changes the color of the turtle's pen
  14. fillcolor()     Color name      Changes the color of the turtle will use to fill a polygon
  15. heading()       None            Returns the current heading
  16. position()      None            Returns the current position
  17. goto()          x, y            Move the turtle to position x,y
  18. begin_fill()    None            Remember the starting point for a filled polygon
  19. end_fill()      None            Close the polygon and fill with the current fill color
  20. dot()           None            Leave the dot at the current position
  21. stamp()         None            Leaves an impression of a turtle shape at the current location
  22. shape()         shapename       Should be 'arrow', 'classic', 'turtle' or 'circle'
  23. '''
  24.  
  25. import turtle
  26. win = turtle.Screen()
  27. t = turtle.Turtle()
  28. turtle.title('Turtle')
  29. turtle.bgcolor('light blue')
  30. t.circle(50)
  31. t.penup()
  32. t.hideturtle()
  33. t.forward(200)
  34. t.color('yellow')
  35. t.pendown()
  36. t.pensize(width=9)
  37. t.circle(100)
  38. t.speed(0) # 0=fastest, 6=normal, 1-to-10=slowest-to-fast
  39. t.penup()
  40. t.backward(400)
  41. t.pendown()
  42. t.pensize(width=1)
  43. t.begin_fill()
  44. t.circle(100)
  45. t.penup()
  46. t.goto(0,-100)
  47. t.pendown()
  48. for i in range(10):
  49.     t.forward(200)
  50.     t.right(144)
  51. 0
  52. t.end_fill()
  53. t.penup()
  54. t.goto(0,100)
  55. t.pendown()
  56. t.shape('turtle')
  57. t.showturtle()
  58. print t.pos()
  59.  
  60. def petal(t, r, angle):
  61.     for i in range(2):
  62.         t.circle(r,angle)
  63.         t.left(180-angle)
  64. 0
  65. def flower(t, n, r, angle):
  66.     for i in range(n):
  67.         petal(t, r, angle)
  68.         t.left(360.0/n)
  69. 0
  70. win.ontimer(None, 3000)
  71. t.clear()
  72. t.fill(1)
  73. flower(t, 10, 100.0, 80.0)
  74. t.fill(0)
  75. t.pensize(width=2)
  76. t.color("purple")
  77. flower(t, 10, 100.0, 80.0)
  78. t.penup()
  79. t.goto(0,-100)
  80. t.write('   End Of Demo', font=('Arial', 30, 'italic', 'bold'))
  81. turtle.done()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement