forked from edrobertsrayne/starfield
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnebula.js
More file actions
36 lines (30 loc) · 945 Bytes
/
Copy pathnebula.js
File metadata and controls
36 lines (30 loc) · 945 Bytes
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
class Nebula {
constructor() {
this.noise = new OpenSimplexNoise2D(Date.now());
this.imgBlue = createGraphics(width, height);
this.imgRed = createGraphics(width, height);
this.xoff = 0.002;
this.yoff = 0.002;
this.imgBlue.loadPixels();
this.imgRed.loadPixels();
for (let x = 0; x < width; x++) {
for (let y = 0; y < height; y++) {
let n = this.noise.noise(x * this.xoff, y * this.yoff);
let b = map(n, -1, 1, 0, 20);
let c = color(220, 50, b);
this.imgBlue.set(x, y, c);
n = this.noise.noise(x * this.xoff + 10000, y * this.yoff + 10000);
b = map(n, -1, 1, 0, 20);
this.imgRed.set(x, y, color(5, 40, b));
}
}
this.imgRed.updatePixels();
this.imgBlue.updatePixels();
}
draw() {
blendMode(LIGHTEST);
image(this.imgBlue, 0, 0, width, height);
image(this.imgRed, 0, 0, width, height);
blendMode(BLEND);
}
}