Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import turtle
  2. from random import random
  3. w = 1000
  4. h = 800
  5. s = turtle.Screen()
  6. #Блок ниже не изменять: ===================
  7. s.setup(w,h, 0,200) #
  8. s.setworldcoordinates(0, h, w, 0) #
  9. s.bgcolor('grey')
  10. s.title('Our Screen')
  11.  
  12. #Конец блока ==============================
  13.  
  14. ball = turtle.Turtle()
  15. ball.shape('circle')
  16. ball.color('red')
  17. ball.up()
  18.  
  19. plate = turtle.Turtle()
  20. plate.shape('square')
  21. plate.shapesize(1,3)
  22. plate.speed(0)
  23. plate.color('green')
  24. plate.up()
  25. x2 = 200
  26. y2 = 787
  27. plate.setposition(x2,y2)
  28.  
  29. x = 30
  30. y = 30
  31. dx = 10
  32. dy = 10
  33.  
  34. dx2 = 8
  35. dy2 = 0
  36.  
  37. count = 0
  38. try:
  39. while True:
  40. s.update()
  41. ball.setx(x)
  42. ball.sety(y)
  43. y += dy
  44. x += dx
  45. if x > w or x < 5:
  46. dx = -dx
  47. if y > h or y < 5:
  48. dy = -dy
  49. plate.setx(x2)
  50. plate.sety(y2)
  51. y2 += dy2
  52. x2 += dx2
  53. if count == 2:
  54. dx2 = 0
  55. dy2 = -8
  56. count += 1
  57. elif count == 5:
  58. dx2 = 8
  59. dy2 = 0
  60. count = 0
  61. elif count > 2:
  62. if y2 > h-10 or y2 < 10:
  63. dy2 = -dy2
  64. count += 1
  65. plate.color(random(),random(),random())
  66. else:
  67. if x2 > w-25 or x2 < 20:
  68. dx2 = -dx2
  69. count += 1
  70. plate.color(random(),random(),random())
  71.  
  72.  
  73. except Exception as ex:
  74. exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement