Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
How to get true 1-pixel width black color line in p5.js

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>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!