forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slow-fade.html
46 lines (44 loc) · 935 Bytes
/
slow-fade.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Slow Fade</title>
</head>
<body>
<h1>Slow Fade</h1>
<div>
<canvas id="c"></canvas>
</div>
</body>
<script src="../dist/gpu-browser.min.js"></script>
<script>
const canvas = document.getElementById('c');
const gpu = new GPU({
canvas: canvas,
mode: 'gpu'
});
const dim = 512;
const kernel = gpu.createKernel(
function(x) {
this.color(
(x * (this.thread.y + this.thread.x)) / 1024,
(x * (this.thread.y * this.thread.x)) / (1024 * 1024),
(x * (this.thread.y * 2 * this.thread.x)) / (1024 * 2),
1
);
},
{
useLegacyEncoder: true,
output: [dim, dim],
graphical: true
}
);
let param = 0;
const doDraw = () => {
kernel(param);
param += 0.001;
window.requestAnimationFrame(doDraw);
};
window.requestAnimationFrame(doDraw);
</script>
</html>