-
Notifications
You must be signed in to change notification settings - Fork 8
/
perlin.js
39 lines (29 loc) · 868 Bytes
/
perlin.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
var time = Date.now();
console.log(time);
var perlin = require('perlin-noise');
var noise = perlin.generatePerlinNoise(288, 1, {
amplitude: 0.3,
octaveCount: 3,
persistence: 0.3,
});
console.log(noise);
const nuevo = noise.map((i) => Number(i));
console.log(nuevo);
var totalNoise = nuevo.reduce((a ,b) => a + b, 0);
var meanNoise = (totalNoise / nuevo.length) || 0;
console.log('this is the noise sum:',totalNoise);
console.log('this is the noise mean:',meanNoise);
const myObject = [];
var i = 0;
for (i=0; i<noise.length; i++) {
myObject.push(
{noise: noise[i]/10-0.05, order: (i), time : time + (i)*1000*60*5})
}
console.log(myObject);
const datamyObject = JSON.stringify(myObject, null, 4);
const fs = require('fs');
fs.writeFile('./files/perlin.json', datamyObject, (err) => {
if (err) {
throw err;
}
});