-
Notifications
You must be signed in to change notification settings - Fork 0
/
zdog-cat.js
91 lines (73 loc) · 1.65 KB
/
zdog-cat.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
let illo = new Zdog.Illustration({
element: '.zdog-canvas',
zoom: 10,
dragRotate: true,
});
// ---- model ---- //
// Sphere of head
let head = new Zdog.Shape({
addTo: illo,
stroke: 12,
color: '#EA0',
});
let rightEar = new Zdog.Hemisphere({
addTo: head,
diameter: 5,
translate: {z: 1, y: -4, x: 3},
rotate: { x: Zdog.TAU/6, y: -Zdog.TAU/14 },
// fill enabled by default
// disable stroke for crisp edge
stroke: .4,
color: '#C25',
backface: '#EA0',
});
// left ear
rightEar.copy({
translate: { x: -3, y: -4},
rotate: {x: Zdog.TAU/6, y: Zdog.TAU/14 }
});
let lefteye = new Zdog.Ellipse({
addTo: head,
diameter: 2,
quarters: 2, // semi-circle
translate: { x: -2, y: 1, z: 4.5 },
// rotate semi-circle to point up
rotate: { z: -Zdog.TAU/4},
color: Zdog.eggplant,
stroke: 0.5,
// hide when front-side is facing back
backface: false,
});
// right eye
lefteye.copy({
translate: { x: 2, y: 1, z: 4.5 },
});
let nose = new Zdog.Shape({
addTo: head,
path: [ // triangle
{ x: 0, y: -.5 },
{ x: .5, y: .5 },
{ x: -.5, y: .5 },
],
translate: { y: 2, z: 4.5 },
// closed by default
stroke: 1,
color: '#636'
});
// -- animate --- //
function animate() {
illo.updateRenderGraph();
requestAnimationFrame( animate );
}
let ticker = 0;
let cycleCount = 150;
function easeAnimate() {
let progress = ticker / cycleCount;
// apply easing to rotation
let tween = Zdog.easeInOut( progress % 1, 3 );
illo.rotate.y = tween * Zdog.TAU;
ticker++;
illo.updateRenderGraph();
requestAnimationFrame( easeAnimate );
}
easeAnimate();