Using P8gGraphics to export sketch as .svg file for Adobe Illustrator

edited June 2014 in Library Questions

Hi,

I am using PhiLho's excellent library to export sketches as an .svg.

http://phi.lho.free.fr/programming/Processing/P8gGraphicsSVG/index.html

I was successful in saving the sketch as an .svg (although, lost the typeface settings which I am willing to overlook for now), which, if I preview on mac OS by clicking space bar, displays my image.

However, when I try to open the .svg with illustrator, it gives the error:

Screen Shot 2014-06-09 at 19.01.02

All help appreciated. See code below.

Will

As extra info: I am using Processing version 1.5.1 (because since I upgraded my hard-drive, Processing 2 stopped working...) and here is my code:

/*
 *M O I R E  G E N E R A T O R
 *9th June 2014
 *Will Brown
 *
 *Credit to Alex Mutter for original code
 */

import org.philhosoft.p8g.svg.P8gGraphicsSVG;

PFont KnockoutLite;
P8gGraphicsSVG svg;

int state = 0;
int old_state = 0;
long f = 0;
long ff = 0;
int runNumber = 0;

float r1 = 0;
float r2 = 0;
float r3 = 0;

void setup () {
  size(600, 400);
  background(200);
  smooth();
  KnockoutLite = createFont("KnockHTF49Lit", 20);
  textFont(KnockoutLite);

  svg = (P8gGraphicsSVG) createGraphics(width, height, P8gGraphicsSVG.SVG, "MOIRE.svg");
  beginRecord(svg);

  println("Press g to start,\ns to save the image,\nand q to end the sketch");
}

void draw() {

  if (state == 0) {
    background(200);
    f = frameCount;

    r1 = random(3, 4);
    r2 = random(-1, 1);
    r3 = random(-1, 1);
  }

  if (state == 1) {
    ff = frameCount - f;


    pushMatrix();
    translate(-120 + ff*r1, height/2 + ff*r2); //translate(-120 + frameCount*3, height/2);
    drawFigureTwo();//ellipse
    popMatrix();

    pushMatrix();
    translate(width/2 + ff*r3, -60 + ff*3);
    drawFigureTwo();
    popMatrix();

    //print(ff);

    if (ff > 300) {
      drawBorder();
      runNumber++;
      //print(runNumber);
      state = 2;
    }
  }

  if (state == 2) {
    ff = frameCount - f;

    if (ff > 350) {
      noStroke();
      fill(50);
      textAlign(CENTER);
      text("#"+runNumber, 300, 330);
      rectMode(CENTER);
      rect(300, 335, 25, 2);
    }
  }
}

void drawFigureOne () {//draw rectangle
  noFill();
  stroke(0, 0, 0, 128);
  ellipseMode(CENTER);
  ellipse(0, 0, 250, 250);
}

void drawFigureTwo () {//draw ellipse
  noFill();
  stroke(0, 0, 0, 128);
  ellipseMode(CENTER);
  ellipse(0, 0, 250, 250);
}

void keyPressed() {
  if ((key == 'g') && (state != 2)) {
    state = 1;
  }

  if (key == 's') {
    svg.recordFrame("MOIRE-###.svg");
    println("Saved #" + svg.savedFrameCount);
    state = 0;
  }

  //if (key == 'd') {
  //  svg.endRecord();
  //  println("Saved current.");
  //}

  if (key == 'q') {
    svg.clear();
    exit();
  }
}

void drawBorder() {
  noStroke();
  fill(200);
  rectMode(CORNERS);
  rect(0, 0, 200, 400);
  rect(0, 0, 600, 100);
  rect(400, 0, 600, 400);
  rect(0, 300, 600, 400);
}

Answers

Sign In or Register to comment.