/** 2007 (c) LAFKON This script is licensed under the GNU General Public License */ import traer.physics.*; import java.util.Vector; import processing.pdf.*; import processing.candy.*; import processing.xml.*; import ddf.minim.*; import ddf.minim.signals.*; float framerate; String yes = "yes"; Vector marticl; ParticleSystem physics; Particle mouse; Spring s; int greyer; boolean drawing; boolean nothingDrawn; boolean saveOneFrame = false; int number,count; int numexport = 110; int pdfnumber = 100; AudioOutput out; SquareWave sqa; ///////////////// void setup() { size( 595,841 ); //smooth(); stroke( 0 ); background( 255 ); physics = new ParticleSystem( 0.0f, 0.05f ); mouse = physics.makeParticle(); mouse.makeFixed(); marticl = new Vector(); drawing = false; Minim.start(this); // get a line out from Minim, default sample rate is 44100, bit depth is 16 //out = Minim.getLineOut(Minim.STEREO, 512); // create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate 44100 to match the line out sqa = new SquareWave(440, 0.2, 44100); // set the portamento speed on the oscillator to 200 milliseconds sqa.portamento(200); // add the oscillator to the line out //out.addSignal(sqa); initiate(); reConfigure(); } //////////// void draw(){ reConfigure(); count++; if(pdfnumber > numexport) { pdfnumber = 100; } frameRate(framerate); float f = frameCount/(2*sqrt(frameCount)); int i = int(f); if((saveOneFrame == true) && (i == f)) { println("recorded PDF in frame " + frameCount); beginRecord(PDF, "data/output/Mnmrtcl-" + pdfnumber + ".pdf"); pdfnumber++; } physics.advanceTime( 1.0f ); mouse.setMass( 10 ); // Midi hier physics.setGravity (-0.1); // Midi hier background( 255 ); translate(50,400); scale(0.9); drawStroke(); if((saveOneFrame == true) && (i == f)) { endRecord(); } } void drawStroke() { stroke(0); noFill(); for ( int i = 0; i < marticl.size()-1; i++ ) { M4rticl t = (M4rticl)marticl.get( i ); drawElastic( t ); } if ( marticl.size()-1 >= 0 ) drawElastic( (M4rticl)marticl.lastElement() ); } void drawElastic( M4rticl t ) { float lastStretch = 1; for ( int i = 0; i < t.particles.size()-1; ++i ) { Vector3D firstPoint = ((Particle)t.particles.get( i )).position(); Vector3D firstAnchor = i < 1 ? firstPoint : ((Particle)t.particles.get( i-1 )).position(); Vector3D secondPoint = i+1 < t.particles.size() ? ((Particle)t.particles.get( i+1 )).position() : firstPoint; Vector3D secondAnchor = i+2 < t.particles.size() ? ((Particle)t.particles.get( i+2 )).position() : secondPoint; Spring s = (Spring)t.springs.get( i ); s.setStrength( 0.5 ); // Midi hier float springStretch = 5.5*s.restLength()/s.currentLength(); Vector3D thick = ((Particle)t.particles.get( i )).position(); strokeWeight( dist(thick.x(),thick.y(),width,height)/100 ); // !!! müsste smoother sein -> sin? lastStretch = springStretch; beginShape(); curveVertex(firstAnchor.x(), firstAnchor.y()); curveVertex(firstPoint.x(), firstPoint.y()); curveVertex(secondPoint.x(), secondPoint.y()); curveVertex(secondAnchor.x(), secondAnchor.y()); endShape(); ///////////////////////////////////////////////////////////////////// float pan = map(100, 0, springStretch*100, -1, 1); sqa.setPan(pan); float freq = map(springStretch*500, 0, firstAnchor.y()*30, 1500, 60); sqa.setFreq(freq); ///////////////////////////////////////////////////////////////////// mouse.moveTo(pan/30+300, pan/30+150, 0 ); } } //////////////////////////////// class M4rticl { public Vector particles; public Vector springs; ParticleSystem physics; public M4rticl( ParticleSystem p, Vector3D firstPoint, Particle followPoint ) { particles = new Vector(); springs = new Vector(); physics = p; Particle firstParticle = p.makeParticle( 1.0f, firstPoint.x(), firstPoint.y(), firstPoint.z() ); particles.add( firstParticle ); physics.makeSpring( followPoint, firstParticle, 0.1f, 0.1f, 5 ); } public void addPoint( Vector3D p ) { Particle thisParticle = physics.makeParticle( 1.0f, p.x(), p.y(), p.z() ); springs.add( physics.makeSpring( ((Particle)particles.lastElement()), thisParticle, 1.0f, 1.0f, ((Particle)particles.lastElement()).position().distanceTo( thisParticle.position() ) ) ); particles.add( thisParticle ); } } ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// void initiate() { setFrameRate(); marticl.add( new M4rticl( physics, new Vector3D( 0, 0, 0 ),mouse ) ); for ( int i = 0; i < 5; i++ ) { ((M4rticl)marticl.lastElement()).addPoint( new Vector3D( i, 0, 0 ) ); ((M4rticl)marticl.lastElement()).addPoint( new Vector3D( i+30 ,0, 0 ) ); ((M4rticl)marticl.lastElement()).addPoint( new Vector3D( i+50 ,0, 0 ) ); } marticl.add( new M4rticl( physics, new Vector3D( 0, 0, 0 ),mouse ) ); for ( int i = 0; i < 6; i++ ) { ((M4rticl)marticl.lastElement()).addPoint( new Vector3D( i ,0, 0 ) ); ((M4rticl)marticl.lastElement()).addPoint( new Vector3D( i+40 ,0, 0 ) ); ((M4rticl)marticl.lastElement()).addPoint( new Vector3D( i+60 ,0, 0 ) ); } } void setFrameRate() { String rate[] = loadStrings("data/framerate.ctrl"); framerate = float(rate[0]); println(framerate); } void savePDF(){ saveOneFrame = true; String cycle[] = loadStrings("data/cycle.ctrl"); int number = int(cycle[0]); number++; String[] up = { str(number) }; saveStrings("data/cycle.ctrl", up); } void reConfigure(){ String loadcon[] = loadStrings("data/reconfigure.ctrl"); for (int i=1; i < loadcon.length; i++) { String reconfigure[] = split(loadcon[i],'='); if((i == 1) && (reconfigure[1].equals(yes) == true)) { println("reload Framerate in frame " + frameCount); setFrameRate(); } if((i == 2) && (reconfigure[1].equals(yes) == true)) { savePDF(); } if((i == 2) && (reconfigure[1].equals(yes) == false) && (saveOneFrame == true)) { println("stopped to record PDFs in frame " + frameCount); saveOneFrame = false; } if((i == 3) && (reconfigure[1].equals(yes) == true)) { numexport = int(reconfigure[2]); } if((i == 4) && (reconfigure[1].equals(yes) == true)) { exit(); } } }