SaveText.Ru

Без имени
  1. from random import *
  2. from turtle import *
  3. from time import sleep
  4.  
  5. tracer(0, 0)
  6. hideturtle()
  7. width(5)
  8. x1 = 0
  9. y1 = 0
  10. size1 = 50
  11. sc = getscreen()
  12. score = 0
  13.  
  14. def rect(x, y, size = 50):
  15.     penup()
  16.     goto(x, y)
  17.     fd(size / 2)
  18.     rt(90)
  19.     fd(size / 2)
  20.     rt(90)
  21.     pendown()
  22.     begin_fill()
  23.     color('black')
  24.    
  25.     for i in range(4):
  26.         fd(size)
  27.         rt(90)
  28.     rt(180)
  29.     penup()
  30.     color('red')
  31.     end_fill()
  32.    
  33. def started(x, y):
  34.     global x1, y1, size1, score
  35.     clear()
  36.     if x > x1 - size1 / 2 and x < x1 + size1 / 2 and y > y1 - size1 / 2 and y < y1 + size1 / 2:
  37.         x1 = randint(-400, 400)
  38.         y1 = randint(-400, 400)
  39.         size1 = randint(50, 150)
  40.         score += 1
  41.     rect(x1, y1, size1)
  42.     update()
  43.     goto(250, 250)
  44.     color('green')
  45.     write(score, False, align='left', font=('Arial', 25,'normal'))
  46.  
  47. started(0, 1000)
  48. sc.onclick(started, btn=1, add=None)
  49. update()
  50. sleep(0.01)
  51.  
  52.  

Share with your friends:

Print