-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathprocedural.html
132 lines (121 loc) · 3.18 KB
/
procedural.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>MathBox - Procedural Vectors</title>
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/three@0.137.0/build/three.min.js"
></script>
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/three@0.137.0/examples/js/controls/OrbitControls.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>
mathbox = MathBox.mathBox({
plugins: ["core", "controls", "cursor"],
controls: {
klass: THREE.OrbitControls,
},
});
three = mathbox.three;
three.camera.position.set(3.5, 1.4, -2.3);
three.renderer.setClearColor(new THREE.Color(0x204060), 1.0);
time = 0;
three.on("update", function () {
clock = three.Time.clock;
time = clock / 4;
t = Math.max(clock - 1, 0) / 12;
t = t < 0.5 ? t * t : t - 0.25;
o = 0.5 - 0.5 * Math.cos(Math.min(1, t) * MathBox.π);
c = Math.cos(t);
s = Math.sin(t);
view.set("quaternion", [0, -s, 0, c]);
surface.set("opacity", 1 - o * 0.25);
f = 1 + o;
view.set("range", [
[-3 * f, 3 * f],
[0, 6],
[-3 * f, 3 * f],
]);
view.set("scale", [2 * f, 2, 2 * f]);
});
view = mathbox
.unit({
scale: 720,
})
.cartesian({
range: [
[-3, 3],
[0, 6],
[-3, 3],
],
scale: [2, 2, 2],
});
view.grid({
width: 5,
opacity: 0.5,
axes: [1, 3],
});
view.area({
width: 36,
height: 36,
items: 2,
axes: [1, 3],
expr: function (emit, x, y, i, j) {
a = Math.sin(i * 31.718 - time) * Math.sin(j * 21.131 + time);
b =
Math.sin(i * 27.41 + time) *
Math.sin(j * 11.91 + 5 * Math.cos(i * 4.1) + time);
emit(x, 3 * (1 + a), y);
emit(x, 3 * (1 + a + b * 0.25), y);
},
channels: 3,
});
view.vector({
color: 0xa0d0ff,
width: 5,
start: false,
end: true,
});
view.area({
id: "sampler",
width: 83,
height: 83,
axes: [1, 3],
expr: function (emit, x, y, i, j) {
emit(
x,
3 * (0.5 + 0.5 * (Math.sin(x + time) * Math.sin(y + time))),
y
);
},
channels: 3,
});
view.surface({
lineX: true,
lineY: true,
shaded: true,
color: 0x5090ff,
width: 5,
});
surface = mathbox.select("surface");
vector = mathbox.select("vector");
</script>
</body>
</html>