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 & HelpSyntax Questions › why the outer circle does not fade away
Page Index Toggle Pages: 1
why the outer circle does not fade away? (Read 5335 times)
why the outer circle does not fade away?
Jun 18th, 2010, 12:37pm
 
I'm just testing minim library, I want to create cirles that are fading away eventually. I get the main circle work(which radius is 2*radius), and I don't know why the outer ring doesn't work.

P.S.: you need to change the add your own mp3 to the data folder.

Code:
import processing.video.*;
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.*;


Minim minim;
AudioPlayer song;
//WaveformRenderer waveform;
FFT fft;
ArrayList trails;
MovieMaker mm;
boolean play = false;

void setup()
{
size(1024, 800);
background(0);
smooth();
//frameRate(128);
//mm = new MovieMaker(this, width,height,"bubbles.mov",30,MovieMaker.VIDEO, MovieMaker.LOSSLESS);
// always start Minim first!
minim = new Minim(this);

// specify 1024 for the length of the sample buffers
// the default buffer size is 1024
song = minim.loadFile("糖不厌.mp3", 1024);
play();

//waveform = new WaveformRenderer();
//song.addListener(waveform);

// an FFT needs to know how
// long the audio buffers it will be analyzing are
// and also needs to know
// the sample rate of the audio it is analyzing
fft = new FFT(song.bufferSize(), song.sampleRate());

trails = new ArrayList();

}

void play(){
if(play == true) song.play();
}

void draw()
{

//waveform.draw();
//spectrum
// first perform a forward fft on one of song's buffers
// I'm using the mix buffer
// but you can use any one you like
fft.forward(song.mix);

//stroke(255, 0, 0, 128);
//strokeWeight(5);
// draw the spectrum as a series of vertical lines
// I multiple the value of getBand by 4
// so that we can see the lines better
for(int i = 0; i < (fft.specSize()-1)*2; i+=1024/(fft.specSize()-1))
{
//line(i, height, i, height - fft.getBand(i)*5);

if(dist(i,height, i, height - fft.getBand(i)*5)>height/20){
Circle c = new Circle(int(random(0,width)), int(random(0,height)), random(10,50), 255);
c.drawOneCircle();
}
}

//trails
for(int j = 0; j < trails.size(); j++){
Trail t = (Trail) trails.get(j);
t.update();
t.drawOneCircle();
}


//waveform
stroke(255);
strokeWeight(0);
// we draw the waveform by connecting neighbor values with a line
// we multiply each of the values by 50
// because the values in the buffers are normalized
// this means that they have values between -1 and 1.
// If we don't scale them up our waveform
// will look more or less like a straight line.
for(int i = 0; i < song.bufferSize() - 1; i++)
{
// line(i, height/2 - 50 + song.left.get(i)*50, i+1, height/2 - 50 + song.left.get(i+1)*50);
// line(i, height/2 + 50 + song.right.get(i)*50, i+1, height/2 + 50 + song.right.get(i+1)*50);
// line(i, height/2 + song.mix.get(i)*50, i +1, height/2 + song.mix.get(i+1)*50);
}

//mm.addFrame();


}

void stop()
{
song.close();
minim.stop();

super.stop();
}

void keyPressed(){
if(key == 'f'){
mm.finish();
println("movie saved");
}

if ( key == 'p' ) {
play = true;
play();
}
}

class Circle{
//variable
int posx;
int posy;
float radius;
float magnatude;

//constructor
Circle(int _posx, int _posy, float _radius, float _magnatude){
posx = _posx;
posy = _posy;
radius = _radius;
magnatude = _magnatude;
}

//method
void drawOneCircle(){

noStroke();
fill(magnatude,10);
ellipse(posx,posy,radius*4,radius*4);
//fill(magnatude,magnatude,magnatude,10);
ellipse(posx,posy,radius*3,radius*3);
//fill(magnatude,magnatude,magnatude,10);
ellipse(posx,posy,radius*2.5,radius*2.5);

//stroke(0,60);
fill(magnatude);
ellipse(posx,posy,radius*2,radius*2);


//color
//noStroke();
// for(int k = 1; k < 30; k++){
// fill(random(0,magnatude),random(0,magnatude),random(0,magnatude),20);
// arc(posx, posy, radius*2, radius*2, random(0,2*PI), random(0,2*PI));
// }


// for(float i = 0.0; i < 2.0*PI; i+=0.5-radius/200){
// stroke(0,random(0,100));
// line(posx,posy,posx+sin(i)*radius,posy+cos(i)*radius);
// }

trails.add(new Trail(posx, posy, radius, magnatude));

}


}

class Trail{
//variable
int posx;
int posy;
float radius;
float magnatude;

//constructor
Trail(int _posx, int _posy, float _radius, float _magnatude){
posx = _posx;
posy = _posy;
radius = _radius;
magnatude = _magnatude;
}

//method
void update(){
magnatude-=30;

if(magnatude < 0){
trails.remove(this);
//println("circle remove");
}
}

void drawOneCircle(){

noStroke();
fill(magnatude,10);
ellipse(posx,posy,radius*4,radius*4);
//fill(magnatude,magnatude,magnatude,10);
ellipse(posx,posy,radius*3,radius*3);
//fill(magnatude,magnatude,magnatude,10);
ellipse(posx,posy,radius*2.5,radius*2.5);

//stroke(0,60);
fill(magnatude);
ellipse(posx,posy,radius*2,radius*2);


//color
// noStroke();
// for(int k = 1; k < 30; k++){
// fill(random(0,magnatude),random(0,magnatude),random(0,magnatude),20);
// arc(posx, posy, radius*2, radius*2, random(0,2*PI), random(0,2*PI));
// }


// for(float i = 0.0; i < 2.0*PI; i+=0.5-radius/200){
// stroke(0,random(0,100));
// line(posx,posy,posx+sin(i)*radius,posy+cos(i)*radius);
// }

}


}

































Page Index Toggle Pages: 1