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

163
Visualizações
Trying to fill the diamond I drew on my JavaScript file with a color but it comes back black

I'm very new to coding and have no idea what I'm doing. I created a diamond in my canvas in the JS file, using the "+c+" but it keeps coming back black. Any help would be much appreciated, it's driving me crazy.

const ctx = document.querySelector("canvas").getContext('2d')
const w = 200
const h = 200

diamond(w / 2, h / 2, 50, 50, 260, 0.5);

function diamond(x, y, w, h, c, a) {
  x = x - w / 2;
  y = y - h / 2;
  ctx.beginPath();
  ctx.moveTo(x, y);
  ctx.lineTo(x + w, y + h);
  ctx.lineTo(x, y + h * 2);
  ctx.lineTo(x - w, y + h);
  ctx.lineTo(x, y);
  ctx.fillStyle = "hsal(" + c + ", 100%, 50%, " + a + ")";
  ctx.fill();
}
<canvas width="200" height="200"></canvas>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This:

ctx.fillStyle = "hsal(" + c + ", 100%, 50%, " + a + ")";

Should be changed into:

ctx.fillStyle = "hsl(" + c + ", 100%, 50%, " + a + ")";

From what I can tell your color doesn't have a value and your diamond shows as black.

Edited as an answer

about 4 years ago · Juan Pablo Isaza Relatório
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