Thursday, March 6, 2008

PROJECT01 Asta - Jung























import processing.opengl.*;

import ddf.minim.*;
import ddf.minim.analysis.*;

AudioPlayer song;
BeatDetect beat;

float ang;
int limit = 1500;


int ball = 2000;
pelo[] lista ;
float[] z = new float[ball];
float[] phi = new float[ball];
float[] largos = new float[ball];
float radio = 100;
float rx = 0;
float ry =0;

float eRadius;


void setup(){
size(1000, 800, OPENGL);
radio = height/6;

lista = new pelo[ball];
for (int i=0; i*<*ball; i++){
lista[i] = new pelo();
}
noiseDetail(2);


//add your song!
Minim.start(this);
song = Minim.loadFile("DJ Son & Potlatch - Self Portrait.mp3");
song.play();
// a beat detection object song SOUND_ENERGY mode with a sensitivity of 10 milliseconds
beat = new BeatDetect();

ellipseMode(CENTER_RADIUS);
eRadius = 20;
}

void draw()
{
background(255);
translate(width/2,height/2);

float rxp = ((mouseX-(width/2))*0.005);
float ryp = ((mouseY-(height/2))*-0.005);
rx = (rx*0.9)+(rxp*0.15);
ry = (ry*0.9)+(ryp*0.15);
rotateY(rx);
rotateX(ry);
fill(255);
noStroke();
sphere(radio);

for (int i=0;i{ball;i++){
lista[i].dibujar();

beat.detect(song.mix);
float a = map(eRadius, 20, 80, 60, 255);
fill(60, 55, 110, a);
if ( beat.isOnset() ) eRadius = 300;

ellipse(width/2, height/2, eRadius, eRadius);
eRadius *= 0.95;
if ( eRadius < 20 ) eRadius = 20;

}
}


class pelo
{
float z = random(-radio,radio);
float phi = random(TWO_PI);
float largo = random(4,1.2);
float theta = asin(z/radio/3);

void dibujar(){

float off = (noise(millis() * 0.0005,sin(phi))-0.5) * 0.3;
float offb = (noise(millis() * 0.0007,sin(z) * 0.01)-0.5) * 0.3;

float thetaff = theta+off;
float phff = phi+offb;
float x = radio * cos(theta) * cos(phi);
float y = radio * cos(theta) * sin(phi);
float z = radio * sin(theta);
float msx= screenX(x,y,z);
float msy= screenY(x,y,z);

float xo = radio * cos(thetaff) * cos(phff);
float yo = radio * cos(thetaff) * sin(phff);
float zo = radio * sin(thetaff);

float xb = xo * largo;
float yb = yo * largo;
float zb = zo * largo;

beginShape(LINES);
stroke(130,140,10,30);
vertex(x,y,z);
stroke(230,80);
vertex(xb,yb,zb);

endShape();
}
}

void keyPressed(){
if (key=='s'){
saveFrame("project-####.jpg"); //saves the image in documents
}
}


for i *<* ball take out either *<* and replace with just < or { and replace with <; had some trouble posting the script to the blog, blog thought it was HTML!