-
-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathgrow.html
185 lines (173 loc) · 4.34 KB
/
grow.html
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>MathBox - Grow</title>
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/three@0.137.0/build/three.min.js"
></script>
<!--
- a minified version mathbox.min.js is also available;
- recommend using a specific version (not @latest) in public sites
-->
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/mathbox@latest/build/bundle/mathbox.js"
></script>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/mathbox@latest/build/mathbox.css"
/>
<meta name="viewport" content="initial-scale=1, maximum-scale=1" />
</head>
<body>
<script>
var mathbox = MathBox.mathBox({
plugins: ["core"],
});
var three = mathbox.three;
three.renderer.setClearColor(new THREE.Color(0xffffff), 1.0);
function previous() {
present.set("index", present.get("index") - 1);
}
function next() {
present.set("index", present.get("index") + 1);
}
if (window == top)
window.onkeydown = function (e) {
switch (e.keyCode) {
case 37:
case 38:
previous();
break;
case 39:
case 40:
next();
break;
}
//console.log(present.get('index'));
};
var size = 1.2;
var scale = 1.6;
var view = mathbox.cartesian({
range: [
[-size, size],
[-size, size],
[-size, size],
],
scale: [scale, scale, scale],
});
view.axis({
axis: "x",
size: 5,
color: "red",
});
view.axis({
axis: "y",
size: 5,
color: "green",
});
var present = view.present({
index: 1,
});
// Nest the whole presentation in a slide
// This means any .step() directly inside will follow present.index directly
var slide = present.slide();
// Camera has a global script of steps
slide
.camera({
lookAt: [0, 0, 0],
proxy: true,
})
.step({
pace: 1,
script: {
0: { position: [0, 0, 3], up: [0, 1, 0] },
1: { position: [0, -2.5, 0.4], up: [0, 0, 1] },
},
});
// Points are visible the entire presentation
slide
.array({
width: 16,
items: 2,
channels: 3,
fps: 60,
live: false,
expr: function (emit) {
var x = Math.random() * 2 - 1;
var y = Math.random() * 2 - 1;
emit(x, y, 0); // footprint
emit(x, y, x * x + y * y); // point
},
})
// Grow points on step 2
// Use first item as reference point
.grow({
items: "first",
})
.step({
delay: 2,
pace: 2,
trigger: 1,
script: [{ props: { scale: 0 } }, { props: { scale: 1 } }],
})
// Connect footprint and point with line
.vector({
width: 3,
})
// Draw second point only
.slice({
items: [1, 2],
})
.point({
size: 8,
});
// Paraboloid is revealed next and stays for 2 steps
// Make a subslide for this to keep the current slide visible too
slide
.slide({
steps: 2,
})
.reveal({
delay: 1,
duration: 1.2,
})
.area({
axes: "xy",
width: 24,
height: 24,
channels: 3,
items: 1,
live: false,
expr: function (emit, x, y) {
emit(x, y, x * x + y * y);
},
})
.surface({
opacity: 0.2,
shaded: true,
lineX: true,
lineY: true,
})
.step({
script: [{ props: { opacity: 0.2 } }, { props: { opacity: 1 } }],
});
</script>
<div
style="
position: absolute;
bottom: 15px;
left: 50%;
margin-left: -60px;
width: 120px;
font-size: 20px;
text-align: center;
"
>
<button onclick="previous()"><</button
><button onclick="next()">></button>
</div>
</body>
</html>