xxxxxxxxxx
45
let x, y;
let gogo = true;
function setup() {
createCanvas(800, 800);
x = width / 2;
y = height / 2;
pdf = createPDF();
pdf.beginRecord();
strokeWeight(1);
noFill();
stroke(0);
background(255);
}
function draw() {
let nextX = x + random(-20, 20);
let nextY = y + random(-20, 20);
nextX = constrain(nextX, width / 2 - 100, width / 2 + 100);
nextY = constrain(nextY, height / 2 - 100, height / 2 + 100);
line(x, y, nextX, nextY);
x = nextX;
y = nextY;
}
function mousePressed() {
if (gogo) {
noLoop();
} else {
loop();
}
gogo = !gogo;
}
function keyPressed() {
if (keyCode === ENTER) {
pdf.save();
}
}