Interactive Authoring – Visual Music

//modified version of Pixel Flow’s ‘getting started’ code by Thomas Diewald
// http://github.com/diwi/PixelFlow
// Minim is made by Damien Di Fede and Anderson Mills
import com.thomasdiewald.pixelflow.java.DwPixelFlow;
import com.thomasdiewald.pixelflow.java.fluid.DwFluid2D;

import ddf.minim.*;
import ddf.minim.analysis.*;
int innerSize=30;
int XPos = mouseX;
Minim minim;
AudioPlayer song;
FFT fft;
BeatDetect beat;
float eRadius;
float bRadius;
DwFluid2D fluid;
PGraphics2D pg_fluid;
PImage rocks;
public void setup()
{
size(512, 700, P2D);
DwPixelFlow context = new DwPixelFlow(this);
fluid = new DwFluid2D(context, width, height, 1);
fluid.param.dissipation_velocity = 1f;
fluid.param.dissipation_density = .3f;

pg_fluid = (PGraphics2D) createGraphics(width, height, P2D);

minim = new Minim(this);
song = minim.loadFile(“No Time For Caution.mp3”, 512);
song.play();
fft = new FFT(song.bufferSize(), song.sampleRate());
beat = new BeatDetect();
eRadius=20;
rocks=loadImage(“Rocksh.png”);
}

public void draw()
{
background(0);

fft.forward(song.mix);
beat.detect(song.mix);
float a = map(eRadius, 20, 80, 60, 255);
if (beat.isOnset() ) eRadius = 800;
if (beat.isOnset() ) bRadius = 600;
eRadius*=.90;
bRadius*=.90;
if (eRadius<80) eRadius=30;
if (innerSize<30) innerSize=30;
fluid.addCallback_FluiData(new DwFluid2D.FluidData() {
public void update(DwFluid2D fluid) {

float px = 100; //places smoke in Xposition
float py = 100; //subtract because sim Y is flipped
float dx = mouseX-335; //places smoke in Xposition
float dy = height-mouseY;
float vx = random(-300, 300);
float vy = eRadius + random(-50, 50);
float Bvx = random(-300, 300);
float Bvy = eRadius + random(-50, 50)+10;
float Cvx = random(-300, 300);
float Cvy = bRadius + random(-50, 50);
float Dvx = random(-100,100);
float Dvy = random(-100,100);
fluid.addVelocity(px, py, 24, vx, vy);
fluid.addDensity (px, py, 50, 1f, .2f, .3f, 1f, 1); //redsmoke
fluid.addDensity (px, py, innerSize, 1.0f, 1.0f, 0f, 1.0f, 1); //brightsmoke

fluid.addVelocity(px+205, py, 30, Bvx, Bvy);
fluid.addDensity (px+205, py, 60, 1f, .2f, .3f, 1f, 1); //redsmoke 2
fluid.addDensity (px+205, py, innerSize, 1.0f, 1.0f, 0f, 1.0f, 1); //brightsmoke 2

fluid.addVelocity(px+335, py, 30, Cvx, Cvy);
fluid.addDensity (px+335, py, 60, 1f, .2f, .3f, 1f, 1); //redsmoke 3
fluid.addDensity (px+335, py, innerSize, 1.0f, 1.0f, 0f, 1.0f, 1); //brightsmoke 3

fluid.addVelocity(dx+335, dy, 20, Dvx, Dvy);
fluid.addDensity (dx+335, dy, 20, 1f, .2f, .3f, 1f, 1); //handsmokered
fluid.addDensity (dx+335, dy, 5, 1.0f, 1.0f, 0f, 1f, 1); //handSmokeyellow
}
}
);

fluid.update();

// clear render target
pg_fluid.beginDraw();
pg_fluid.background(0);
pg_fluid.endDraw();

// render fluid stuff
fluid.renderFluidTextures(pg_fluid, 0);

// display
image(pg_fluid, 0, 0);

image(rocks, -100, -550);
}

Advertisements
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s