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 9136769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:59:48+00:00 2026-06-17T08:59:48+00:00

I am working to create an animation which draws a canvas like O –

  • 0

I am working to create an animation which draws a canvas like “O – O” shape.
The animation should first animate to draw the circle on the left, then the right circle and finally the connection in between.

I am able to draw a circle but I would like to know how can I draw the three elements one by one instead of drawing three of them together.

Psuedo-code:

window.onload = draw;

function draw(){
drawcircle();
}

function drawcircle(){
draw part of circle
if( finish drawing){
clearTimeout
}
else{
setTimeout(drawcircle());
}

However, if I run another drawcircle function after first in the draw() function. Both circles are drawn at the same time instead of one by one. Is there any method to draw each elements one by one?
Thanks very much

  • 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-06-17T08:59:48+00:00Added an answer on June 17, 2026 at 8:59 am

    What you want are callbacks:

    Circle(ctx, 50, 50, 25, 1000, function () {       // animate drawing a circle
      Circle(ctx, 150, 50, 25, 1000, function () {    // then animate drawing a circle
        Line(ctx, 75, 50, 125, 50, 1000, function(){  // then animate drawing a line
          alert('done');
        });
      });
    });
    

    Here’s a simple implementation of animated drawings of circles and lines:

    function Circle(context, x, y, radius, dur, callback) {
      var start = new Date().getTime(),
          end = start + dur,
          cur = 0;
    
      (function draw() {
        var now = new Date().getTime(),
            next = 2 * Math.PI * (now-start)/dur;
    
        ctx.beginPath();
        ctx.arc(x, y, radius, cur, next);
        cur = Math.floor(next*100)/100; // helps to prevent gaps
        ctx.stroke();
    
        if (cur < 2 * Math.PI) requestAnimationFrame(draw);  // use a shim where applicable
        else if (typeof callback === "function") callback();
      })();
    }
    
    function Line(context, x1, y1, x2, y2, dur, callback) {
      var start = new Date().getTime(),
          end = start + dur,
          dis = Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2)),
          ang = Math.atan2(y2-y1, x2-x1),
          cur = 0;
    
      (function draw() {
        var now = new Date().getTime(),
            next = Math.min(dis * (now-start)/dur, dis);
    
        ctx.beginPath();
        ctx.moveTo(x1 + Math.cos(ang) * cur, y1 + Math.sin(ang) * cur);
        ctx.lineTo(x1 + Math.cos(ang) * next, y1 + Math.sin(ang) * next);
        cur = next;
        ctx.closePath();
        ctx.stroke();
    
        if (cur < dis) requestAnimationFrame(draw);  // use a shim where applicable.
        else if (typeof callback === "function") callback();
      })();
    }
    

    And here’s a working (webkit only) demo: http://jsfiddle.net/QSAyw/3/

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

Sidebar

Related Questions

I am trying to create an animation in which a circle will be containing
Hello I would like to create a zoom like animation on my page which
I am working to create an app in which there are multiple stages- in
im trying to create ball animation using gdi but i can't get it working.
Code: //create the animation. $('img#header').hover(function(){ $(this).animate({top: -10px }, slow); I am trying to have
My objective is to create a generic function for animation which would require to
I'm working on a project which should have a progressdialog. But since i didn't
I'm trying to create an animation that would look like 2 french doors (or
I've created custom toggle slide animation. Its working fine as expected but its not
I'm working to create an java web apps using Struts and a Cassandra DB.

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.