My goal is to create a line in my code by placing points according to the line equation and adding a 100 millisecond delay before each point is displayed. However, when I try to run the code, it seems to wait for some time and then displays all the points at once without the desired delay.
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");
var children=main.childNodes;
var child=document.createElement("div");
child.className="anime";
child.style.left=a+"px";
child.style.top=300-b+"px";
main.appendChild(child);
}
If anyone has any suggestions or solutions, they would be greatly appreciated.