frankb
YaBB Newbies
Offline
Posts: 44
dxf out
Sep 23rd , 2006, 5:14am
I've been playing around with the examples from the particle system page but I'm now trying to output one of the forms to a dxf file. it works but when I try to open the file i get an error message does any one know what i'm doing wrong? Thanks for your help. import traer.physics.*; import processing.dxf.*; boolean record; ParticleSystem physics; Particle[][] particles; int gridSize = 10; void setup() { size(400, 400,P3D); fill(0); framerate(60); physics = new ParticleSystem(0, 0,5,0.5); particles = new Particle[gridSize][gridSize]; float gridStepX = (float) ((width / 2) / gridSize); float gridStepY = (float) ((height / 2) / gridSize); for (int i = 0; i < gridSize; i++) { for (int j = 0; j < gridSize; j++) { //Spring makeSpring( Particle a, Particle b, float strength, float damping, float restLength ) particles[i][j] = physics.makeParticle(0.2, j * gridStepX + (width / 4), i * gridStepY + 20, sin(gridStepY + 20)); if (j > 0) { physics.makeSpring(particles[i][j - 1], particles[i][j], 8.0, 0.5, gridStepX); } } } for (int j = 0; j < gridSize; j++) { for (int i = 1; i < gridSize; i++) { physics.makeSpring(particles[i - 1][j], particles[i][j], 8.0, 0.5, tan(gridStepY)); } } particles[0][0].makeFixed(); particles[0][gridSize - 1].makeFixed(); particles[9][gridSize - 1].makeFixed(); particles[9][gridSize - 10].makeFixed(); } void keyPressed() { // use a key press so that it doesn't make a million files if (key == 'r') record = true; } void draw() { if (record) { beginRaw("processing.dxf.RawDXF", "output.dxf"); } physics.advanceTime(0.1); if (mousePressed && keyCode == UP) { particles[0][gridSize - 1].moveTo(mouseX, mouseY, 0); particles[0][gridSize - 1].velocity().clear(); } if (mousePressed && keyCode == LEFT) { particles[9][gridSize - 1].moveTo(mouseX, mouseY, 0); particles[9][gridSize - 1].velocity().clear(); } if (mousePressed && keyCode == RIGHT) { particles[9][gridSize - 10].moveTo(mouseX, mouseY, 0); particles[9][gridSize - 10].velocity().clear(); } if (mousePressed && keyCode == DOWN) { particles[0][0].moveTo(mouseX, mouseY, 0); particles[0][0].velocity().clear(); } background(255); for (int i = 0; i < gridSize; i++) { beginShape( LINE_STRIP ); curveVertex(particles[i][0].position().x(), particles[i][0].position().y()); for (int j = 0; j < gridSize; j++) { curveVertex(particles[i][j].position().x(), particles[i][j].position().y()); } curveVertex(particles[i][gridSize - 1].position().x(), particles[i][gridSize - 1].position().y()); endShape(); } for (int j = 0; j < gridSize; j++) { beginShape( LINE_STRIP ); curveVertex(particles[0][j].position().x(), particles[0][j].position().y()); for (int i = 0; i < gridSize; i++) { curveVertex(particles[i][j].position().x(), particles[i][j].position().y()); } curveVertex(particles[gridSize - 1][j].position().x(), particles[gridSize - 1][j].position().y()); endShape(); } } void mouseReleased() { particles[0][gridSize - 1].setVelocity( (mouseX - pmouseX), (mouseY - pmouseY), 0 ); if (record) { endRaw(); record = false; } }