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 & HelpSyntax Questions › P2D bug: strokeWeight lines 2X too wide (v1.05)
Page Index Toggle Pages: 1
P2D bug: strokeWeight lines 2X too wide (v1.05) (Read 356 times)
P2D bug: strokeWeight lines 2X too wide (v1.05)
Jun 24th, 2009, 7:58am
 
Like many others, I often switch between JAVA2D, P2D, P3D, and OPENGL to trade off quality and speed when drawing.  Therefore, it is important for drawing functions to be as consistent as possible.

There is a strokeWeight bug in P2D. Cry
It draws lines twice as wide as they should be.

In JAVA2D and P3D, using strokeWeight(40) lines are drawn correctly (40 pixels wide).

In P2D, using StrokeWeight(40), lines are drawn incorrectly (80 pixels wide).

Since the error seems to be a simple factor of 2, I am hoping it will be easy for someone (who knows how to navigate the Processing source code) to track down and correct this bug.

(Note: This bug is different from the documented limitation in OPENGL where the max line width (e.g., 10 px) is limited by your graphics card.)
Re: P2D bug: strokeWeight lines 2X too wide (v1.05)
Reply #1 - Jun 24th, 2009, 8:06am
 
This code illustrates the P2D bug: strokeWeight lines 2X too wide

Switch the drawing mode to JAVA2D or P3D and the error goes away.

Code:

import processing.opengl.*;
// stroke_demo


final int Npoints = 4;
float [] x = {
 70, 150, 70, 70 };
float [] y = {
 40, 100, 160, 200 };

void setup() {
 size(400,300, P2D);
 hint(DISABLE_OPENGL_2X_SMOOTH);
 smooth();
 drawBackground();
}

void drawBackground() {
 int i, j;

 background(190);
 noStroke();
 fill(160);
 for (i = 0 ; i < width ; i += 20) {
   for (j = 0 ; j < height ; j += 10) {
     rect(i+(j%20),j, 10,10);
   }
 }
}

void draw() {

 noFill();
 strokeJoin(ROUND);
 strokeCap(SQUARE);
 strokeShape();
 if (frameCount > 10) {
   saveFrame("stroke.tif");
   noLoop();
 }
}

void strokeShape() {
 stroke(0,90);
 strokeWeight(40);
 drawShape();

 stroke(255);
 strokeWeight(2);
 drawShape();

 drawBox();
}

void drawShape() {
 int i;

 if (frameCount == 1) {
   beginShape();
   for (i = 0 ; i < Npoints ; ++i) {
     vertex(x[i],y[i]);
   }
   endShape();

   for (i = 1 ; i < Npoints ; ++i) {
     line(x[i-1]+100,y[i-1], x[i]+100,y[i]);
   }
 }

 for (i = 1 ; i < Npoints ; ++i) {
   if (i == frameCount) {
     line(x[i-1]+200,y[i-1], x[i]+200,y[i]);
   }
 }
}

void drawBox() {
 int i;

 if (frameCount == 1) {
   stroke(255);
   strokeWeight(2);
   fill(0,90);
   rectMode(CENTER);
   for (i = 0 ; i < 3 ; ++i) {
     rect(x[3]+i*100,y[3]+50, 40,40);
   }
 }
}
Page Index Toggle Pages: 1