Hi, I'm struggling on where to put the script to make my processing animation save as a DXF file as well as stop it at a particular place. Would anyone have any ideas?
This is my script so far:
import processing.dxf.*;
import ddf.minim.analysis.*;
import ddf.minim.*;
FFT fftLin;
FFT fftLog;
Waveform myRects;
Minim minim;
AudioPlayer groove;
boolean record;
PFont font;
float camzoom;
float maxX = 0;float maxY = 0;float maxZ = 0;
float minX = 0;float minY = 0;float minZ = 0;
void setup(){
size(1000,500,P3D);
noStroke();
minim = new Minim(this);
groove = minim.loadFile("01.mp3");
//repeat the song
groove.loop();
background(255);
font = loadFont("Eureka-90.vlw");
fftLog = new FFT(groove.bufferSize(),groove.sampleRate());
fftLog.logAverages(22,4); //adjust numbers to adjust spacing
float w = float (width/fftLog.avgSize());
float x = w;
float y = 0;
float z = 50;
float radius = 10;
myRects = new Waveform(x,y,z,radius);
}
void draw(){
if (record) {
// Note that #### will be replaced with the frame number. Fancy!
beginRecord(PDF, "frame-0001.pdf");
}
background(0);
directionalLight(126,126,126,sin(radians(frameCount)),cos(radians(frameCount)),1);
ambientLight(102,102,102);
if (frameCount>130){
for(int i = 0; i < fftLog.avgSize(); i++){
float zoom = 1;
float jitter = (fftLog.getAvg(i)*2);
//println(jitter);
PVector foc = new PVector(myRects.x+jitter, myRects.y+jitter, 0);
PVector cam = new PVector(zoom, zoom, -zoom);
camera(foc.x+cam.x+50,foc.y+cam.y+50,foc.z+cam.z,foc.x,foc.y,foc.z,0,0,1);
}
}
//play the song
fftLog.forward(groove.mix);
myRects.update();
//myRects.textdraw();
myRects.plotTrace();
if(record){
endRaw();
record = false;
println("Done DXF~!");
}
}
void stop() {
// always close Minim audio classes when you finish with them
groove.close();
// always stop Minim before exiting
minim.stop();
super.stop();
}
class Waveform{
float x,y,z;
float radius;
PVector[] pts = new PVector[fftLog.avgSize()];
PVector[] trace = new PVector[0];
Waveform(float incomingX, float incomingY, float incomingZ, float incomingRadius){
x = incomingX;
y = incomingY;
z = incomingZ;
radius = incomingRadius;
}
void update(){
plot();
}
void plot(){
for(int i = 0; i < fftLog.avgSize(); i++){
int w = int(width/fftLog.avgSize());
x = i*w;
y = frameCount*5;
z = height/3-fftLog.getAvg(i)*03;
stroke(0);
point(x, y, z);
pts = new PVector(x, y, z);
//increase size of array trace by length+1
trace = (PVector[]) expand(trace, trace.length+1);
//always get the next to last
trace[trace.length-1] = new PVector(pts.x, pts.y, pts.z);
}
}
void textdraw(){
for(int i =0; i<fftLog.avgSize(); i++){
pushMatrix();
translate(pts.x, pts.y, pts.z);
rotateY(PI/2);
rotateZ(PI/2);
textFont(font);
fill(255,200);
text(round(fftLog.getAvg(i)*100),0,0,0);
popMatrix();
}
}
void plotTrace(){
/*
//drawing points
for(int i=0; i<trace.length; i++){
stroke(255,0,0);
//locator(trace.x, trace.y, trace.z, 1);
point(trace.x, trace.y, trace.z);
}
*/
//drawing poly surface
stroke(255,80);
int inc = fftLog.avgSize();
for(int i=1; i<trace.length-inc; i++){
if(i%inc != 0){
beginShape(TRIANGLE_STRIP);
float value = (trace.z*100);
float m = map(value, -500, 20000, 0, 255);
fill(m*2, 381, -m*2, 222);
vertex(trace.x, trace.y, trace.z);
vertex(trace[i-1].x, trace[i-1].y, trace[i-1].z);
vertex(trace[i+inc].x, trace[i+inc].y, trace[i+inc].z);
vertex(trace[i-1+inc].x, trace[i-1+inc].y, trace[i-1+inc].z);
endShape(CLOSE);
}
}
/*
//draw splines
int skip = 5;
stroke(255, 20);
noFill();
for(int i=0; i<trace.length; i+=inc*skip){
beginShape();
for(int j=0; j<inc; j+=skip){
stroke(255,0,0,40);
curveVertex(trace[i+j].x, trace[i+j].y, trace[i+j].z);
}
endShape();
}
*/ }
}
void keyPressed() {
// use a key press so that it doesn't make a million files
if (key == 'r') record = true;
}
Thanks
Alex