forked from unconed/mathbox
/
repeat.html
122 lines (108 loc) · 2.65 KB
/
repeat.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>MathBox - Repeat</title>
<script src="../../build/mathbox-bundle.js"></script>
<link rel="stylesheet" href="../../build/mathbox.css">
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
</head>
<body>
<script>
mathbox = mathBox({
plugins: ['core', 'controls', 'cursor'],
controls: {
klass: THREE.OrbitControls
},
camera: {
near: .1,
far: 1000,
}
});
three = mathbox.three;
three.camera.position.set(7, 2, -7);
three.renderer.setClearColor(new THREE.Color(0xFFFFFF), 1.0);
function lerp(a, b, t) { return a + (b - a) * t; }
time = 0
three.on('update', function () {
time = three.Time.now
t = Math.max(three.Time.clock, 0) / 20
t = t < .5 ? t * t : t - .25
o = .5 - .5 * Math.cos(Math.min(1, t) * π)
p = .5 - .5 * Math.cos((t * 4) * π);
q = .5 - .5 * Math.cos((t * 1.13) * π);
m = .5 - .5 * Math.cos((t * 0.387) * π);
n = .5 - .5 * Math.cos(Math.max(0, Math.min(1, t - 40)) * π)
r = t * 2;
c = Math.cos(r);
s = Math.sin(r);
view.set('quaternion', [0, s, 0, c]);
view.set('bend', lerp(0.005, .721 - p * .1, o));
view.set('helix', o * .1);
r = o *.2 + q * .8 - m * 2 + n;
c = Math.cos(r);
s = Math.sin(r);
r = (m) * .1;
cc = Math.cos(r);
ss = Math.sin(r);
surface.set('quaternion', [s*cc, 0, s*ss, c]);
});
view = mathbox.set({ scale: 720, focus: 3 }).polar({
bend: 1/128,
range: [[-π, π], [-1, 1], [-1, 1]],
scale: [2, 2, 2],
});
view.interval({
width: 32,
centered: false,
expr: function (emit, x, i) {
var a = Math.sin(x + time) * .5 - 1;
var b = Math.cos(x - time * .917) * .25 - 1
emit(a);
emit(b);
},
items: 2,
channels: 1,
});
view.swizzle({
order: 'yx',
});
view.repeat({
height: 20,
depth: 11,
});
view.spread({
id: 'spread',
unit: 'absolute',
width: [π/31, 0, 0, 0],
height: [π, 0, 0, 0],
depth: [0, 0, 1/10, 0],
});
view.transpose({
order: 'zwxy'
});
view
.transform({
classes: ['surface'],
position: [0, 2, 0],
})
.surface({
color: 0x3090FF,
shaded: true,
lineX: true,
lineY: true,
})
.transpose({
source: '#spread',
order: 'wxzy',
})
.surface({
color: 0x3090FF,
shaded: true,
lineX: true,
lineY: true,
});
surface = mathbox.select('transform.surface');
</script>
</body>
</html>