forked from TerribleHack/terriblehack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cat.js
106 lines (92 loc) · 1.66 KB
/
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function petCat(heading) {
push();
translate(-catPosition.x, -catPosition.y, -catPosition.z);
translate(camera.x - 500, -450, camera.z);
textSize(24);
textAlign(CENTER);
fill(255);
text("Cat", 0, 0);
const toCat = catPosition.copy().sub(camera.copy().add(-500, -450, 0)).setMag(25);
translate(0, 30, 0);
stroke(255);
line(
0, 0, 0,
toCat.x, toCat.y, toCat.z
);
noStroke();
translate(toCat.x, toCat.y, toCat.z);
sphere(5, 5, 5);
pop();
push();
translate(40, -250, 0);
textSize(24);
fill(255);
textAlign(CENTER);
text("Pet the cat", 0, 0);
pop();
push();
rotateY(PI - heading);
cat();
pop();
}
function cat() {
noStroke();
ambientMaterial(250);
push();
translate(-40, -50, 0);
// Head
sphere(20, 5, 5);
// Body
push();
translate(50, 0, 0);
scale(2, 1, 1);
sphere(20, 10, 10);
pop();
// Ears
[-1, 1].forEach(side => {
push();
translate(-8, -15, side*8);
scale(1, 1.8, 1);
sphere(7, 5, 5);
pop();
});
// Eyes
[-1, 1].forEach(side => {
noStroke();
fill(255);
emissiveMaterial(255);
push();
translate(-20, -5, side*8);
sphere(5, 5, 5);
pop();
});
stroke(200, 50, 50);
ambientMaterial(250);
noFill();
// tail
push();
translate(90, 0, 0);
beginShape();
vertex(0, 0, 0);
bezierVertex(
20, 0, 0,
20, -40, 0,
40, -40, 0
);
endShape();
pop();
// Legs
push();
translate(50, 0, 0);
[-1, 1].forEach(side1 => {
[-1, 1].forEach(side2 => {
line(
side1*25, 0, side2*15,
side1*25 + sin(3*side1 + 2*side2 + frameCount/10)*20,
50, side2*15
);
});
});
pop();
pop();
}