Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda