Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Draw a line between 2 points 1

Status
Not open for further replies.

Nebooaw

Programmer
Jun 1, 2001
142
GB
Hi, is is possible to raw a line between two points i.e.

0,0 & 50,75

Kind thanks.

 

Yes. Using JavaScript, the only way I can think of is to write an implementation of Bressenham's line drawing algorithm.

There are a few JS graphic libraries out there which do this already, and I've written one, but don't have the source available right now.

I suuggest searching on Google for "javascript graphics library"... It should turn up at least one of the JS libraries out there.

Hope this helps,
Dan
 
Incidentally, should you fancy writing it yourself, the easiest way to draw a "pixel" in JS is to create an absolutely-positioned DIV, and use CSS to style it, somethinig like this:

Code:
.pixel {
   position: absolute;
   width: 1px;
   height: 1px;
   background-color: #000000;
   overflow: hidden;
}
...
<div class="pixel"></div>

You can set the top and left coordinates accordingly, and override the background colour if you don't want to use black.

Dan
 
yup,
layers are the best way to draw lines...

Known is handfull, Unknown is worldfull
 
i meant divs just that i term them as layers since i used to work a lot in NN 4.7x...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top