Create a random set of points.
import ddf.minim.*; Minim minim; AudioInput sound; ArrayList <PVector> pts = new ArrayList<PVector>(); void setup(){ size(900,900); minim = new Minim(this); sound = minim.getLineIn(Minim.STEREO, 1024); for(int i = 0; i < sound.mix.size(); i++){ float xp = random(100,width-100); float yp = random(100,height-100); pts.add(new PVector(xp,yp,0)); } } void draw(){ background(0); stroke(255); strokeWeight(2); for(int i = 0; i < sound.mix.size(); i++){ PVector p1 = pts.get(i); point(p1.x,p1.y); } }
import ddf.minim.*; Minim minim; AudioInput sound; ArrayList <PVector> pts = new ArrayList<PVector>(); ArrayList <PVector> speed = new ArrayList<PVector>(); float amplitude; float distance; ///camera varibles int oldx = mouseX; int oldy = mouseY; float rotx = 0; float roty = 0; float zcam = 0; void setup(){ size(900,900); minim = new Minim(this); sound = minim.getLineIn(Minim.STEREO, 1024); ///declare a slider with a range of 0 - 1200 for(int i = 0; i < sound.mix.size(); i++){ float xp = random(50,width-50); float yp = random(50,height-50); pts.add(new PVector(xp,yp,0)); float xs = random(-1,1); float ys = random(-1,1); speed.add(new PVector(xs,ys,0)); } } void draw(){ background(0); stroke(255); strokeWeight(2); for(int i = 0; i < sound.mix.size(); i++){ PVector p1 = pts.get(i); PVector s1 = speed.get(i); point(p1.x,p1.y); float newx = p1.x + s1.x; float newy = p1.y + s1.y; if(newx < 0 || newx > width){ s1.x = s1.x * -1; } if(newy < 0 || newy > height){ s1.y = s1.y * -1; } PVector p2 = new PVector(newx,newy); pts.set(i,p2); speed.set(i,s1); } }
import ddf.minim.*; import controlP5.*; ControlP5 cp5; Minim minim; AudioInput sound; ArrayList <PVector> pts = new ArrayList<PVector>(); ArrayList <PVector> speed = new ArrayList<PVector>(); float distance; ///camera varibles int oldx = mouseX; int oldy = mouseY; float rotx = 0; float roty = 0; float zcam = 0; void setup(){ size(900,900); minim = new Minim(this); sound = minim.getLineIn(Minim.STEREO, 1024); cp5 = new ControlP5(this); cp5.addSlider("distance") .setPosition(40,80) .setRange(0,100) .setSize(200,20) .setValue(50) .setColorForeground(color(20,200,200)) .setColorLabel(color(255)) .setColorBackground(color(70,70,70)) .setColorValue(color(0,0,0)) .setColorActive(color(0,255,255)) ; for(int i = 0; i < sound.mix.size(); i++){ float xp = random(50,width-50); float yp = random(50,height-50); pts.add(new PVector(xp,yp,0)); float xs = random(-1,1); float ys = random(-1,1); speed.add(new PVector(xs,ys,0)); } } void draw(){ background(0); stroke(255); strokeWeight(2); for(int i = 0; i < sound.mix.size(); i++){ PVector p1 = pts.get(i); PVector s1 = speed.get(i); point(p1.x,p1.y); float newx = p1.x + s1.x; float newy = p1.y + s1.y; if(newx < 0 || newx > width){ s1.x = s1.x * -1; } if(newy < 0 || newy > height){ s1.y = s1.y * -1; } float sound_sample = abs(sound.mix.get(i))+1; s1.x = s1.x*sound_sample; s1.y = s1.y*sound_sample; PVector p2 = new PVector(newx,newy); s1.x = s1.x *.99; s1.y = s1.y * .99; pts.set(i,p2); speed.set(i,s1); } strokeWeight(1); for(int i = 0; i < pts.size(); i++){ for(int j = 0; j < pts.size(); j++){ PVector p1 = pts.get(i); PVector p2 = pts.get(j); if(p1.dist(p2) < distance){ line(p1.x,p1.y,p2.x,p2.y); } } } }
import ddf.minim.*; import controlP5.*; ControlP5 cp5; Minim minim; AudioInput sound; ArrayList <PVector> pts = new ArrayList<PVector>(); ArrayList <PVector> speed = new ArrayList<PVector>(); float amplitude; float distance; ///camera varibles int oldx = mouseX; int oldy = mouseY; float rotx = 0; float roty = 0; float zcam = 0; void setup(){ size(900,900,P3D); minim = new Minim(this); sound = minim.getLineIn(Minim.STEREO, 1024); cp5 = new ControlP5(this); ///declare a slider with a range of 0 - 1200 cp5.addSlider("amplitude") .setPosition(40,40) .setRange(0,10) .setSize(200,20) .setValue(5) .setColorForeground(color(20,200,200)) .setColorLabel(color(255)) .setColorBackground(color(70,70,70)) .setColorValue(color(0,0,0)) .setColorActive(color(0,255,255)) ; cp5.addSlider("distance") .setPosition(40,80) .setRange(0,100) .setSize(200,20) .setValue(50) .setColorForeground(color(20,200,200)) .setColorLabel(color(255)) .setColorBackground(color(70,70,70)) .setColorValue(color(0,0,0)) .setColorActive(color(0,255,255)) ; for(int i = 0; i < sound.mix.size(); i++){ float xp = random(-450,450); float yp = random(-450,450); float zp = random(-450,450); pts.add(new PVector(xp,yp,zp)); float xs = random(-1,1); float ys = random(-1,1); float zs = random(-1,1); speed.add(new PVector(xs,ys,zs)); } } void draw(){ background(0); pushMatrix(); cam(); stroke(255); strokeWeight(2); for(int i = 0; i < sound.mix.size(); i++){ PVector p1 = pts.get(i); PVector s1 = speed.get(i); point(p1.x,p1.y,p1.z); float sound_sample = abs(sound.mix.get(i)) * amplitude; float newx = p1.x + s1.x; float newy = p1.y + s1.y; float newz = p1.z + s1.z; float nsx = s1.x + random(-sound_sample, sound_sample); float nsy = s1.y + random(-sound_sample, sound_sample); float nsz = s1.z + random(-sound_sample, sound_sample); PVector p2 = new PVector(newx,newy,newz); pts.set(i,p2); PVector s2 = new PVector(nsx,nsy,nsz); speed.set(i,s2); } strokeWeight(1); for(int i = 0; i < pts.size(); i++){ for(int j = 0; j < pts.size(); j++){ PVector p1 = pts.get(i); PVector p2 = pts.get(j); if(p1.dist(p2) < distance){ line(p1.x,p1.y,p1.z,p2.x,p2.y,p2.z); } } } popMatrix(); } void cam() { int newx = mouseX; int newy = mouseY; translate(width/2, height/2,zcam); rotateY(rotx); rotateX(roty); //rotateZ(PI); if ((mousePressed == true) && mouseY > 200) { rotx = rotx + (oldx-newx)/50.0; roty = roty + (oldy-newy)/50.0; } oldx = newx; oldy = newy; } void mouseWheel(MouseEvent event) { float e = event.getCount(); zcam = zcam - e*5; }