let drawing = [];
let city;
function preload() {
city = loadImage("city.jpg");
}
function setup() {
createCanvas(city.width, city.height);
}
function mouseDragged() {
drawing.push({
mouseX: mouseX,
mouseY: mouseY,
});
}
function draw() {
colorMode(HSB);
// clear previous frame
background(city);
if (mouseIsPressed) {
// set line color to a range from light yellow to dark red
// using HSB color mode with hue from 40 to 0 and saturation and brightness at 100
stroke(random(0, 40), 100, 100);
// draw line from top right corner to mouse y-5 and y+5
line(width - 1, 0, mouseX, mouseY - 5);
line(width - 1, 0, mouseX, mouseY + 5);
line(width - 1, 0, mouseX + random(-5, 5), mouseY + random(-5, 5));
// set fill color to random
fill(random(0, 40), 100, 100);
// generate a random position within a radius of 10 of the mouse position
let x = mouseX + random(-20, 20);
let y = mouseY + random(-20, 20);
// draw a circle of radius 1 at the random position
circle(x, y, 2);
}
}
https://editor.p5js.org/106p01013/sketches/dgE9njGLj
我想用鼠标控制哥斯拉的热光束,烧毁城市作画。 然而,每次我尝试做一个油漆标记时,光束线的效果都留在画布上。
如何用喷笔效果作画而不让光束线留下痕迹?