loading

Archive for the 'pdf' Category

Martin Wisniowski

Write or Die: Writing-Tool? Game? Lifehack?

write-or-die

Good, I have to try out this tool and at the same time suggest it to you. It is a *useful tool* and also got a very subtle kind of humor. Tools with humor? How does it work?

Write or die is meant for people who procrastinate lot or spend hours and hours slowly writing texts. This one will get you going. It supervises the words you type and measures the time of not. If the timeout is getting too big, you will be punished.

You begin your session by selecting the mode you want to work with: Select number of words, maximum session-time (=deadline?) and sort of evil-mode. The letter tells you, what kind of punishment you want, if you do not write, write, write like a slave (like me right know). The default mode is, that an “evil” sound will play on procrastination (I don’t think that sound is that bad / the sounds also differ). The most evil mode will delete the last words you typed, if you stop writing - so don’t answer the phone!

To be honest, you have to try this! This is really *useful*! And an interesting experience as well. I would doubt, that it enhances the quality of work in general, but in certain moods this can be really satisfying. Some people suggested to also implement “Design or Die”-modes into graphic software like Photoshop or Illustrator. Unfortunately this would not work at coding jobs… because there you have to think more!

write-or-die-result1

PS:
The tools from Dr. Wicked generally focus on writing tasks. He goes:

Welcome to the Writing Lab, Applications for Authors. Actual help for the floundering ones, no namby-pamby advice. Utilities that help you get writing done, and tools to help you with the deeply annoying parts of the editing process.

via Prokrastination.com

Peter Kirn

Processing Bug Fixes: SVG, PDF Problems Solved

Import and export is, of course, a huge workflow factor for anyone, especially anyone from a graphic design background. Some of my students at MassArt have been kicking the tires on Processing’s SVG and PDF libraries and running into hitches. There’s nothing more frustrating than getting an obscure error message when you think you’re doing things right. Happily, we’ve got some solutions.

Of course, it’d be great to hear from others with similar issues.

The following libraries might also be of use:
http://www.texone.org/prosvg/
http://processing.unlekker.net/SimplePostscript/index.html

PDF

Several students had problems with font embedding using the built-in library. Symptoms: strange, blocky letters. The issues seem to occur on Mac OS X (all the students in this case I believe were on Mac exclusively.) The reference documentation for the PDF library offers this clue:

Starting in release 0120, text is no longer treated as shape data by default, meaning that the font will need to be installed to view the PDF that’s created. The upside is that the PDF will render better (particularly in light of the Mac OS X bug noted here). To force text to be treated as shape data, use textMode(SHAPE), immediately after size(). See the developer reference for textMode() inside PGraphicsPDF for more specifics.

But so far, forcing SHAPE hasn’t been very helpful.

Colin Owens has this tip instead:

Placing:

hint(ENABLE_NATIVE_FONTS);

before text();

does the trick.

This needs to happen before all your other font/text code. (I believe setup() is optional.)

I also suggested, for those on the Mac, at least, that people get fonts working on Mac and try re-saving in Preview.app for cross-platform / cross-machine compatibility as needed. (The same would be true with Acrobat or any PDF builder on any platform, just in case the library is misbehaving.)

Oddly, people are still having issues in which the first couple of characters are garbled, so they’ve taken to hiding the first two characters used. Bizarre.

SVG

Mahesh Gudapakkam was having some problems with the SVG graphics format, even following examples from Ben Fry. Nicely enough, he solved it himself.

Basically, the issue was tag information being handled in a way other than he intended, thus triggering an array out of bounds error.

First, the symptoms:

running into a problem here .. i am trying to work with a SVG version of the US map.

i have a version that works well - zooms in and out and scales the way i want to - unfortunately i had no way to control characteristics of individual states (only later did i realize that SVG’s can have markers for individual states stored as attributes to its tags and my svg image didnt have any - i downloaded a free one of the web)

