xxxxxxxxxx
41
const numRows = 10;
const numCols = 10;
let b = 0;
let h = 0;
let phase = 0;
let noiseMax;
let noiseSlider;
let vPad;
let hPad;
function setup() {
createCanvas(window.innerWidth, window.innerHeight * 0.95);
b = width / numCols;
h = height / numRows;
noiseSlider = createSlider(50, 200, 50, 1);
stroke(255);
noFill();
}
function draw() {
background(52);
noiseMax = noiseSlider.value();
vPad = height / noiseMax;
hPad = width / noiseMax;
for (let row = - floor(vPad); row < numRows + ceil(vPad); row++) {
beginShape(TRIANGLE_STRIP);
for (let col = - floor(hPad); col < numCols + ceil(hPad); col++) {
let xoff = row % 2 == 0 ? 0.5 : 0;
let x1 = (col + xoff) * b;
let y1 = row * h;
let x2 = (col + 0.5 + xoff) * b;
let y2 = (row + 1) * h;
vertex(x1 + map(noise(x1 / width + phase), 0, 1, -noiseMax, noiseMax),
y1 + map(noise(y1 / height + phase), 0, 1, -noiseMax, noiseMax));
vertex(x2 + map(noise(x2 / width + phase), 0, 1, -noiseMax, noiseMax),
y2 + map(noise(y2 / height + phase), 0, 1, -noiseMax, noiseMax));
}
endShape();
}
phase += 0.01;
}