xxxxxxxxxx
// make source code public
// schien@mail.ncku.edu.tw, Spring 2025
//
// the baby-step way to draw a line in variations with noise
// program for lectures on "The Wrong Way to Draw a Line"
// schien@mail.ncku.edu.tw, Fall 2018
// revised for DPD 2023
//
function setup() {
createCanvas(500, 100);
noLoop();
}
function draw() {
background(255);
strokeWeight(5);
stroke(0, 30);
line(20, 50, 480, 50);
stroke(20, 50, 70, 150);
let step = 10;
let nlevel = 0.1;
let lastx = -999;
let lasty = -999;
let ynoise = random(10);
let y;
let border = 20;
for (var x=border; x<=width-border; x+=step) {
y = 10 + noise(ynoise)*80;
if (lastx > -999) {
line(x, y, lastx, lasty);
}
lastx = x;
lasty = y;
ynoise += nlevel;
}
}