For my second P5 sketch, I utilized the mouseIsPressed and keyIsPressed functions to make my artwork interactive. Below are the images that I created along with the code.



function setup() {
createCanvas(1280, 720);
}
function draw() {
background(120,240,80);
if(mouseIsPressed){
strokeWeight(0);
} else{
strokeWeight(4);
}
stroke(0);
for (let y=0; y<=height; y+=40)
{for (let x=0; x<=width; x+=40)
{
fill(250,160,240);
ellipse(x,y,40,40);
}}
strokeWeight(55);
if (keyIsPressed) {
stroke(120,240,80);
} else{
stroke(0);
}
line(0,400,width,0);
line(0,0,400,height);
}
コメント