Ellipses not expanding?

Viewed 29

I'm working on a Processing project for an art class and my plan was to make an audio visualizer where circles would appear from the amplitudes from the audio file. My main problem is that I'm trying to achieve a ripple effect where the circles would expand and ripple outward beyond the window after generating, but all of my circles stay put. Here's my draw function:

void draw(){
  int n = 1000;
  fft.forward(song.mix);
  
  for (int i = 0; i <fft.specSize(); i++ ) {
    
    z = fft.getBand(i) * 20;
    
    if (n < 150){
      stroke(colors [(int)random(0,9)]);
      strokeWeight(random(50, 300)); //bigger strokes towards the middle
      ellipse(x, y, z, z); //basic lines and shapes
      z ++;
    }
    
    else{
      stroke(colors [(int)random(0,9)]);
      strokeWeight(random(10));
      
      ellipse(x, y, z, z); //basic lines and shapes
      z ++;
    } 
    
  }

}

I'm not sure where I'm going wrong since I am incrementing z, so as far as I know each ellipses should expand.

1 Answers

You're not seeing any expansion, since you're only incrementing z within a single draw call and then it is reset. But in order to see the expansion, z must be incremented over multiple draw cycles. You can do this by using an if statement instead of a loop. Note that draw is continually called.

int i = -1;

void draw(){
  int n = 1000;
  fft.forward(song.mix);
  
  if(++i < fft.specSize()) {
    
    z = fft.getBand(i) * 20;
    
    if (n < 150){
      stroke(colors [(int)random(0,9)]);
      strokeWeight(random(50, 300)); //bigger strokes towards the middle
      ellipse(x, y, z, z); //basic lines and shapes
      z ++;
    }else{
      stroke(colors [(int)random(0,9)]);
      strokeWeight(random(10));
      
      ellipse(x, y, z, z); //basic lines and shapes
      z ++;
    } 
  }
}

I haven't tested it, but this should redraw the ellipses as they expand.

P.S. If the height and width of your ellipse are equal, you can use circle(x, y, z).

Related