i realized the above while reading through ben fry’s [book Visualizing Data]. in an example of his, he points to an SVG on wikimedia (http://commons.wikimedia.org/wiki/Image:Blank_US_Map.svg)

for some reason when i work with this file i get an exception
java.lang.ArrayIndexOutOfBoundsException: 1

all i am doing at this point is declaring a SVG object and reading this downloaded object into it .. and then trying to display it - any ideas?.. processing version is 0135Beta

The problem? Poorly-formed tags:

quick update. i was able to figure out what was causing the array out of bounds error. comparing the working svg vs the one not working and picking up on some threads from some of the early postings rgd’ing issues with candy’s parsing on the processing forums - i found that the graphic tag had some extra attributes. here’s how it appears in the non-working ones.

OR

the candy svg library seems to not like this - once i reduced it down to it happily worked. also a few other things i had to change -
1. it does not work with the tag either - needed to get rid of it
2. some other tags it failed to work with are ones that had these attributes

# sodipodi:type="arc"
# sodipodi:nodetypes="cc"

processing complained that it does not recognize the shape command - once i got rid of these attributes it didnt complain of those errors ..

once i addressed all of these i was able to get the svg to work with candy.

this might be something of interest to others in the group who might end up working with SVG’s .. these tags get produced even when you use a program like illustrator to create a svg (i went that route too and it produced errors as well). hopefully it will save them some time.

If you run into other errors like this, let us know!

marius watz

SIAA workshop pt. 2

I’ve just uploaded the remaining files from the SIAA workshop to the workshop directory. They include examples for how to generate PDF, how to download your del.icio.us bookmarks using the delicious-java library and how to make HTTP requests using the Apache HttpClient class.

Thanks to the SIAA organizers and all the participants for a great workshop. I wanted to name all of you, but not everybody sent me their info. So anyway, cheers to Danny McNeil, James Brown, Chris Dunne, Pedro Mari, Javier Abanses, Li Zhu, Nick James, Mat Steel and Joe “Qubik” Gilmore.

Andreas

An Evening with Aristid Lindenmeyer

2007 03 17 14:21:06

Eigentlich fand ich L-Systeme immer ein wenig langweilig. Durch Zufall bin ich auf diesen Artikel von Joshua Davis gestoßen in dem er an ein paar Beispielen zeigt was man L-Systemen außer Pseudobäumen noch so machen kann. Zum Glück muss man für Processing nicht alles neu erfinden. Einmal kurz nach processing und lsystem gegoogelt und man hat schon mal einen guten Ansatzpunkt.

Wenn man nun, wie in Joshuas Artikel beschrieben, statt einfacher Linien für die Äste Grafiken zeichnen lässt bekommt nach einigem rumprobieren recht ansehnliche Ergebnisse. Gestartet hab ich mit importierten SVG Grafiken aus dem NEUBAUWELT Buch (oberes Bild). Danach dann einige Spielereien mit Bezierkurven und festen Winkel für die Verästelungen. Alle Bilder gibt’s hier.

Das gute an Processing ist, dass man das ganze als pdf exportieren und in Illustrator impotieren kann wobei alle Elemente als Vektorgrafik übernommen werden. Womit man eine gute Ausgangslage zur Weiterverarbeitung als Cover, Flyer etc. hat.

2007 03 26 23:14:37

Andreas

An Evening with Aristid Lindenmeyer

2007 03 17 14:21:06

Eigentlich fand ich L-Systeme immer ein wenig langweilig. Durch Zufall bin ich auf diesen Artikel von Joshua Davis gestoßen in dem er an ein paar Beispielen zeigt was man L-Systemen außer Pseudobäumen noch so machen kann. Zum Glück muss man für Processing nicht alles neu erfinden. Einmal kurz nach processing und lsystem gegoogelt und man hat schon mal einen guten Ansatzpunkt.

Wenn man nun, wie in Joshuas Artikel beschrieben, statt einfacher Linien für die Äste Grafiken zeichnen lässt bekommt nach einigem rumprobieren recht ansehnliche Ergebnisse. Gestartet hab ich mit importierten SVG Grafiken aus dem NEUBAUWELT Buch (oberes Bild). Danach dann einige Spielereien mit Bezierkurven und festen Winkel für die Verästelungen.

Das gute an Processing ist, dass man das ganze als pdf exportieren und in Illustrator impotieren kann wobei alle Elemente als Vektorgrafik übernommen werden. Womit man eine gute Ausgangslage zur Weiterverarbeitung als Cover, Flyer etc. hat.

2007 03 26 23:14:37

watz

Scripting Adobe Illustrator CS using JavaScript

Creating PDFs in Processing and post-processing them in Adobe Illustrator, I frequently find myself wanting to do things like adjust global transparency levels, colors etc. So far that's been frustrated by the rather poor color adjustment options built into Illustrator, but today I finally got impatient enough to look into a scripting solution.

Illustrator has had Javascript support since CS 1, exposing the document object model to anyone with a bit of scripting savvy. Adobe is good about publishing technical documents, perhaps a holdover from the days when they relied on PostScript to build their empire. So anyone can go to the online scripting documentation and download a complete PDF with a description of the Illustrator API.

As might be expected, coding Javascript is not without its troubles, and I found myself having dotcom flashbacks to the days when I would do client-side scripting. In particular, debugging is always been a pain with Javascript, especially when one is not intimate with the DOM and API. Fortunately, the ExtendScript Toolkit provided by Adobe functions both as a IDE and a debugger. Still, I find myself wanting a few nice details, like the possibility of displaying a progress bar when a script is executing.

To give you an idea of the oddities of coding for Illustrator, I am posting a script that allows the user to input a multiplier, which is then used to adjust the opacity of all path items in the active document. This covers for the lack of such a function in Illustrator proper. To be honest I was surprised at the speed with which I was able to accomplish my goal. I would seriously consider this as a way to do brute-force post-processing of vector files.

That said, I doubt it will ever be as fun and quirky as Scriptographer

Source code - OpacityAdj.js

// OpacityAdj.js - JavaScript for Adobe Illustrator CS
// Marius Watz - http://workshop.evolutionzone.com
//
// Adjusts opacity for all paths by a given multiplier.
 
// Prompt user for input
var mult=eval(prompt("Multiplier for transparency",1,"TransMult.js"));
 
// $.writeln() is used to write to the JavaScript console
$.writeln("Multiplier: '"+mult+"'");
if(mult==1) alert("Multiplier is 1.0. No changes made.");
if(mult<=0) {
  alert("Multiplier can't be zero or negative.");
  mult=1;
}
 
index=0;
 
// Get active document from the global Application variable "app".
doc = app.activeDocument;
 
if ( doc.pathItems.length > 0 && mult!=1) {
  thePaths = doc.pathItems;
  numPaths = thePaths.length;
  for ( i = 0; i <numPaths ; i++ ) {
    pathArt = doc.pathItems[i];
    newval=pathArt.opacity*mult;
    if(newval>100) newval=100;
    pathArt.opacity=newval;
 
    // Provide some feedback for complex documents.
    if(index%500==0) {
      percstr=""+((index/numPaths )*100);
      decimalPos=percstr.indexOf(".");
      if(decimalPos!=-1 && (percstr.length-decimalPos>4))
        percstr=percstr.substring(0,decimalPos+2);
      $.writeln(percstr+"% - "+index+"/"+numPaths );
    }
    index++;
  }
  $.writeln("OpacityAdj.js done.");
}
watz

Tile-based output of huge raster images

Demo of high-res tiled image output: KugelTiled04 res demo

I've been able to generate huge raster files for print use from Processing, using the tiling trick first outlined on the Processing forums by user "surelyyoujest". Using his code as a base, I got it working with OpenGL and proceeded to output some gigantic files. A quick hack using PImage allowed me to stitch the resulting tiles together in one huge image, which was then saved as a Targa file.

See the picture above for a demo. When viewed at its original size, the left half of this image shows the full picture at 10% (original res 10240 x 7680 px). The right half shows the whited-out section of the left image at 100%. The resolution is staggering.

This should clear the way for doing huge prints, without not having to worry about PDFs not showing 3D correctly (see previous post). I will post sample code for tile-based rendering and stitching as a library when I have time.

watz

Code tool: NodeBox

I just posted an entry about NodeBox over on Generator.x. libraries, like the Pixie handwriting library or the PhotoBot image processing library.

Unfortunately, NodeBox is only for Mac OS, but the source is available under a MIT license. It looks like a fun alternative to Processing with a slightly different bias on what kind of work it is useful for. Have a look at the Gallery for some examples.

watz

More PDF: Graphics for NIAF

060522_pdf_niaf_postcards.jpg

More PDF output examples: Graphics for NIAF

More gratuitous (real-world) examples of how great PDF output is. These are teaser postcards for Norwich International Animation Festival, which will take place in October this year. I am doing a generative piece which will function as identity graphics for the festival. Essentially, a single Processing software will generate a large variety of stills for print use (using PDF), as well as realtime animated trailers to be run ahead of every screening.

See Flickr for my sketches for the NIAF piece, the image over shows the 4 postcards that will go out in the next few weeks. Posters and a catalogue will follow, which I am very excited about. Again, the images show that the new PDF output library gives very high quality for print when using 3D objects.

However, there are a few quirks to PDF:

  • No depth-sorting or intersecting objects. In the NIAF project that proved to be a benefit rather than a setback, as the shapes would sometimes intersect in a visually unattractive way.
  • No pro-vertex shading, i.e. no gradient-filled polygons. In the NIAF piece you can see that I have used multiple polygons with interpolated color. This is not ideal, as it produces banding, but it can be worked into the aesthetic of the piece.
  • No possibilities for using groups or layers, a typical feature of PDF and Illustrator documents. If this could be added it would make it much easier to post-edit the results. Processing uses the free iText PDF library, and I experimented briefly with inserting layers by directly accessing the PDFWriter object, but no luck so far.

Still, PDF output is a god-send for a range of new Processing applications.

Andreas

PDF Output

Marius Watz zeigt hier an einem Beispiel wie man einen pdf Screenshot von seinem Processing Sketch machen kann. Das Ergebniss ist wirklich grandios. Alle Elemente werden als Vektorgrafik in das pdf gepackt, was ein verlustfreies Plotten in jeder beliebigen Größe ermöglicht. Das ganze funktioniert nicht nur im normalen sondern auch im P3D bzw. OPENGL Mode.
Die […]

watz

Code: PDF for complex 3D output

Complex 3D output using PDF in Processing

Complex 3D output using PDF in Processing.

Sample code for PDF output of complex geometries from Processing, with a 3D shape using lines and polygons being written correctly to PDF. Uses beginRaw() / endRaw().

Source code - pdf_complex.pde

// pdf_complex.pde - workshop.evolutionzone.com - Marius Watz
// Example using PDF to output complex 3D geometry for print.
// Press "s" to save a PDF.
 
import processing.opengl.*;
import processing.pdf.*;
 
// Trig lookup tables borrowed from Toxi. Cryptic but effective
public static final float sinLUT[];
public static final float cosLUT[];
public static final float SINCOS_PRECISION=1f;
public static final int SINCOS_LENGTH= (int) (360f/SINCOS_PRECISION);
static {
  sinLUT=new float[SINCOS_LENGTH];
  cosLUT=new float[SINCOS_LENGTH];
  for (int i=0; i<SINCOS_LENGTH; i++) {
    sinLUT[i]= (float)Math.sin(i*DEG_TO_RAD*SINCOS_PRECISION);
    cosLUT[i]= (float)Math.cos(i*DEG_TO_RAD*SINCOS_PRECISION);
  }
}
 
// System data
boolean dosave=false;
int num;
float pt[];
int style[];
 
void setup() {
  size(600, 600, OPENGL);
  framerate(24);
  background(255);
 
  num=150;
  pt=new float[6*num]; // rotx, roty, deg, rad, w, speed
  style=new int[2*num]; // color, render style
 
  // Set up arc shapes
  int index=0;
  float prob;
  for(int i=0; i<num; i++) {
    pt[index++]=random(PI*2); // Random X axis rotation
    pt[index++]=random(PI*2); // Random Y axis rotation
 
    pt[index++]=random(60,80); // Short to quarter-circle arcs
    if(random(100)>90) pt[index]=(int)random(8,27)*10;
 
    pt[index++]=(int)random(2,50)*5; // Radius. Space them out nicely
 
    pt[index++]=random(4,32); // Width of band
    if(random(100)>90) pt[index]=random(40,60); // Width of band
 
    pt[index++]=radians(random(5,30))/5; // Speed of rotation
 
    // get colors
    prob=random(100);
    if(prob<30) style[i*2]=colorBlended(random(1),
    255,0,100, 255,0,0, 210);
    else if(prob<70) style[i*2]=colorBlended(random(1),
    0,153,255, 170,225,255, 210);
    else if(prob<90) style[i*2]=colorBlended(random(1),
    200,255,0, 150,255,0, 210);
    else style[i*2]=color(255,255,255, 220);

    if(prob<50) style[i*2]=colorBlended(random(1),
      200,255,0, 50,120,0, 210);
    else if(prob<90) style[i*2]=colorBlended(random(1),
      255,100,0, 255,255,0, 210);
    else style[i*2]=color(255,255,255, 220);

 
    style[i*2+1]=(int)(random(100))%3;
  }
}
 
void draw() {
 
  if(dosave) {
    // set up PGraphicsPDF for use with beginRaw()
    PGraphicsPDF pdf=(PGraphicsPDF)beginRaw(PDF, "pdf_complex_out.pdf"); 

    // set default Illustrator stroke styles and paint background rect.
    pdf.strokeJoin(MITER);
    pdf.strokeCap(SQUARE);
    pdf.fill(0);
    pdf.noStroke();
    pdf.rect(0,0, width,height);
  }
 
  background(0);
 
  int index=0;
  translate(width/2,height/2,0);
  rotateX(PI/6);
  rotateY(PI/6);
 
  for(int i=0; i<num; i++) {
    pushMatrix();
 
    rotateX(pt[index++]);
    rotateY(pt[index++]);
 
    if(style[i*2+1]==0) {
      stroke(style[i*2]);
      noFill();
      strokeWeight(1);
      arcLine(0,0, pt[index++],pt[index++],pt[index++]);
    }
    else if(style[i*2+1]==1) {
      fill(style[i*2]);
      noStroke();
      arcLineBars(0,0, pt[index++],pt[index++],pt[index++]);
    }
    else {
      fill(style[i*2]);
      noStroke();
      arc(0,0, pt[index++],pt[index++],pt[index++]);
    }
 
    // increase rotation
    pt[index-5]+=pt[index]/10;
    pt[index-4]+=pt[index++]/20;
 
    popMatrix();
  }
 
  if(dosave) {
    endRaw();
    dosave=false;
  }
}
 
 
// Get blend of two colors
public int colorBlended(float fract,
float r, float g, float b,
float r2, float g2, float b2, float a) {
 
  r2 = (r2 - r);
  g2 = (g2 - g);
  b2 = (b2 - b);
  return color(r + r2 * fract, g + g2 * fract, b + b2 * fract, a);
}
 
 
// Draw arc line
public void arcLine(float x,float y,float deg,float rad,float w) {
  int a=(int)(min (deg/SINCOS_PRECISION,SINCOS_LENGTH-1));
  int numlines=(int)(w/2);
 
  for(int j=0; j<numlines; j++) {
    beginShape(LINE_STRIP);
    for(int i=0; i<a; i++) vertex(cosLUT[i]*rad+x,sinLUT[i]*rad+y);
    endShape();
    rad+=2;
  }
}
 
// Draw arc line with bars
public void arcLineBars(float x,float y,float deg,float rad,float w) {
  int a=(int)(min (deg/SINCOS_PRECISION,SINCOS_LENGTH-1));
  a/=4;
 
  beginShape(QUADS);
  for(int i=0; i<a; i+=4) {
    vertex(cosLUT[i]*(rad)+x,sinLUT[i]*(rad)+y);
    vertex(cosLUT[i]*(rad+w)+x,sinLUT[i]*(rad+w)+y);
    vertex(cosLUT[i+2]*(rad+w)+x,sinLUT[i+2]*(rad+w)+y);
    vertex(cosLUT[i+2]*(rad)+x,sinLUT[i+2]*(rad)+y);
  }
  endShape();
}
 
// Draw solid arc
public void arc(float x,float y,float deg,float rad,float w) {
  int a=(int)min (deg/SINCOS_PRECISION,SINCOS_LENGTH-1);
  beginShape(QUAD_STRIP);
  for(int i=0; i<a; i++) {
    vertex(cosLUT[i]*(rad)+x,sinLUT[i]*(rad)+y);
    vertex(cosLUT[i]*(rad+w)+x,sinLUT[i]*(rad+w)+y);
  }
  endShape();
}
 
void keyPressed() {
  if(key=='s') dosave=true;
}
 
void mouseReleased() {
  background(255);
}
watz

C.stem: CMYK posters

Proof positive of the power of PDF export in Processing: I have just uploaded images of 4 posters I've made for the upcoming C.stem exhibition in Turin. Using the new PDF export, I was able to effortlessly output print-ready files which were then finally prepped in InDesign. Using PDF has many advantages over the older libraries (AIExport, my own SimplePostscript etc):

  • Using beginRaw() / endRaw() it is possible to render 3D shapes.
  • Adding PDF output is typically 6 lines of code.
  • PDF has transparency support.
  • Using PDF with Processing gives you accurate control over the canvas size and units.

As you can tell, I can not say how excited I am about the PDF output. Thank you, Ben!

This set of posters were output as black only, so that the printer could easily output a single film for each poster. They are then printed as a single-color process, with each using one of the CMYK colors. See also the Sketches Flickr set for in-progress examples, or C.Stem: CMYK posters (Original size) for a higher-res version.

watz

Flickr: C3D 0035 no bg flat

Real test of complex polygon models with PDF output from Processing, rasterized and monotoned in Photoshop. Some very few 3D rendering artifacts are visible, but considering the complexity of the scene it's impressive.

hint(ENABLE_DEPTH_SORT) breaks PDF output for me, so haven't been able to see if that would help with the few incorrectly sorted triangles visible to the right.

watz

Flickr: Cstem-PDF-Sketch-03

Cstem-PDF-Sketch-03

Cstem-PDF-Sketch-03, originally uploaded by watz.

I am testing blogging pictures from Flickr.

This is a closeup of 3D shapes rendered as PDF with the new beginRaw() function in Processing. The results are amazing. Have a look at these for reference: 1, 2, 3, 4.

The upshot of this new function is that one can now output complex 3D geometry complete with transparency, and get practically identical images in PDF and OpenGL. I predict that a deluge of Processing print pieces will follow… I’ll post some sample code for this functionality in the next few days, it’s not so well documented yet, as it’s fresh out of Ben’s dungeon.