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
What you want are callbacks:
Here’s a simple implementation of animated drawings of circles and lines:
And here’s a working (webkit only) demo: http://jsfiddle.net/QSAyw/3/