The p5.js line() function does not seem to be able to draw a true 1-pixel wide black line. (Or any other color.)
strokeWeight
is 1 pixel, but the resulting line is 2 pixels wide.color
is black with no transparency, but the resulting color is gray.
blendMode()
seems to have something to do with the funny results above. I tried REPLACE
, but it didn't have the effect I expected. (Only the last shape seems to survive?)
How can I draw a 1-pixel wide line in p5.js with the "true" stroke color? Is this a limitation of the underlying canvas
element?
A simple p5.js demo is included in the snippet below. This problem can also be seen in official p5.js examples:
- No Loop (Should be white line on black background.)
- strokeWeight() (All lines should be black.)
function setup() {
createCanvas(400, 100);
background(200);
stroke(0,0,0, 255); // Black color, no transparancy.
strokeWeight(1); // Default
line(20, 20, 380, 20);
strokeWeight(2); // 2
line(20, 40, 380, 40);
strokeWeight(4); // Thicker
line(20, 60, 380, 60);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/p5.min.js"></script>
Zoom in and verify pixels/colors with color picker: <input type=color>