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

182
Vistas
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
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