42
1
/*
2
Path Example
3
This example uses motion to mark 50 steps
4
along a path with gravity.
5
6
In this example, we use a for loop instead
7
of the animation loop to draw.
8
9
We also use fillrect to fill a pixel rather
10
than drawing a circle.
11
*/
12
function setup(){
13
//no special setup needed
14
}
15
function draw(){
16
var x,y; //coordinates
17
var vx,vy; //velocity
18
var ax,ay; //acceleration
19
var i; //index
20
21
//random position
22
x=random()*width;
23
y=random()*height;
24
25
//random velocity - but vy is going up
26
vx=random();
27
vy=-random();
28
29
//a little bit of gravity
30
ax=0;
31
ay=.01;
32
33
//draw 50 steps of path
34
for (i=0;i<50;i++){
35
fillrect(x,y,1,1);
36
x=x+vx;
37
y=y+vy;
38
vx=vx+ax;
39
vy=vy+ay;
40
}
41
}
42