This repository was archived by the owner on Dec 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
Expand file tree
/
Copy path02-extruded-a-depth.html
More file actions
133 lines (122 loc) · 6.36 KB
/
02-extruded-a-depth.html
File metadata and controls
133 lines (122 loc) · 6.36 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Extruded A Depth</title>
<link rel="stylesheet" href="../include/style.css">
</head>
<body>
<header>
Example from <a href="http://amzn.com/1430236655?tag=html5anim-20"><em>Foundation HTML5 Animation with JavaScript</em></a>
</header>
<canvas id="canvas" width="400" height="400"></canvas>
<aside>Move mouse on canvas element.</aside>
<script src="../include/utils.js"></script>
<script src="./classes/point3d.js"></script>
<script src="./classes/triangle.js"></script>
<script>
window.onload = function () {
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d'),
mouse = utils.captureMouse(canvas),
points = [],
triangles = [],
fl = 250,
vpX = canvas.width / 2,
vpY = canvas.height / 2,
angleX, angleY;
//first set
points[0] = new Point3d( -50, -250, -50);
points[1] = new Point3d( 50, -250, -50);
points[2] = new Point3d( 200, 250, -50);
points[3] = new Point3d( 100, 250, -50);
points[4] = new Point3d( 50, 100, -50);
points[5] = new Point3d( -50, 100, -50);
points[6] = new Point3d(-100, 250, -50);
points[7] = new Point3d(-200, 250, -50);
points[8] = new Point3d( 0, -150, -50);
points[9] = new Point3d( 50, 0, -50);
points[10] = new Point3d( -50, 0, -50);
//second set
points[11] = new Point3d( -50, -250, 50);
points[12] = new Point3d( 50, -250, 50);
points[13] = new Point3d( 200, 250, 50);
points[14] = new Point3d( 100, 250, 50);
points[15] = new Point3d( 50, 100, 50);
points[16] = new Point3d( -50, 100, 50);
points[17] = new Point3d(-100, 250, 50);
points[18] = new Point3d(-200, 250, 50);
points[19] = new Point3d( 0, -150, 50);
points[20] = new Point3d( 50, 0, 50);
points[21] = new Point3d( -50, 0, 50);
points.forEach(function (point) {
point.setVanishingPoint(vpX, vpY);
point.setCenter(0, 0, 200);
});
triangles[0] = new Triangle(points[0], points[1], points[8], "#6666cc");
triangles[1] = new Triangle(points[1], points[9], points[8], "#6666cc");
triangles[2] = new Triangle(points[1], points[2], points[9], "#6666cc");
triangles[3] = new Triangle(points[2], points[4], points[9], "#6666cc");
triangles[4] = new Triangle(points[2], points[3], points[4], "#6666cc");
triangles[5] = new Triangle(points[4], points[5], points[9], "#6666cc");
triangles[6] = new Triangle(points[9], points[5], points[10], "#6666cc");
triangles[7] = new Triangle(points[5], points[6], points[7], "#6666cc");
triangles[8] = new Triangle(points[5], points[7], points[10], "#6666cc");
triangles[9] = new Triangle(points[0], points[10], points[7], "#6666cc");
triangles[10] = new Triangle(points[0], points[8], points[10], "#6666cc");
triangles[11] = new Triangle(points[11], points[19], points[12], "#cc6666");
triangles[12] = new Triangle(points[12], points[19], points[20], "#cc6666");
triangles[13] = new Triangle(points[12], points[20], points[13], "#cc6666");
triangles[14] = new Triangle(points[13], points[20], points[15], "#cc6666");
triangles[15] = new Triangle(points[13], points[15], points[14], "#cc6666");
triangles[16] = new Triangle(points[15], points[20], points[16], "#cc6666");
triangles[17] = new Triangle(points[20], points[21], points[16], "#cc6666");
triangles[18] = new Triangle(points[16], points[18], points[17], "#cc6666");
triangles[19] = new Triangle(points[16], points[21], points[18], "#cc6666");
triangles[20] = new Triangle(points[11], points[18], points[21], "#cc6666");
triangles[21] = new Triangle(points[11], points[21], points[19], "#cc6666");
triangles[22] = new Triangle(points[0], points[11], points[1], "#cccc66");
triangles[23] = new Triangle(points[11], points[12], points[1], "#cccc66");
triangles[24] = new Triangle(points[1], points[12], points[2], "#cccc66");
triangles[25] = new Triangle(points[12], points[13], points[2], "#cccc66");
triangles[26] = new Triangle(points[3], points[2], points[14], "#cccc66");
triangles[27] = new Triangle(points[2], points[13], points[14], "#cccc66");
triangles[28] = new Triangle(points[4], points[3], points[15], "#cccc66");
triangles[29] = new Triangle(points[3], points[14], points[15], "#cccc66");
triangles[30] = new Triangle(points[5], points[4], points[16], "#cccc66");
triangles[31] = new Triangle(points[4], points[15], points[16], "#cccc66");
triangles[32] = new Triangle(points[6], points[5], points[17], "#cccc66");
triangles[33] = new Triangle(points[5], points[16], points[17], "#cccc66");
triangles[34] = new Triangle(points[7], points[6], points[18], "#cccc66");
triangles[35] = new Triangle(points[6], points[17], points[18], "#cccc66");
triangles[36] = new Triangle(points[0], points[7], points[11], "#cccc66");
triangles[37] = new Triangle(points[7], points[18], points[11], "#cccc66");
triangles[38] = new Triangle(points[8], points[9], points[19], "#cccc66");
triangles[39] = new Triangle(points[9], points[20], points[19], "#cccc66");
triangles[40] = new Triangle(points[9], points[10], points[20], "#cccc66");
triangles[41] = new Triangle(points[10], points[21], points[20], "#cccc66");
triangles[42] = new Triangle(points[10], points[8], points[21], "#cccc66");
triangles[43] = new Triangle(points[8], points[19], points[21], "#cccc66");
function move (point) {
point.rotateX(angleX);
point.rotateY(angleY);
}
function depth (a, b) {
return (b.getDepth() - a.getDepth());
}
function draw (triangle) {
triangle.draw(context);
}
(function drawFrame () {
window.requestAnimationFrame(drawFrame, canvas);
context.clearRect(0, 0, canvas.width, canvas.height);
angleX = (mouse.y - vpY) * 0.0005;
angleY = (mouse.x - vpX) * 0.0005;
points.forEach(move);
triangles.sort(depth);
triangles.forEach(draw);
}());
};
</script>
</body>
</html>