| 1 |
import random |
| 2 |
import time |
| 3 |
from turtle import * |
| 4 |
def draw_circle(x, y, r, c): |
| 5 |
color(c, c) |
| 6 |
penup() |
| 7 |
goto(x, y) |
| 8 |
pendown() |
| 9 |
begin_fill() |
| 10 |
dot(2*r) |
| 11 |
end_fill() |
| 12 |
hideturtle() |
| 13 |
a = [(0, 0, (random.random(), random.random(), random.random()))] |
| 14 |
dx, dy = 0, 0 |
| 15 |
for i in range(500): |
| 16 |
clearscreen() |
| 17 |
bgcolor("gray10") |
| 18 |
tracer(False) |
| 19 |
for x, y, c in a: |
| 20 |
draw_circle(x, y, 10, c) |
| 21 |
update() |
| 22 |
time.sleep(0.1) |
| 23 |
if len(a) < 10: |
| 24 |
a.append((0, 0, 0)) |
| 25 |
for i in range(min(10, len(a)) - 1, 0, -1): |
| 26 |
a[i] = a[i - 1] |
| 27 |
x, y = a[0][0] + dx, a[0][1] + dy |
| 28 |
if 2 * x > window_width(): x = -window_width() / 2 |
| 29 |
if 2 * y > window_height() : y = - window_height() / 2 |
| 30 |
if 2 * x < -window_width(): x = window_width() / 2 |
| 31 |
if 2 * y < -window_height(): y = window_height() / 2 |
| 32 |
a[0] = (x, y, (random.random(), random.random(), random.random())) |
| 33 |
dx += random.randint(-3, 3) |
| 34 |
dx = min(dx, 5) |
| 35 |
dx = max(dx, -5) |
| 36 |
dy += random.randint(-3, 3) |
| 37 |
dy = min(dy, 5) |
| 38 |
dy = max(dy, -5) |
| 39 |
mainloop() |
Комментарии