AyanUpadhaya

Shape Drawing By Turtle

May 12th, 2021 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. import turtle
  2.  
  3. #@shape drawing programing by Ayan Upadhaya
  4.  
  5. #key commands
  6. #left arrow -for left drawing
  7. #right arrow- for right drawing
  8. #up arrow - for up drawing
  9. #down arrown- for down drawing
  10. #x- to penup
  11. #c- to pendown
  12. #d- create eraser
  13. #r- restet pen
  14.  
  15. #move the player left and right
  16. def moveLeft():
  17.     playerXPosition=playerx.xcor()
  18.     vel=15
  19.     playerx.setx(playerXPosition-vel)
  20.     win.update()
  21.  
  22. def moveRight():
  23.     playerXPosition=playerx.xcor()
  24.     vel=15
  25.     playerx.setx(playerXPosition+vel)
  26.     win.update()
  27. #move the player up and bottom
  28.  
  29. def moveUp():
  30.     playerYPosition=playerx.ycor()
  31.     vel=15
  32.     playerx.sety(playerYPosition+vel)
  33.     win.update()
  34. def moveDown():
  35.     playerYPosition=playerx.ycor()
  36.     vel=15
  37.     playerx.sety(playerYPosition-vel)
  38.     win.update()
  39.  
  40. #to penup and pedown event
  41.  
  42. def notDraw():
  43.     playerx.penup()
  44.  
  45. def draw():
  46.     playerx.pendown()
  47.  
  48. #make the eraser
  49.  
  50. def eraser():
  51.     playerx.color('black','white')
  52.    
  53. def reset():
  54.     playerx.color('yellow','black')
  55.  
  56.  
  57. #playerx profile
  58.  
  59. playerx=turtle.Turtle()
  60. playerx.shape('triangle')
  61. playerx.color('yellow')
  62. playerx.goto(0,0)
  63. playerx.setheading(90)
  64. playerx.speed(0)
  65.  
  66. #Screen Profile
  67. win=turtle.Screen()
  68. win.title("Draw as you like")
  69. win.bgcolor('black')
  70. win.setup(width=600,height=600)
  71. win.tracer(0)
  72.  
  73. #screen event listner
  74.  
  75. win.listen()
  76. win.onkeypress(moveLeft,'Left')
  77. win.onkeypress(moveRight,'Right')
  78. win.onkeypress(moveUp,'Up')
  79. win.onkeypress(moveDown,'Down')
  80. win.onkeypress(notDraw,'x')
  81. win.onkeypress(draw,'c')
  82. win.onkeypress(eraser,'d')
  83. win.onkeypress(reset,'r')
  84.  
  85. #keeps the screen on untill we close it.
  86. win.mainloop()
Add Comment
Please, Sign In to add comment