-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdrawing.js
63 lines (54 loc) · 1.31 KB
/
drawing.js
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
52
53
54
55
56
57
58
59
60
61
62
63
(function() {
// Timeline control
var frame = 0, frameCount = 3 * 30;
// Canvas Size
var cx = 1920, cy = 1080;
/**
* Initialization
*
* Do anything that you need before drawing the first frame
* Such as clearing the canvas, initializing variables, etc
*/
var init = function(canvas) {
frame = 0;
}
/**
* Drawing
*
* For each frame, this function will be called.
* Draw the next frame on the canvas. The canvas contains the image of the previous frame
* You may want to keep track of the frame number yourself
*
* By default, the animations runs at 30 fps on a 1920x1080 canvas (see variable cx and cy)
*
* Return false when you want to end the movie
*/
var draw = function(canvas) {
// Get the canvas context to draw on
var ctx = canvas.getContext('2d');
if (frame > frameCount) {
// End of animation
return false;
}
// Drawing begins, clear canvas first
ctx.clearRect(0, 0, cx, cy);
ctx.fillStyle = "#fff";
ctx.fillRect(0,0,cx,cy);
// TODO: insert drawing code here...
ctx.strokeStyle = '#6cf';
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(cx * frame / frameCount, 0);
ctx.lineTo(cx * frame / frameCount, cy);
ctx.closePath();
ctx.stroke();
// Increments, then return true to let the animation continue
frame++;
return true;
}
// Exports
window.Animator = {
init: init,
draw: draw
}
})();