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

179
Views
Is there any way to create a line using fillRect in JS(canvas)

I am trying a tutorial from YouTube, and when I use the following snippet, it creates a dot/pixel in the canvas. I can recreate the function multiple times with different values to create a line, but is it possible to create a straight line using the following code?

Apologies for simple question, I'm pretty new in using canvas. Thanks

let tileCount = 20;   //total tiles = 20. or you can say pixels body
let tileSize = canvas.width / tileCount - 2;

let appleX = 5;
let appleY = 5;

function drawApple() {     //craetes the food item for snake to collide
    ctx.fillStyle = "red";   //color of apple
    ctx.fillRect(appleX * tileCount, appleY * tileCount, tileSize, tileSize);   //defining apple as rectangle
}
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!