Drawing fireworks

Here’s my link.

And here’s my sketch: 

This is a picture of fireworks at night. Since fireworks are colorful and shining, I made the brush color change randomly all the time within a certain range (series of blue, green, yellow and pink). Also the stroke weight is always changing which I try to use to express that fireworks are flashing. (I really miss these fireworks during the Spring Festival:( )

I think it is the most important code snippet below, because I use this part to draw and change colors.

if (mouseIsPressed) {
if (key == "g") {
r = 0;
g = 255;
b = random(0, 255);
strokeWeight(random(5, 10));
stroke(r, g, b);
line(pmouseX, pmouseY, mouseX, mouseY);
}
if (key == "y") {
r = 255;
g = 255;
b = random(0, 255);
strokeWeight(random(5, 10));
stroke(r, g, b);
line(pmouseX, pmouseY, mouseX, mouseY);
}
if (key == "p") {
r = 255;
g = random(0, 255);
b = 255;
strokeWeight(random(5, 10));
stroke(r, g, b);
line(pmouseX, pmouseY, mouseX, mouseY);
}
if (key == "b") {
r = 0;
g = random(0, 255);
b = 255;
strokeWeight(random(5, 10));
stroke(r, g, b);
line(pmouseX, pmouseY, mouseX, mouseY);
}

When I was coding, comparing with variables including “mouseX” and “mouseY”, I was more trapped into those “if” statements. As a beginner, it’s hard for me to use “if” properly. Often too many or too few instructions are included in an IF statement that it can not work in the right way. But this kind of problems can not be found by p5.js itself because the logic is right.

 

Leave a Reply

Your email address will not be published. Required fields are marked *