-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
strokeWeight(1) appears as 2 pixels for a rectangle. #7319
Comments
@perminder-17 Also, the stroke width problem is the same with line(). |
Thanks for filing an issue! The issue, I think, is that lines are centered about the vertices of the rectangle. If you have a 2px wide line, and a vertex is at an integer, then the left and the right side of the line is also at an integer (±1). If you have a 1px wide line, then the edges of the line will both be halfway through a pixel (±0.5), so antialiasing causes it to show up on both pixels, with around half opacity. The key thing here is to take into account the positioning of lines if you want pixel-precision strokes. Here are two lines, one adjusted so the edges of the stroke are not halfway across a pixel, and the other is misaligned, causing the effect you see: function setup() {
createCanvas(400, 400)
pixelDensity(1)
background(200)
line(100.5, 0, 100.5, 400)
line(300, 0, 300, 400)
}
Antialiasing of lines is a fundamental aspect of the underlying 2D JavaScript canvas that we can't turn off. For this reason, we aren't currently planning to do any workarounds to match how a non-JavaScript-canvas renderer might look. |
Most appropriate sub-area of p5.js?
p5.js version
1.10
Web browser and version
Firefox 131 on Windows, Chrome 130 on Linux and Windows
Operating system
Windows, Linux
Steps to reproduce this
Steps:
Snippet:
The text was updated successfully, but these errors were encountered: