In my code, I want to draw a line. For that I am putting points according to the equation of line. And I also want delay of 100 milliSec before next point is printed. So, I used setTimeout(). But when I run this code, first it waits for some time and then prints all the point at a time without delay of 100ms. Here is my code for drawing line:
function drawLine(x1, y1,x2,y2){
var x, y, m;
m=(y2-y1)/(x2-x1);
for(x=x1;x<=x2;x++){
y=(m*(x-x1)+y1)/6;
setTimeout(drawPoint,100,x,y);
}
}
function drawPoint(a,b){
main=document.getElementById("main"); //parent div tag in which children div tags are to be appended
var children=main.childNodes;
var child=document.createElement("div");
child.className="anime";
child.style.left=a+"px";
child.style.top=300-b+"px"; //300 is some offset
main.appendChild(child);
}
Any help will highly be appreciated.