xxxxxxxxxx
39
function setup() {
createCanvas(800, 800);
background(255);
}
function draw() {
// Set stroke weight based on mouse position
let weight = map(mouseY, 0, height, 1, 10);
strokeWeight(weight);
// Set stroke color based on mouse position
let r = random(1,255);
let g = random(1,255);
let b = random(1,255);
stroke(r, g, b);
// Draw lines when mouse is pressed
if (mouseIsPressed) {
let numLines = int(random(5, 20)); // Random number of lines to draw
let lineLength = random(5, 30); // Random length of each line
for (let i = 0; i < numLines; i++) {
let startX = mouseX + random(-10, 10); // Randomize start position within range
let startY = mouseY + random(-10, 10); // Randomize start position within range
let endX = startX + random(-lineLength, lineLength); // Randomize end position within range
let endY = startY + random(-lineLength, lineLength); // Randomize end position within range
line(startX, startY, endX, endY);
}
}
}
// Function to clear the screen when 'c' key is pressed
function keyPressed() {
if (key === 'c' || key === 'C') {
background(255);
}
}