xxxxxxxxxx
46
let points = [];
function setup() {
createCanvas(400, 400);
// Use HSB color mode, which is easier to control colour output in.
colorMode(HSB, 360, 100, 100, 100);
background(0);
// Set the fill colour to a fairly transparent black.
fill(0, 10);
}
function draw() {
console.log("d");
// Draw a transparent rectangle on the background to make old lines fade.
noStroke();
rect(0, 0, width, height);
// Loop over the array of points (we will learn more about this in T03)
for (let i = 0; i < points.length; i++) {
for (let j = 1; j < points[i].length; j++) {
// Get the point before, so we can draw a continuous line
let p1 = points[i][j - 1];
p1.x += randomGaussian() / 2;
p1.y += randomGaussian() / 2;
// Set the hue depending on how far through the line it is
let h = map(j, 0, points[i].length, 0, 360);
stroke(h, 80, 100, 80);
let p2 = points[i][j];
line(p1.x, p1.y, p2.x, p2.y);
}
}
}
function mousePressed() {
console.log("mp");
points.push([]);
}
function mouseDragged() {
points[points.length - 1].push(createVector(mouseX, mouseY));
}