grow objects individually
in
Programming Questions
•
1 years ago
I have a silly problem... i have a Class of ellipses that are given an initial size, then increasing in size each frame...
Problem is I'm overriding the grown size with the initial size every time i create a new object...
Im sure there is a simple answer for this... but you know, it's sunday...
Any thoughts appreciated...
Code below:
- ArrayList rings;
- Ring ring;
- float s, newS;
- float r, g, b;
- float life;
- float rWidth = 1;
- void setup() {
- size(screenWidth/2, screenHeight/2);
- smooth();
- rings = new ArrayList();
- }
- void draw() {
- background(0);
- stroke(r, g, b);
- fill(154, 0);
- //for (int i = rings.size()-1; i >= 0; i--) {
- for (int i = 0; i < rings.size(); i++) {
- Ring ring = (Ring) rings.get(i);
- ring.grow();
- ring.display();
- if (ring.finished()) {
- rings.remove(i);
- }
- }
- } //
- void mousePressed() {
- r=random(127);
- g=random(127);
- b=random(127);
- // reset size
- newS = frameCount;
- // A new ball object is added to the ArrayList (by default to the end)
- rings.add(new Ring(mouseX, mouseY, rWidth, r, g, b));
- }
- class Ring {
- float xpos;
- float ypos;
- float rsize;
- float r,g,b;
- float life = 255;
- Ring(float _xpos, float _ypos, float _rsize, float _r, float _g, float _b) {
- xpos = _xpos;
- ypos = _ypos;
- rsize = _rsize;
- rWidth = rsize;
- r = _r;
- g = _g;
- b = _b;
- }
- void grow() {
- //s = frameCount - newS;
- s = newS - frameCount ;
- rsize = rWidth + s;
- }
- boolean finished() {
- // Balls fade out
- life--;
- if (life < 0) {
- return true;
- } else {
- return false;
- }
- }
- void display(){
- strokeWeight(18);
- stroke(r,g,b,life);
- ellipse(xpos, ypos, rsize, rsize);
- }
- }
1