Saving as SVG – Processing

Code 1 in Processing:

import org.philhosoft.p8g.svg.P8gGraphicsSVG;
P8gGraphicsSVG svg;

Particle myParticle;
ArrayList<Particle> particles;

void setup (){

size(500,500);

svg = (P8gGraphicsSVG) createGraphics(width, height, P8gGraphicsSVG.SVG, “SVGTEST1.svg”);
beginRecord(svg);
particles = new ArrayList();

Particle p = new Particle();
particles.add( new Particle() );

//or (same as above): particles.add ( new Particle() );
}

void draw(){

background(255);

for (int i = 0; i < particles.size(); i++){
Particle p=particles.get(i);
p.update();
p.display();

}
}

void keyPressed(){
if (key == ‘n’){
particles.add(new Particle() );
println( particles.size() );
}
if (key == ‘s’){
svg.endRecord();
println(“File saved.”);
}
else if (key == ‘q’) {
svg.clear();
exit();
}
}

class Particle{

//variables
float x;
float y;
float velX;
float velY;

Particle(){
x = random(width);
y = random(height);
velX = random (-5,5);
velY = random(-5,5);

}

void display(){
ellipse(x,y,10,10);
}

void update(){
x += velX;
y += velY;
velX -= velX*.1;
velY -= velY*.1;

}
}

 

Exported as SVG files (2 tests):

Screen Shot 2014-10-28 at 9.49.05 AM

Screen Shot 2014-10-28 at 9.49.19 AM

Editing in Illustrator:

Screen Shot 2014-10-28 at 9.52.46 AM

Code 2 in Processing:

ArrayList<Agent> agents;
import org.philhosoft.p8g.svg.P8gGraphicsSVG;
import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;

Minim minim;
AudioInput audioIn;
FFT fft;

P8gGraphicsSVG svg;
void setup() {

size (400, 400);

svg = (P8gGraphicsSVG) createGraphics(width, height, P8gGraphicsSVG.SVG, “SVGTEST1.svg”);
beginRecord(svg);
minim=new Minim(this);
audioIn=minim.getLineIn(Minim.STEREO, 1024);
fft = new FFT(audioIn.bufferSize(), audioIn.sampleRate());

agents = new ArrayList();
for (int i = 0; i < 100; i++) {
agents.add( new Agent() );
}
}

void draw() {
float volume = audioIn.mix.level();
background(volume * 1350, volume * 500, volume * 500);

for ( int i = 0; i < agents.size (); i++) {
Agent myAgent = agents.get(i);
myAgent.update();
myAgent.display();
}

for ( int i = 0; i < agents.size (); i++) {

for ( int j = 0; j < i; j++) {

Agent myAgentA = agents.get(i);
Agent myAgentB = agents.get(j);
float myDist = dist(myAgentA.x, myAgentA.y, myAgentB.x, myAgentB.y);
if ( myDist < 50) {
float alpha = map (myDist,0,50,0,255);
stroke(50 + volume * 500,200-alpha * volume * 1000, 100);
line(myAgentA.x, myAgentA.y, myAgentB.x, myAgentB.y);
}
}
}
}

class Agent {

float x;
float y;
float noiseX;
float noiseY;

Agent() {
x = random(width);
y = random(height);
noiseX = random (100);
noiseY = random (100);
}

void display() {

ellipse(x, y, 3, 3);
}

void update() {
float volume = audioIn.mix.level();
x = width * noise(noiseX) ;
y = height * noise(noiseY);
noiseX += volume/6;
noiseY += volume/6;
}
}

void keyPressed(){
if (key == ‘s’){
svg.endRecord();
println(“File saved.”);
}
else if (key == ‘q’) {
svg.clear();
exit();
}
}

 

Exported as SVG files (2 tests):

Screen Shot 2014-10-28 at 9.57.16 AM

Screen Shot 2014-10-28 at 9.57.03 AM

Editing in Illustrator:

Screen Shot lines

NEXT STEP: LASER CUT ON MATERIAL

(to be continued…)

From: Greece Born: 1995 Parsons Paris AMT Student

Leave a reply