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

132
Views
Drawing a Grid With Canvas / Line Width Creating Black Box

I'm trying to create a JS Function (nodeJS) that takes in width, height, padding (size of each square) and line width. I'd like to fit the grid perfectly into the provided width and height. Right now, it's not working.

When I put in the line width, it gives me a black box. When it's gone, it prints out a grid.

    let left = 0;
    let top = 0;
    let bottom = canvas.height;
    let right = canvas.width;

    ctx.lineWidth = lineWidth;
    ctx.beginPath();
    for (let x=left; x<right; x+=padding) {
        ctx.moveTo(x, top);
        ctx.lineTo(x, bottom);
    }

    for (let y=top; y<bottom; y+=padding) {
        ctx.moveTo(left, y);
        ctx.lineTo(right, y);
    }

    ctx.strokeStyle = "#000000";
    ctx.stroke();

Any help would be appreciated. Thanks.

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!