NumberdCtzn
YaBB Newbies
Offline
Posts: 1
Making Particle System react to Sound
Jun 2nd , 2007, 1:10am
Just trying to do something that should be rather simple but I'm having a hell of a time getting it to function. I have 7 days before it needs to be displayed. I am trying to have smoke be pushed around by sound. Basically, have the input for the Particle System change from the mouse to the microphone. I have the sets of code that I want to blend. I know this is vague but anything will help. SET ONE:::: The Particle system import traer.physics.*; //import processing.pdf.*; //import pitaru.sonia_v2_9.*; Particle mouse, b, c; Particle[] others; ParticleSystem physics; PImage img; void setup() { size( 500, 500 ); frameRate( 24 ); cursor( CROSS ); // sprite mask thing stolen from dan shiffman PImage msk = loadImage("texture.gif"); img = new PImage( msk.width, msk.height ); for ( int i = 0; i < img.pixels.length; i++ ) img.pixels[i] = color(255); img.mask(msk); imageMode(CORNER); tint( 0, 225 ); physics = new ParticleSystem( 0, 0.1 ); mouse = physics.makeParticle(); mouse.makeFixed(); others = new Particle[1500]; for ( int i = 0; i < others.length; i++ ) { others[i] = physics.makeParticle( 1.0, random( 0, width ), random( 0, height ), 0 ); physics.makeAttraction( mouse, others[i], 4000, 50 ); } } void draw() { mouse.moveTo( mouseX, mouseY, 0 ); physics.tick(); background( 245 ); for ( int i = 0; i < others.length; i++ ) { Particle p = others[i]; image(img,p.position().x()-img.width/2,p.position().y()-img.height/2); } } SET TWO:::::: The Sound System import processing.pdf.*; import pitaru.sonia_v2_9.*; int xpos = 5; float a = 0.0; float inc = PI/0.3; float[]spectrum; float x,y,px,py; void setup(){ size(1000,800); spectrum = new float[1024]; Sonia.start(this); LiveInput.start(1024); ellipseMode(CENTER); colorMode(RGB, 256); smooth(); background(255); } void draw(){ getSpectrum(); } void getSpectrum(){ noStroke(); spectrum = LiveInput.getSpectrum(); float v = LiveInput.getLevel() * 10; for ( int i = 0; i < spectrum.length/4; i++){ float r = (400.0/1000.0) * spectrum[i]; float r1 = (400.0/1000.0) * spectrum[i+1]; fill(i*5, xpos, 0,150); float w = (10.0/400.0) * r; ellipse((width/2)+sin(a)*xpos,(height/2)+cos(a)*xpos,w,w); inc = PI/r1; a += inc; xpos += r/100.0; } a = 0.0; xpos = 1; } void mousePressed(){ background(255); } void keyPressed(){ exit(); } public void stop(){ Sonia.stop(); super.stop(); }