-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathParade.pv
More file actions
51 lines (44 loc) · 1.68 KB
/
Copy pathParade.pv
File metadata and controls
51 lines (44 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""A balloon-launch simulation.
This example shows object-oriented design in animation for
defining a set of "actors" (the balls) that parade on stage.
"""
speed(30)
size(340, 482)
# Import PRNG and trigonometry functions
from random import seed
from math import sin,cos
# The main actor in the animation is a Balloon.
# A Ball has a set of state values: its position, size, color and delta-values.
# The delta-values affect the position and size, and are a simple way to give
# each ball "character". Higher delta-values make the ball more hectic.
class Balloon:
# Initialize a ball -- set all the values to their defaults.
def __init__(self):
self.x = random(WIDTH)
self.y = random(HEIGHT)
self.size = random(10, 72)
self.dx = self.dy = self.ds = 0.0
self.color = color(random(), 1, random(0,2), random())
# Update the internal state values.
def update(self):
self.dx = sin(FRAME/float(random(5,100))) * 20.0
self.dy = cos(FRAME/float(random(5,100))) * 20.0
self.ds = cos(FRAME/float(random(5,100))) * 10.0
# Draw a ball: set the fill color first and draw a circle.
def draw(self):
fill(self.color)
arc(self.x + self.dx, self.y + self.dy, self.size + self.ds)
# Initialize the animation by instantiating a list of balls.
def setup(anim):
anim.balloons = []
for i in range(30):
anim.balloons.append(Balloon())
# Draw the animation by updating and drawing each individual ball.
def draw(anim):
background(0.2)
seed(1)
# This translate command makes the ball move up on the screen.
translate(0, HEIGHT-FRAME)
for ball in anim.balloons:
ball.update()
ball.draw()