Web Analytics Made Easy -
StatCounter Line Algorithm - CodingForum

Announcement

Collapse
No announcement yet.

Line Algorithm

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Line Algorithm

    Right now I'm concentrating on line and shape algorithms, and am not getting far as usual . 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.

    Code:
    <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>

  • #2
    Not an answer, but have you ever considered SVG?

    <line x1="0" y1="0" x2="1" y2="1"/>

    Is all that is needed to create a line with equation:

    y = x;

    jasonkarldavis.com

    Comment


    • #3
      I haven't thought of that yet. I'm actually better aquainted with VML, but I guess I could give SVG a shot.

      Thanks!

      Happy coding!

      Comment


      • #4
        Originally posted by nolachrymose
        I'm actually better aquainted with VML
        *pfft* VML - I personally don't see it uses anymore. Whatever you can accomplish with VML can be done (and more so with SVG), and SVG is a W3C standard, and the excellent Adobe SVG plugin exists.
        (Not to mention Mozilla has a decent amount of native SVG support ).
        jasonkarldavis.com

        Comment

        Working...
        X