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

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

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