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

110
Vistas
HTML JS Circle Drawing Line

I'm trying to draw a ball and a circle around it. I don't know why a line appears in the right side of the ball. I'm using .fill to make the ball and .stroke to make the circle.

function draw() {
  var canvas = document.getElementById('circle');
  if (canvas.getContext) {
    var ctx = canvas.getContext('2d');
    var X = canvas.width / 2;
    var Y = canvas.height / 2;
    var R = 45;

    ctx.beginPath();
    ctx.arc(X, Y, R, 0, 2 * Math.PI, false);
    ctx.lineWidth = 3;
    ctx.fillStyle = "white";
    ctx.fill();
  }
  if (canvas.getContext) {
    var rtx = canvas.getContext('2d');
    var A = canvas.width / 2;
    var B = canvas.width / 2;
    var Ra = 90;

    rtx.arc(A, B, Ra, 0, 2 * Math.PI, false);
    rtx.lineWidth = 2;
    rtx.strokeStyle = "white";
    rtx.stroke();
  }
}
body {
  background-color: rgb(8, 8, 22);
  position: absolute;
  top: 50%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
<body onload="draw()">
  <canvas id="circle" width="1000" height="1000">

    </canvas>
</body>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As you have used ctx.beginPath(); . The same is to be used for rtx also, the white line which is being showed is because you have not used rtx.beginPath(); inside the if block which contains rtx. So just add rtx.beginPath(); one line before rtx.arc(A, B, Ra, 0, 2 * Math.PI, false);

function draw() {
  var canvas = document.getElementById('circle');
  if (canvas.getContext) {
    var ctx = canvas.getContext('2d');
    var X = canvas.width / 2;
    var Y = canvas.height / 2;
    var R = 45;

    ctx.beginPath();
    ctx.arc(X, Y, R, 0, 2 * Math.PI, false);
    ctx.lineWidth = 3;
    ctx.fillStyle = "white";
    ctx.fill();
  }
  if (canvas.getContext) {
    var rtx = canvas.getContext('2d');
    var A = canvas.width / 2;
    var B = canvas.width / 2;
    var Ra = 90;

    rtx.beginPath(); //the line to be added
    rtx.arc(A, B, Ra, 0, 2 * Math.PI, false);
    rtx.lineWidth = 2;
    rtx.strokeStyle = "white";
    rtx.stroke();
  }
}
body {
  background-color: rgb(8, 8, 22);
  position: absolute;
  top: 50%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
<body onload="draw()">
  <canvas id="circle" width="1000" height="1000">

    </canvas>
</body>

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