Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda