generated from mwc/project_drawing
Adding examples
This commit is contained in:
parent
0b609de21e
commit
882cedb841
|
@ -0,0 +1,34 @@
|
|||
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)
|
||||
|
Loading…
Reference in New Issue