This has been done often using layers, but I can't use those scripts because I want the line's pixels not to be layers but 1 by 1 pixel table cells. This is so that I can animate the table more easily. I know I could use nested layers but most graphics libs out there won't let me do that without me going through their impossible to comprehend code. And plus I like tables.
Here is my code, based upon the idea that at each y-value (table row) those colums that fit the equation y-y1=m(x-x1) will be drawn.
Can anybody tell me why this produces some VERY strange results (usually nothing at all)? It doesn't seem to throw an error so I have no idea what the problem is! Could somebody please help me?
Here is my code, based upon the idea that at each y-value (table row) those colums that fit the equation y-y1=m(x-x1) will be drawn.
Code:
function renderLine(x1,y1,x2,y2) {
line_color="#000000";
element=document.getElementById("tableLayer");
m=(y2-y1)/(x2-x1);
data="<table cols='"+Math.abs(x2-x1)+"' cellpadding='0' cellspacing='0' border='0'>";
for(y=0;y<Math.abs(y2-y1);y++) {
data+="<tr>";
for(x=0;x<Math.abs(x2-x1);x++) {
data+="<td width='1' height='1'";
yv=m*(x-x1)+y1;
if(y==Math.round(yv)) data+=" bgcolor='"+rrColor+"'";
data+=" nowrap></td>"; }
data+="</tr>"; }
data+="</table>";
element.innerHTML=data; }
Comment