Guest User

Untitled

a guest
Dec 11th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. //Create the ArrayList of Waves
  2. ArrayList<Wave> waves = new ArrayList<Wave>();
  3.  
  4. void setup() {
  5. size(800, 800);
  6.  
  7. //Set all ellipses to draw from the Center
  8. ellipseMode(CENTER);
  9. noFill();
  10. strokeWeight(2);
  11. }
  12.  
  13. void draw() {
  14. //Clear the background with 21 opacity
  15. background(0, 0);
  16.  
  17. if(frameCount%100 == 0){
  18. //Create a new Wave
  19. Wave w = new Wave();
  20. //and Add it to the ArrayList
  21. waves.add(w);
  22. }
  23.  
  24. //Run through all the waves
  25. for(int i = 0; i < waves.size(); i ++) {
  26. //Run the Wave methods
  27. waves.get(i).update();
  28. waves.get(i).display();
  29.  
  30. //Check to see if the current wave has gone all the way out
  31. if(waves.get(i).dead()) {
  32. //If so, delete it
  33. waves.remove(i);
  34. }
  35. }
  36. }
  37.  
  38. //The Wave Class
  39. class Wave {
  40. //Location
  41. PVector loc;
  42. //In case you are not familiar with PVectors, you can
  43. //think of it as a point; it holds an x and a y position
  44.  
  45. //The distance from the wave origin
  46. int farOut;
  47.  
  48. //Color
  49. color strokeColor;
  50. int strokeOpacity;
  51.  
  52. Wave() {
  53. //Initialize the Location PVector
  54. loc = new PVector();
  55.  
  56. //Set location to the Mouse Position
  57. loc.x = width/2;
  58. loc.y = height/2;
  59.  
  60. //Set the distance out to 1
  61. farOut = 1;
  62. strokeOpacity = 255;
  63.  
  64.  
  65. //Randomize the Stroke Color
  66. strokeColor = color(255, strokeOpacity);
  67. }
  68.  
  69. void update() {
  70. //Increase the distance out
  71. farOut += 1;
  72.  
  73. if (farOut > 500){
  74. strokeOpacity--;
  75. }
  76.  
  77. }
  78.  
  79. void display() {
  80. //Set the Stroke Color
  81. stroke(255, strokeOpacity);
  82.  
  83. //Draw the ellipse
  84. ellipse(loc.x, loc.y, farOut, farOut);
  85. }
  86.  
  87. boolean dead() {
  88. //Check to see if this is all the way out
  89. if(farOut > 1500) {
  90. //If so, return true
  91. return true;
  92. }
  93. //If not, return false
  94. return false;
  95. }
  96. }
Add Comment
Please, Sign In to add comment