Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6913243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:11:36+00:00 2026-05-27T09:11:36+00:00

I was trying to do an Olympic type flag, purely as a way of

  • 0

I was trying to do an Olympic type flag, purely as a way of learning how to draw in JavaScript. This should draw two circles – one blue, one black…
Here is the code (which I apologise for, been moving things between the two functions – Not sure how to refer to the context non-explicitly):

function drawCircle(ctx,x,y,radius, color){
  var startAngle = 0;
  var endAngle = (Math.PI*2);
  var clockwise = true;
  ctx.fillStyle = color;
  ctx.arc(x,y,radius,startAngle,endAngle, clockwise);
  ctx.fill();
  ctx.closePath;
}
function drawCircles(){
    var canvas = document.getElementById('myCanvasArea');  
    var ctx = canvas.getContext('2d'); 
     if (canvas.getContext){    
        drawCircle(ctx,50,25,25, 'blue');
        drawCircle(ctx,100,25,25, 'black');
    }
}

I get two black circles. I presume I’m not differentiating between the two shapes, therefore the properties of the 2nd are applied to the 1st.

How do I make that distinction? I was thinking of making clicking each one raise an action. Am I going about this incorrectly from the start?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:11:37+00:00Added an answer on May 27, 2026 at 9:11 am

    It’s because you are never calling beginPath()!

    function drawCircle(ctx,x,y,radius, color){
      var startAngle = 0;
      var endAngle = (Math.PI*2);
      var clockwise = true;
      ctx.fillStyle = color;
      ctx.beginPath(); // <-- Need me!!
      ctx.arc(x,y,radius,startAngle,endAngle, clockwise);
      ctx.fill();
      ctx.closePath;
    }
    

    Since you don’t call beginPath, you are drawing one blue circle, then you are continuing a path that now has two circles (the old one and the new one), and drawing that path (and thus both circles) black!

    Instead you want to draw one blue circle, fill it blue, begin a new path, and draw that one black.

    Live code:

    http://jsfiddle.net/5PDUb/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to implement a MSMQ-backed WCF PubSub. I understand that net.msmq is one-way; however
trying to fade these images in sequentially (one after the other) after they're grabbed
Trying to get my css / C# functions to look like this: body {
Trying to keep all the presentation stuff in the xhtml on this project and
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
Trying to do this, but is it wrong? Below is my style and script
Trying to find some information on this but am unable to get any results
Trying to come up with a succinct way to create a named query with
Trying to launch and pass tel. no. to skype by this code from my
Trying to get this query to work. I'm having issues with brackets I think.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.