-
Notifications
You must be signed in to change notification settings - Fork 1
/
noise.html
56 lines (44 loc) · 1.42 KB
/
noise.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
<!DOCTYPE html>
<html>
<head>
<title>syngen example: noise visualizer</title>
<script src="../dist/syngen.js"></script>
</head>
<body>
<p>This example visualizes randomly generated noise.</p>
<canvas></canvas>
<p>FPS: <span id="fps">0</span></p>
<script>
const noise = syngen.utility.createNoiseWithOctaves({
octaves: 1,
seed: 'test',
type: syngen.utility.simplex4d,
})
const size = 4,
scale = 100,
step = 1/60
const canvas = document.querySelector('canvas'),
context = canvas.getContext('2d'),
fps = document.querySelector('#fps')
let time = 0
canvas.height = canvas.width = size * scale
function draw() {
const data = context.getImageData(0, 0, canvas.width, canvas.height)
for (let i = 0; i < data.data.length; i += 4) {
const x = (i / 4) % data.width,
y = Math.floor((i / 4) / data.width)
const noiseValue = noise.value((x / scale) + time, (y / scale) + time, time, 0),
value = Math.round(noiseValue * 255)
data.data[i] = value
data.data[i + 1] = value
data.data[i + 2] = value
data.data[i + 3] = 255
}
context.putImageData(data, 0, 0)
fps.innerHTML = syngen.performance.fps()
time += step
}
syngen.loop.on('frame', draw).start()
</script>
</body>
</html>