74 lines
2.3 KiB
Plaintext
74 lines
2.3 KiB
Plaintext
/*
|
|
Idea: Just a Firework "animation"
|
|
- Create an Object that flies upward from the bottom of the screen
|
|
- Make said Object explode after reaching some turning point
|
|
- Maybe make that explosion out of even more Objects that fly outward from their origin
|
|
- Create an Explosion on the current Mouse Position when Mouse is Pressed?
|
|
|
|
### Ignore the filename, it's because I have done this before but it's been years and I don't want to delete the old code. ###
|
|
*/
|
|
|
|
|
|
// Section for constant variables:
|
|
final int AMOUNT_OF_ROCKETS = 20;
|
|
final float ROCKET_DIAMETER = 10f;
|
|
final int MAX_FLARE_LIFETIME = 130;
|
|
final int AMOUNT_OF_PARTICLES = 75;
|
|
final float PARTICLE_DIAMETER = 7.5;
|
|
final float MAX_FLARE_VELOCITY = 2.125;
|
|
final float MAX_ROCKET_VELOCITY = 10.35;
|
|
final float DECELERATION_MAGNITUDE = 0.05;
|
|
|
|
|
|
// Section for global variables:
|
|
ArrayList<Rocket> firework = new ArrayList<Rocket>();
|
|
ArrayList<Rocket> userInputs = new ArrayList<Rocket>();
|
|
|
|
|
|
// Function called when program is started
|
|
void setup() {
|
|
// Initialize full-screen window
|
|
fullScreen();
|
|
|
|
colorMode(HSB);
|
|
textAlign(LEFT, TOP);
|
|
textSize(24);
|
|
|
|
for (int i = 0; i < AMOUNT_OF_ROCKETS; i++) {
|
|
firework.add(new Rocket(firework, new PVector(random(width), height)));
|
|
}
|
|
}
|
|
|
|
// Function called every Frame at <frameRate>
|
|
void draw() {
|
|
// Set black background
|
|
background(0);
|
|
|
|
// Display Framerate, fixed in the top left corner in white
|
|
noStroke();
|
|
fill(255);
|
|
text("FPS: "+round(frameRate), 0, 0);
|
|
|
|
// Loop backwards through all Rockets, update their position, remove if out of bounds, then show them
|
|
for (int i = firework.size()-1; i >= 0; i--) {
|
|
Rocket r = firework.get(i);
|
|
r.showNext();
|
|
}
|
|
for (int i = userInputs.size()-1; i >= 0; i--) {
|
|
Rocket r = userInputs.get(i);
|
|
r.showNext();
|
|
}
|
|
|
|
// If any Rockets got deleted from main Array 'firework', add new random ones
|
|
while (firework.size() < AMOUNT_OF_ROCKETS) {
|
|
firework.add(new Rocket(firework, new PVector(random(width), height)));
|
|
}
|
|
}
|
|
|
|
// Function called when a user presses any mouse button inside of the window
|
|
void mousePressed() {
|
|
// Create Rocket at current mouse position, make it explode instantly and add it to special array
|
|
Rocket r = new Rocket(userInputs, new PVector(mouseX, mouseY));
|
|
r.vel.y = 0;
|
|
userInputs.add(r);
|
|
} |