rect(x, y, width, height)
in
Programming Questions
•
2 years ago
I just notice that rect() rectangles are 1 pixel wider if stroke() is on.
So 2x5 becomes 3x6 for example
aaaaa
aaaaa
bbbbbb
baaaab
bbbbbb
It's kind of a bug, although it's easy to compensate for it.
Try the following code to see it.
- void setup() {
size(200,200);
background(200);
noLoop();
}//setup() - void draw() {
//
stroke(100,100,100);
fill(0,0,0);
rect(10+6,4,1,1); //has size 1+1
rect(10+5,9,2,2); //has size 2+1
rect(10+4,15,3,3); //has size 3+1
rect(10+3,22,4,4); //has size 4+1
rect(10+2,30,5,5); //has size 5+1
rect(10+1,39,6,6); //has size 6+1
rect(10,49,7,7); //has size 7+1
//
noStroke();
fill(0,0,0);
rect(20,4,1,1); //has size 1
rect(20,9,2,2); //has size 2
rect(20,15,3,3); //has size 3
rect(20,22,4,4); //has size 4
rect(20,30,5,5); //has size 5
rect(20,39,6,6); //has size 6
rect(20,49,7,7); //has size 7
//
//
stroke(100,100,100);
strokeWeight(2);
fill(0,0,0);
rect(30-6,4,1,1); //has size 1+2
rect(30-5,9,2,2); //has size 2+2
rect(30-4,15,3,3); //has size 3+2
rect(30-3,22,4,4); //has size 4+2
rect(30-2,30,5,5); //has size 5+2
rect(30-1,39,6,6); //has size 6+2
rect(30,49,7,7); //has size 7+2
//
stroke(100,100,100);
strokeWeight(3);
fill(0,0,0);
rect(41-12,4,1,1); //has size 1+3
rect(41-10,9,2,2); //has size 2+3
rect(41-8,15,3,3); //has size 3+3
rect(41-6,22,4,4); //has size 4+3
rect(41-4,30,5,5); //has size 5+3
rect(41-2,39,6,6); //has size 6+3
rect(41,49,7,7); //has size 7+3
//
}//draw()
1