46
1
/*
2
Animation Loop
3
This code demonstrates using the animation loop
4
to draw a moving circle.
5
6
The circle will start at the center of the
7
left side canvas and move off the canvas to the
8
right.
9
*/
10
11
/*
12
Variables for the center of the moving circle.
13
These are declared outside of any function so
14
that they are global and can be used in any
15
function
16
*/
17
var x,y;
18
19
function setup(){
20
//Set the initial position of the circle
21
x=0;
22
y=height/2;
23
24
/*
25
Set the number of miliseconds to wait
26
between drawing. The larger this number is,
27
the slower the animation will be.
28
*/
29
timestep(50);
30
31
//call loop to make the draw function be
32
//called repeatedly.
33
loop();
34
}
35
function draw(){
36
//clear canvas for next frame
37
clear();
38
39
//draw filled circle
40
circle(x,y,10);
41
fill();
42
43
//update x coordinate to move the circle
44
x=x+1;
45
}
46