We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › export pdf and hsb colormode
Page Index Toggle Pages: 1
export pdf and hsb colormode? (Read 892 times)
export pdf and hsb colormode?
Oct 3rd, 2008, 12:51pm
 
hello all,

i'd like to export some vectors from a sketch which colormode is set to HSB.

i have already a more or less working solution (see below) ... but unfortunately this one is based on "beginRaw()" and as a result of beginRaw() if have to work with the opengl and p3d renders (?) ... but then all my surface a splited in vertices due to the 3d renders. hmm not so cool.

so does anybody know, how to export a pdf in combination with colormode HSB and the default renderer?

thanks benedikt
ps i'm using processing 0135

Code:

import processing.opengl.*;
import processing.pdf.*;
PGraphicsPDF pdf;

boolean dosave=false;

void setup() {
 size(800, 800, OPENGL);
 colorMode(HSB, 360, 100, 100);
 noStroke();
}

void draw() {

 if(dosave) {
   pdf = (PGraphicsPDF) createGraphics(width, height, PDF, "hsb_test_"+frameCount+".pdf");    
   beginRaw(pdf);
   // set default
   pdf.colorMode(HSB);
   pdf.strokeJoin(MITER);
   pdf.strokeCap(SQUARE);
   pdf.fill(0);
   pdf.noStroke();
   pdf.rect(0,0,width,height);
 }

 fill(120,100,100);
 rect(0,0,width*0.33,height);
 fill(240,100,100);
 rect(width*0.33,0,width*0.33*2,height);
 fill(360,100,100);
 rect(width*0.33*2,0,width,height);

 if(dosave) {
   endRaw();
   dosave=false;
 }
}

void keyPressed() {  
 if (key == 's' || key == 'S') {
   dosave=true;
   saveFrame("hsb_test_"+frameCount+".png");
 }
}

Re: export pdf and hsb colormode?
Reply #1 - Oct 3rd, 2008, 9:07pm
 
why not use size(800, 800, PDF, "test.pdf")?

or if not, try beginRecord() if you want to echo all drawing commands.

the only reason to use beginRaw() is when you want to export 3D geometry, which beginRaw() captures after it's been decomposed into lines a triangles.
Re: export pdf and hsb colormode?
Reply #2 - Oct 4th, 2008, 11:33am
 
thanks.

tried it in the first time with beginRecord() and the default renderer but that was not working ...

i know now why, the hsb export will just work if you set the colormode in that way:
pdf.colorMode(HSB, 360, 100, 100, 100);
for some reason pdf.colorMode(HSB) (without the explicit values) does not work like expected with beginRecord() ... but then again works correctly with beginRaw()? bug?

anyway now everything is working :)
benedikt

Code:

import processing.pdf.*;
PGraphicsPDF pdf;

boolean dosave=false;

void setup() {
size(800, 800);
colorMode(HSB, 360, 100, 100, 100);
noStroke();
}

void draw() {
if(dosave) {
pdf = (PGraphicsPDF) createGraphics(width, height, PDF, "hsb_test_"+frameCount+".pdf");
beginRecord(pdf);
// set default
pdf.colorMode(HSB, 360, 100, 100, 100);
pdf.strokeJoin(MITER);
pdf.strokeCap(SQUARE);
pdf.fill(0);
pdf.noStroke();
pdf.rect(0,0,width,height);
}

fill(120,100,100);
rect(0,0,width,height);
fill(240,100,100);
rect(width*0.33,0,width,height);
fill(360,100,100);
rect(width*0.33*2,0,width,height);

if(dosave) {
endRecord();
dosave=false;
}
}

void keyPressed() {
if (key == 's' || key == 'S') {
dosave=true;
saveFrame("hsb_test_"+frameCount+".png");
}
}

Re: export pdf and hsb colormode?
Reply #3 - Oct 5th, 2008, 10:11pm
 
no, not a bug. you shouldn't be mixing beginRecord() with making calls like pdf.colorMode(). you can either do createGraphics(), and use pdf.beginDraw() and pdf.endDraw() to draw directly into it, or you can use beginRecord() to echo all drawing commands to a second renderer (so that things draw on screen, then draw to a file). the code in your last message mixes those two methods, which will give you weird results.
Re: export pdf and hsb colormode?
Reply #4 - Oct 6th, 2008, 8:53am
 
okay, thanks i understand now the concept ... for the "beginRecord()" way this should be a correct solution.

benedikt

Code:

import processing.pdf.*;
PGraphicsPDF pdf;

boolean dosave=false;

void setup() {
 size(800, 800);
 colorMode(HSB, 360, 100, 100, 100);
 noStroke();
}

void draw() {
 if(dosave) {  
   beginRecord(PDF, "hsb_test_"+frameCount+".pdf");
   // call again to set colormode of pdf renderer
   colorMode(HSB, 360, 100, 100, 100);

   // set some defaults
   strokeJoin(MITER);
   strokeCap(SQUARE);

   noStroke();
 }

 fill(120,100,100);
 rect(0,0,width,height);
 fill(240,100,100);
 rect(width*0.33,0,width,height);
 fill(360,100,100);
 rect(width*0.33*2,0,width,height);

 if(dosave) {
   endRecord();
   dosave=false;
 }
}

void keyPressed() {  
 if (key == 's' || key == 'S') {
   dosave=true;
   saveFrame("hsb_test_"+frameCount+".png");
 }
}

Re: export pdf and hsb colormode?
Reply #5 - Dec 4th, 2008, 8:24pm
 
Thanks for this post, guys!  Very helpful.
Page Index Toggle Pages: 1