Skip to content

Commit 21bb6eb

Browse files
takyanolimzykenneth
authored andcommitted
Noise2D update
An update to the Noise2D example
1 parent 4baa951 commit 21bb6eb

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

src/data/examples/en/08_Math/15_Noise2D.js

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,41 @@ function setup() {
1212
createCanvas(640, 360);
1313
}
1414

15+
function drawNoise(x, y, w, h) {
16+
for (let yp = y; yp < y + h; yp++) {
17+
let yindex = yp * width;
18+
for (let xp = x; xp < x + w; xp++) {
19+
let noiseVal =
20+
noise((mouseX + xp) * noiseScale, (mouseY + yp) * noiseScale) * 255;
21+
22+
let xindex = xp;
23+
let index = 4 * (yindex + xindex);
24+
pixels[index] = noiseVal;
25+
pixels[index + 1] = noiseVal;
26+
pixels[index + 2] = noiseVal;
27+
pixels[index + 3] = 255;
28+
}
29+
}
30+
}
31+
1532
function draw() {
1633
background(0);
34+
35+
loadPixels();
36+
1737
// Draw the left half of image
18-
for (let y = 0; y < height - 30; y++) {
19-
for (let x = 0; x < width / 2; x++) {
20-
// noiseDetail of the pixels octave count and falloff value
21-
noiseDetail(2, 0.2);
22-
noiseVal = noise((mouseX + x) * noiseScale, (mouseY + y) * noiseScale);
23-
stroke(noiseVal * 255);
24-
point(x, y);
25-
}
26-
}
38+
noiseDetail(2, 0.2);
39+
drawNoise(0, 0, width / 2, height - 30);
40+
2741
// Draw the right half of image
28-
for (let y = 0; y < height - 30; y++) {
29-
for (let x = width / 2; x < width; x++) {
30-
// noiseDetail of the pixels octave count and falloff value
31-
noiseDetail(5, 0.5);
32-
noiseVal = noise((mouseX + x) * noiseScale, (mouseY + y) * noiseScale);
33-
stroke(noiseVal * 255);
34-
point(x, y);
35-
}
36-
}
42+
noiseDetail(5, 0.5);
43+
drawNoise(width / 2, 0, width / 2, height - 30);
44+
45+
updatePixels();
46+
3747
//Show the details of two partitions
3848
textSize(18);
3949
fill(255, 255, 255);
40-
text('Noise2D with 2 octaves and 0.2 falloff', 10, 350);
41-
text('Noise2D with 5 octaves and 0.5 falloff', 330, 350);
50+
text("Noise2D with 2 octaves and 0.2 falloff", 10, 350);
51+
text("Noise2D with 5 octaves and 0.5 falloff", 330, 350);
4252
}

0 commit comments

Comments
 (0)