generated from mwc/project_drawing
35 lines
868 B
Python
35 lines
868 B
Python
from turtle import *
|
|
from superturtle.animation import animate
|
|
from random import random, seed
|
|
|
|
HOW_FAR_BUBBLES_GO = 400
|
|
|
|
def random_bubble_x():
|
|
return -200 + 400 * random()
|
|
|
|
def random_bubble_y():
|
|
return -200 + 400 * random()
|
|
|
|
def random_bubble_size():
|
|
return 10 + 40 * random()
|
|
|
|
def generate_bubble_positions(n):
|
|
bubble_positions = []
|
|
for i in range(n):
|
|
x = random_bubble_x()
|
|
y = random_bubble_y()
|
|
r = random_bubble_size()
|
|
bubble_positions.append([x, y, r])
|
|
return bubble_positions
|
|
|
|
def draw_bubbles(bubble_positions, frame):
|
|
for x, y, r in bubble_positions:
|
|
with frame.translate([x, y], [x, y + HOW_FAR_BUBBLES_GO]):
|
|
circle(r)
|
|
|
|
number_of_bubbles = 25
|
|
bubble_positions = generate_bubble_positions(number_of_bubbles)
|
|
for frame in animate(100):
|
|
draw_bubbles(bubble_positions, frame)
|
|
|