39
1
/*
2
Random Path Example
3
This example uses motion to mark 50 steps
4
along a path in which the direction/angle
5
of each step is random.
6
7
To choose a random direction, we choose a
8
random angle. We then take a step with
9
vx=COS(angle) ad vy=SIN(angle).
10
*/
11
function setup(){
12
//no special setup needed
13
}
14
function draw(){
15
var x,y; //coordinates
16
var vx,vy; //velocity
17
var angle; //angle/direction
18
var i; //index
19
20
//start in middle of screen
21
x=width/2;
22
y=height/2;
23
24
//draw 500 steps of path
25
for (i=0;i<500;i++){
26
fillrect(x,y,1,1);
27
28
//update velocity
29
angle=random()*360;
30
vx=COS(angle);
31
vy=SIN(angle);
32
33
//update position
34
x=x+vx;
35
y=y+vy;
36
37
}
38
}
39