xxxxxxxxxx
// make source code public
// schien@mail.ncku.edu.tw, Spring 2025
//
// draw a wiggly line
// program for lectures on "The Wrong Way to Draw a Line"
//
// schien@mail.ncku.edu.tw, DPD 2023
//
function setup() {
createCanvas(500, 100);
noLoop();
}
function draw() {
background(255);
strokeWeight(5);
stroke(0, 30);
line(20, 50, 480, 50); // draw a line
stroke(20, 50, 70, 180);
let step = 10;
let lastx = -999;
let lasty = -999;
let y = 50;
let border = 20;
for (let x=border; x<=width-border; x+=step) {
let ystep = random(20) - 10;
y += ystep;
if (lastx > -999) {
line(x, y, lastx, lasty);
}
lastx = x;
lasty = y;
}
}