Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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;
- }
- }
Add Comment
Please, Sign In to add comment