-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbezier.js
More file actions
44 lines (40 loc) · 935 Bytes
/
bezier.js
File metadata and controls
44 lines (40 loc) · 935 Bytes
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
window.onload = function() {
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
width = canvas.width = window.innerWidth,
height = canvas.height = window.innerHeight,
p0 = {
x: utils.randomRange(0, width),
y: utils.randomRange(0, height)
},
p1 = {
x: utils.randomRange(0, width),
y: utils.randomRange(0, height)
},
p2 = {
x: utils.randomRange(0, width),
y: utils.randomRange(0, height)
},
p3 = {
x: utils.randomRange(0, width),
y: utils.randomRange(0, height)
},
maxT = 0,
pFinal = {};
draw();
function draw() {
context.clearRect(0, 0, width, height);
context.beginPath();
context.moveTo(p0.x, p0.y);
for(var t = 0; t <= maxT; t += 0.01) {
utils.cubicBezier(p0, p1, p2, p3, t, pFinal);
context.lineTo(pFinal.x, pFinal.y);
}
context.stroke();
maxT += 0.01;
if(maxT > 1) {
maxT = 0;
}
requestAnimationFrame(draw);
}
};