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

160
Views
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 answers
Answer question

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 Report
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!