nolachrymose
07-14-2002, 10:18 PM
Right now I'm concentrating on line and shape algorithms, and am not getting far as usual :o. I figured I should start with the easiest and move to the harder - thus, I am starting with the line. I can't even get that working!
Problem is, I don't get any errors - I just get a blank page. My guess is that my algorithm is flawed, but I don't see how. Any help is greatly appreciated. Code is below.
<html>
<head>
<title>Line Algorithm</title>
<script type="text/javascript">
function putpixel(x,y,col) {
var newDiv=document.createElement("div");
newDiv.setAttribute("style","width: 1; height: 10;");
newDiv.style.left=x; newDiv.style.top=y; newDiv.style.backgroundColor=col;
document.body.appendChild(newDiv);
}
function Line(x1,y,x2,col) {
var pointBetween=Math.abs(x1-x2);
while(pointBetween>0) {
putpixel(x1++,y,col);
pointBetween--;
}
}
function init() { Line(20,20,60,"blue"); }
</script>
</head>
<body onload="init();">
</body>
</html>
Problem is, I don't get any errors - I just get a blank page. My guess is that my algorithm is flawed, but I don't see how. Any help is greatly appreciated. Code is below.
<html>
<head>
<title>Line Algorithm</title>
<script type="text/javascript">
function putpixel(x,y,col) {
var newDiv=document.createElement("div");
newDiv.setAttribute("style","width: 1; height: 10;");
newDiv.style.left=x; newDiv.style.top=y; newDiv.style.backgroundColor=col;
document.body.appendChild(newDiv);
}
function Line(x1,y,x2,col) {
var pointBetween=Math.abs(x1-x2);
while(pointBetween>0) {
putpixel(x1++,y,col);
pointBetween--;
}
}
function init() { Line(20,20,60,"blue"); }
</script>
</head>
<body onload="init();">
</body>
</html>