xxxxxxxxxx
// make source public, Spring 2025
// schien@mail.ncku.edu.tw
// Example code for lecture "Adding Dimensions"
// an example from Pearson (2011)
// displaying a noise grid
// schien@mail.ncku.edu.tw, DPD 2023
function setup() {
createCanvas(500, 500);
noLoop();
}
function draw() {
background(255);
let xstart = random(10);
let xnoise = xstart;
let ynoise = random(10);
// loop through all pixels
for (let y = 0; y <= height; y += 1) {
ynoise += 0.01;
xnoise = xstart; // reset the noise at the start of each row
for (let x = 0; x <= width; x += 1) {
xnoise += 0.01;
drawPoint(x, y, noise(xnoise, ynoise));
}
}
}
function drawPoint(x, y, noiseFactor) {
let alph = int(noiseFactor * 255); // the noise function that takes 2 parameters
stroke(0, alph);
line(x, y, x+1, y+1);
}