xxxxxxxxxx
36
// Comparing perlin noise and random
//
// Top half of the canvas is filled with a row of
// rectangles each with fill color set from the
// noise function. The bottom row has them set from
// the random function.
function setup() {
createCanvas(400, 400);
background(220);
noStroke();
// The point we sample the noise at.
let xSample = 0;
// Distance between sample points.
let inc = 0.05;
// Loop across the width of the canvas
for (let i = 0; i < width; i = i + 10) {
// Create one fill based on noise
// and draw a rectangle for the top half
let noiseGrey = noise(xSample) * 255;
fill(noiseGrey);
rect(i, 0, 10, height / 2);
// Create another fill based on randomness
// and draw a rectangle for the bottom half
let randomGrey = random(255);
fill(randomGrey);
rect(i, height / 2, 10, height / 2);
// Move the sample point
xSample = xSample + inc;
}
}