We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › help with background redraw
Page Index Toggle Pages: 1
help with background redraw (Read 323 times)
help with background redraw
Aug 14th, 2008, 1:37am
 
Hi.  I've got snowflakes running down the window and a minim fft gerenated snow bank forming at the bottom of the window.  While the background behind the snowflakes needs to be constantly redrawn, I would like an "imprint" of every fft generated ellipse drawn at the bottom of the screen as to create a larger and larger snowbank as the music crescendos... any tips?

Here is my code (note, you'll need an mp3 called winter.mp3 to run):

//START from minit library FFT example (http://code.compartmental.net/tools/minim/)
import ddf.minim.analysis.*;
import ddf.minim.*;

AudioPlayer jingle;
FFT fft;
//END from minit library FFT example (http://code.compartmental.net/tools/minim/)

//float diameter = 50;
//float a = width/2+200;
//float b = height/2;
int c;
int numFlakes = 7;
float z;
float zz;
float zzz;
float zzzz;
float zzzzz;

//snowFlake testSnow;

snowFlake[]flakes = new snowFlake[numFlakes];

void setup()
 {
//START from minit library FFT example (http://code.compartmental.net/tools/minim/)
 Minim.start(this);
 jingle = Minim.loadFile("winter.mp3");
 jingle.loop();
 fft = new FFT(jingle.bufferSize(), jingle.sampleRate());
 fft.logAverages(22, 3);
 rectMode(CORNERS);
//END from minit library FFT example (http://code.compartmental.net/tools/minim/)
 c=round(random(5,30));
 size(1024, 400);
 //background(20);
smooth();
 frameRate(20);
 //testSnow = new snowFlake(width/2, 0, .02, c);
 for (int i = 0; i < numFlakes; i++)
   {
   flakes[i] = new snowFlake(random(width),random(-500,0), random(.01,.05), round(random(3,30)));
   
   }
 }

void draw()
 {
background(20);
fill(20);
//quad(0,0,width,0,width,height,0,height);

//START from minit library FFT example (http://code.compartmental.net/tools/minim/)
fft.forward(jingle.mix);
 int w = int(width/fft.avgSize());
 for(int i = 0; i < fft.avgSize(); i++)
 {
ellipse(i*w-100, height+200, i*w + w, height - (fft.getAvg(i)*15)/-2);
     fill(random(210,255));
//END from minit library FFT example
     
/*z=(i*w-100);
zz=(height+200);
zzz=(i*w + w);
zzzz=height - (fft.getAvg(i)*15)/-2;
zzzzz=(random(210,255));

float[] zzzzzz = { z,zz,zzz,zzzz,zzzzz };

println(zzzzzz);
*/
   
 }
//  testSnow.draw();
 for (int i = 0; i < numFlakes; i++)
    {
   flakes[i].draw();
    }
 }

//"class" help from Ingrid Wu (section E bootcamp)
class snowFlake
 {
 float x, y, speed;
 int units;
 
 snowFlake(float _x, float _y, float s, int _size)
   {
   x = _x;
   y = _y;
   units = _size;
   speed = s;
   }

 void draw()
   {
         
     y++;
 

if (y > 460){y = -100.0;}

   pushMatrix();
   
   translate(x, y);

//    pushMatrix();
   
     for(int j = 0; j < 8; j++)
     {

     rotate(PI/4);
     
         pushMatrix();
//8 points radial "for loop" referenced from Alba G. Corral's "payaso" at http://openprocessing.org/visuals/?visualID=274
             for (int i = units; i > 1; i--)
             {
             strokeWeight(i/2);
             stroke(225);
             line(0, 0, 0, -5);
             strokeWeight(1);
             line(0,10,30,40);
             line(0,10,-30,40);
             translate(0, -4);  

                 y += speed;
       if (y > width) {y = 0;}
             }
             
         popMatrix();
         
         
     }
//   popMatrix();  
   

   popMatrix();
   
   
 }
 

}

//START from minit library FFT example (http://code.compartmental.net/tools/minim/)
void stop()
{

 jingle.close();
 super.stop();
}
//END from minit library FFT example
Page Index Toggle Pages: 1