diff --git a/0. Randomness/8. Perlin noise/index.html b/0. Randomness/8. Perlin noise/index.html new file mode 100644 index 0000000..c390616 --- /dev/null +++ b/0. Randomness/8. Perlin noise/index.html @@ -0,0 +1,15 @@ + + + + + + + +
+
+ + diff --git a/0. Randomness/8. Perlin noise/sketch.js b/0. Randomness/8. Perlin noise/sketch.js new file mode 100644 index 0000000..5f22e02 --- /dev/null +++ b/0. Randomness/8. Perlin noise/sketch.js @@ -0,0 +1,26 @@ +let increment = 0.01 +let octaves = 3 +let falloff = 0.3 + +function setup() { + createCanvas(640, 240) + pixelDensity(1) + noiseDetail(octaves, falloff) +} + +function draw() { + loadPixels() + for (let x = 0; x < width; x++) { + for (let y = 0; y < height; y++) { + let index = (x + y * width) * 4 + + let noiseValue = noise(x*increment, y*increment) + let bright = map(noiseValue, 0, 1, 0, 255) + pixels[index+0] = bright + pixels[index+1] = bright + pixels[index+2] = bright + pixels[index+3] = 255 + } + } + updatePixels() +}