-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestWebgl2.js
75 lines (63 loc) · 1.95 KB
/
testWebgl2.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
import { Component, cleanup, load, save, update } from "./rahti/component";
import { EventListener } from "./rahti/dom";
import { State } from "./rahti/state";
import { AnimationFrame } from "./webgl2/animationFrame";
export const Webgl2App = new Proxy(function ({
smallTexture,
QuadInstance,
cameraController,
frame,
clear,
drawTriangle,
drawQuads,
}) {
EventListener(document, "pointermove", ({ x, y }) => {
cameraController.target[0] = -x * 0.001;
cameraController.target[1] = y * 0.001;
});
TriangleUpdater(smallTexture);
Quads(QuadInstance);
frame(() => {
clear();
drawTriangle();
drawQuads();
});
}, Component);
// export const lol = "lol";
const TriangleUpdater = new Proxy(function (smallTexture) {
AnimationFrame();
smallTexture.update(
Uint8Array.of(Math.random() * 255, Math.random() * 255, Math.random() * 255, 255),
Math.random() * 64,
Math.random() * 64,
);
}, Component);
const Quads = new Proxy(function (QuadInstance) {
const [max, setMax] = State(100);
save(setTimeout(setMax, Math.random() * 2000, 100 * (0.5 + Math.random() * 0.5)));
cleanup(cleanTimer);
// const max = 100 * (0.5 + Math.random() * 0.5);
// AnimationFrame();
for (let index = 0; index < max; index++) {
if (Math.random() < 0.01) continue;
Quad(index, QuadInstance);
}
}, Component);
const cleanTimer = (timer) => clearTimeout(timer);
const Quad = new Proxy(
function (index, QuadInstance) {
const instance = QuadInstance();
instance.offset[0] = -index * 0.02;
instance.offset[1] = -index * 0.02;
instance.color[0] = Math.random();
instance.color[1] = Math.random();
instance.color[2] = Math.random();
QuadUpdater(instance);
},
{ ...Component, getKey: (index) => index },
);
const QuadUpdater = new Proxy(function (instance) {
AnimationFrame();
instance.offset[0] += (Math.random() * 2 - 1) * 0.003;
instance.offset[1] += (Math.random() * 2 - 1) * 0.003;
}, Component);