Skip to content

Instantly share code, notes, and snippets.

@wonderburg7
Last active December 11, 2018 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wonderburg7/2cf5fe511b647f578fdce5ff4dd07ec5 to your computer and use it in GitHub Desktop.
Save wonderburg7/2cf5fe511b647f578fdce5ff4dd07ec5 to your computer and use it in GitHub Desktop.
//Create the ArrayList of Waves
ArrayList<Wave> waves = new ArrayList<Wave>();
void setup() {
size(800, 800);
//Set all ellipses to draw from the Center
ellipseMode(CENTER);
noFill();
strokeWeight(2);
}
void draw() {
//Clear the background with 21 opacity
background(0, 0);
if(frameCount%100 == 0){
//Create a new Wave
Wave w = new Wave();
//and Add it to the ArrayList
waves.add(w);
}
//Run through all the waves
for(int i = 0; i < waves.size(); i ++) {
//Run the Wave methods
waves.get(i).update();
waves.get(i).display();
//Check to see if the current wave has gone all the way out
if(waves.get(i).dead()) {
//If so, delete it
waves.remove(i);
}
}
}
//The Wave Class
class Wave {
//Location
PVector loc;
//In case you are not familiar with PVectors, you can
//think of it as a point; it holds an x and a y position
//The distance from the wave origin
int farOut;
//Color
color strokeColor;
int strokeOpacity;
Wave() {
//Initialize the Location PVector
loc = new PVector();
//Set location to the Mouse Position
loc.x = width/2;
loc.y = height/2;
//Set the distance out to 1
farOut = 1;
strokeOpacity = 255;
//Randomize the Stroke Color
strokeColor = color(255, strokeOpacity);
}
void update() {
//Increase the distance out
farOut += 1;
if (farOut > 500){
strokeOpacity--;
}
}
void display() {
//Set the Stroke Color
stroke(255, strokeOpacity);
//Draw the ellipse
ellipse(loc.x, loc.y, farOut, farOut);
}
boolean dead() {
//Check to see if this is all the way out
if(farOut > 1500) {
//If so, return true
return true;
}
//If not, return false
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment