-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoise.js
96 lines (74 loc) · 2.36 KB
/
noise.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import png from 'pngjs';
import fs from 'fs';
import hash2 from './lib/hash2.js';
import { prng_alea } from 'esm-seedrandom';
import { prng_xor128 } from 'esm-seedrandom';
const { PNG } = png;
const size = 1024;
let p = new PNG({ width: size, height: size });
for (let y = 0; y < p.height; y++) {
for (let x = 0; x < p.width; x++) {
let idx = (p.width * y + x) << 2;
let col = hash2(0, x, y);
p.data[idx] = (col & 0xff000000) >> 24;
p.data[idx + 1] = (col & 0x00ff0000) >> 16;
p.data[idx + 2] = (col & 0x0000ff0000) >> 8;
p.data[idx + 3] = col & 0x000000ff;
}
}
p.pack()
.pipe(fs.createWriteStream('./xx.png'))
.on('finish', function () {
console.log('XX');
});
// Non seeded random will push a new image to git every time
// p = new PNG({ width: size, height: size });
// for (let y = 0; y < p.height; y++) {
// for (let x = 0; x < p.width; x++) {
// let idx = (p.width * y + x) << 2;
// let col = (Math.random() * 0xffffffff) >>> 0;
// p.data[idx] = (col & 0xff000000) >>> 24;
// p.data[idx + 1] = (col & 0x00ff0000) >>> 16;
// p.data[idx + 2] = (col & 0x0000ff0000) >>> 8;
// p.data[idx + 3] = col & 0x000000ff;
// }
// }
// p.pack()
// .pipe(fs.createWriteStream('./random.png'))
// .on('finish', function () {
// console.log('Random');
// });
let alea = prng_alea(0);
p = new PNG({ width: size, height: size });
for (let y = 0; y < p.height; y++) {
for (let x = 0; x < p.width; x++) {
let idx = (p.width * y + x) << 2;
let col = (alea.quick() * 0xffffffff) >>> 0;
p.data[idx] = (col & 0xff000000) >>> 24;
p.data[idx + 1] = (col & 0x00ff0000) >>> 16;
p.data[idx + 2] = (col & 0x0000ff0000) >>> 8;
p.data[idx + 3] = col & 0x000000ff;
}
}
p.pack()
.pipe(fs.createWriteStream('./alea.png'))
.on('finish', function () {
console.log('Alea');
});
let xor = prng_xor128('0');
p = new PNG({ width: size, height: size });
for (let y = 0; y < p.height; y++) {
for (let x = 0; x < p.width; x++) {
let idx = (p.width * y + x) << 2;
let col = (xor.quick() * 0xffffffff) >>> 0;
p.data[idx] = (col & 0xff000000) >>> 24;
p.data[idx + 1] = (col & 0x00ff0000) >>> 16;
p.data[idx + 2] = (col & 0x0000ff0000) >>> 8;
p.data[idx + 3] = col & 0x000000ff;
}
}
p.pack()
.pipe(fs.createWriteStream('./xor.png'))
.on('finish', function () {
console.log('Xor');
});