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 & HelpPrograms › PDF export problem with basicStroke
Page Index Toggle Pages: 1
PDF export problem with basicStroke? (Read 657 times)
PDF export problem with basicStroke?
May 15th, 2009, 10:48pm
 
Could someone please tell me why the PDF doesn't show the dashes that I see on the screen.  What would be the best way to output a file so as to show the dashes?

Code:
import processing.pdf.*;

int numFlower = 5;
Flower[] flowers1 = new Flower[numFlower];
float[] dashes = { 4.0f, 6.0f, 4.0f, 6.0f};
BasicStroke pen;

void setup(){
 size(400,240);
 smooth();
 pen = new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 4.0f, dashes, 0.0f);
 Graphics2D g2 = ((PGraphicsJava2D) g).g2;
 g2.setStroke(pen);
}
void draw(){
 background(255);    
 int f = frameCount;
 if (f < 2){
 frameRate(0.5);
 beginRecord(PDF, "gl-##.pdf");
 for (int i = 0; i < numFlower; i++){
   float w = random(width);
   float h = random(height);
   if (w < 50){w = w + 50;}
   if (w > 350){w = w - 50;}
   flowers1[i] = new Flower(w, h, 30, 50, 6, 30); //Flower(x,y,r1,r2,divisions,flare)
 }
 for(int i = 0; i < numFlower; i++){
   flowers1[i].display();
 }
endRecord();
}
}


class Flower {
 float ox;
 float oy;
 int r1; //interior points of petals
 int r2; //control points of petals
 int divisions;
 int flare;
 
 Flower(float xIn, float yIn, int r1In, int r2In, int divIn, int flareIn){
   ox = xIn;
   oy = yIn;    
   r1 = r1In;
   r2 = r2In;
   divisions = divIn;
   flare = flareIn;
 }
 
 void display(){
   float inc = 360/divisions;
   float x = ox + (cos(radians(inc))*r1);
   float y = oy + (sin(radians(inc))*r1);
   
   fill(255);
   beginShape();
   vertex(x,y);
   for (float deg=inc; deg < 360+inc; deg+= inc){            //petals
     float angle1 = radians(deg);
     float angle2 = radians(deg+inc);
     float cx1 = ox + (cos(angle1+PI/flare) * r2);
     float cy1 = oy + (sin(angle1+PI/flare) * r2);
     float cx2 = ox + (cos(angle2-PI/flare) * r2);
     float cy2 = oy + (sin(angle2-PI/flare) * r2);
     float x2 = ox + (cos(angle2) * r1);
     float y2 = oy + (sin(angle2) * r1);
     bezierVertex(cx1,cy1,cx2,cy2,x2,y2);
  }
  endShape();
  noFill();
  ellipse(ox,oy,r1*1.5,r1*1.5);
 }
}


thanks
Re: PDF export problem with basicStroke?
Reply #1 - May 15th, 2009, 11:10pm
 
as benfry said
Quote:
also keep in mind that this only works in the default renderer, and as with anything when you grab the Graphics2D object, don't be sad if it doesn't work as expected. (see the faq for more dire warnings re: don't use java graphics.)

sincerely,

the caveat police

It just doenst work with the pdf export. Same with the StrokeCaps...
Re: PDF export problem with basicStroke?
Reply #2 - May 16th, 2009, 8:20am
 
Ahh, I had a feeling that was going to be the answer.

Does anyone have a suggestion for how to get dashed/dotted lines that will work w/ pdf?
Re: PDF export problem with basicStroke?
Reply #3 - May 16th, 2009, 8:28am
 
What about a class of your own that took an Vector / ArrayList of points and connected every other one with a line?  [0-1, 2-3, 4-5]  To look even, it would need some special instructions for long / short segments (break long ones down by adding evenly spaced points, or connect multiple short segments).
Re: PDF export problem with basicStroke?
Reply #4 - May 16th, 2009, 9:05am
 
we had something similar some time ago, but it was more basic. Drawing just a line.
http://processing.org/discourse/yabb2/num_1219255354.html

but maybe it can be adjusted somehow...
Page Index Toggle Pages: 1