xxxxxxxxxx
// make source public, Spring 2025
// schien@mail.ncku.edu.tw
// Example code for lecture "Adding Dimensions"
// an example from Pearson (2011)
// visualizing the noise as a rotation in animation
// schien@mail.ncku.edu.tw, DPD 2023
let xstart, xnoise, ystart, ynoise;
let xstartNoise, ystartNoise;
function setup() {
createCanvas(500, 500);
xstart = random(10);
ystart = random(15);
xstartNoise = random(20);
ystartNoise = random(20);
}
function draw() {
background(255);
xstartNoise += 0.01;
ystartNoise += 0.01;
xstart += (noise(xstartNoise) * 0.5) - 0.25;
ystart += (noise(ystartNoise) * 0.5) - 0.25;
xnoise = xstart;
ynoise = ystart;
// loop through all pixels
for (let y = 0; y <= height; y += 5) {
ynoise += 0.1;
xnoise = xstart; // reset the noise at the start of each row
for (let x = 0; x <= width; x += 5) {
xnoise += 0.1;
drawPoint(x, y, noise(xnoise, ynoise)); // the noise function that takes 2 parameters
}
}
}
function drawPoint(x, y, noiseFactor) {
push(); // start a new drawing state
translate(x, y);
rotate(noiseFactor * radians(360));
stroke(0, 150);
line(0, 0, 20, 0);
pop(); // restore original state
}