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 in animation
// visualize the noise as little fluffy clouds
// schien@mail.ncku.edu.tw, DPD 2023
let xstart, xnoise, ystart, ynoise;
function setup() {
createCanvas(500, 500);
xstart = random(10);
ystart = random(10);
}
function draw() {
background(0);
xstart += 0.01;
ystart += 0.01;
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();
translate(x, y);
rotate(noiseFactor * radians(540));
let edgeSize = noiseFactor*35;
let gcolor = 150 + (noiseFactor*120);
let alph = 150 + (noiseFactor*120);
noStroke();
fill(gcolor, alph);
ellipse(0, 0, edgeSize, edgeSize/2);
pop();
}