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);
}
}
}