1. truecolr.e update, line(), other stuff...
- Posted by Hawke <mdeland at NWINFO.NET> Oct 22, 1998
- 430 views
if anyone is working with the truecolor library that was originally made by chris street, that i updated recently, then please note that i found a rather nasty bug in the line drawing routines... heh... they don't work right for all manner of lines, but work fine for vertical & horizontal lines. the diagonal directions are rather fubar. anyone wanting/needing the latest version, or anyone wishing to place it upon a web page, please email me and i'll get it to you asap. lastly, these new line routines are probably not in their final form, per say. there are two reasons I say this... the first is that there is a tiny rounding 'error' that creeps in for a few specific angles of lines that leaves tiny gaps in the lines; and secondly, even though i've done a fair amount of optimizing for the drawing of diagonal lines, i'm gonna try to squeeze a little more speed out of the routines. from where i'll get this increase, and how in the world i'll fix the rounding 'error' i really don't know--heh. i was using arctan to plot the points, but that is what messed up the routines, because the endpoint wasn't actually at the end of the line. I would like to see anyone's algorithms that plot *diagonal* lines (horizontal and vertical are handily dealt with already) given the following: 1>the start and end points of the line can be anywhere on the screen (allowing backwards diagonal lines to be drawn) 2>you only have 'pixel()' and math functions at your disposal. 3>you needn't worry about points falling off the screen as 'pixel()' (in this discussion) will quietly ignore out-of-bound numbers. 4>the function accepts 5 parameters: function line(integer sx,integer sy, integer ex,integer ey, integer clr) --sx=startX; sy=startY; ex=endX; ey=endY 5>the pixel() function behaves like the builtin function to EU (but, before anyone says it, remember that we cannot use the builtin 'line()' cuz this is for a set of screen modes that EU's line() cannot plot to, and the pixel() function actually being used is called 'true_pixel()' & accepts sequences for clr...) 6>the algorithm you submit should be tested and correct, of course :) with all that said, here is my attempt: procedure line( integer sx, integer sy, integer ex, integer ey, integer clr) integer dx --distanceX atom delta,rise --delta is the change of Y per change of X --is it horizontal? if sy=ey then --blahblahblah --or is it vertical? elsif sx=ex then --blahblahblah --ok, it must be diagonal in some form or fashion... else dx=ex-sx delta=(ey-sy) / abs(dx) rise=sy --convert integer to real (ergo:atom) if dx>0 then for run = sx to ex do pixel({run,round(rise)},clr) rise=rise + delta end for else for run = sx to ex by -1 do pixel({run,round(rise)},clr) --use round() *here* --don't wanna use round() below, we lose precision... rise=rise + delta end for end if end if end procedure now you may note the use of round() within the pixel() call, and abs()... for completeness sake, abs() is the one proffered by (i believe) carl on the listserv a while back, and round() is the following: function round(object num) object temp,flr if integer(num) then return num end if flr =floor(num) temp=floor((num-flr) * 10) return flr + (temp>=5) --see carl? i'm learning :) end function so, after reading all that dribble, anyone feel like putting on a thinking cap? :) take care, and care of--Hawke'
2. Re: truecolr.e update, line(), other stuff...
- Posted by jiri babor <jbabor at PARADISE.NET.NZ> Oct 22, 1998
- 416 views
- Last edited Oct 23, 1998
Hawke wrote: >I would like to see anyone's algorithms that plot >*diagonal* lines (horizontal and vertical are handily >dealt with already) given the following: <bla bla> Go to the Archives and fetch my ratpack (SVGA mouse routines). In it you will find a little library called xor.e. From memory, among other graphic elements it also contains an xor_line routine. It is based on Bresenham's line algorithm, the fastest one known to mankind . Simply replace my xorpixel with your mongrel, and you should be in business within seconds. Give me a yell if you have any problems. But I will be at home, not at work, for the next four or five days, it's Labour weekend over here and I am taking an extra day off to make a decent meal out of it... jiri home: jbabor at paradise.net.nz
3. Re: truecolr.e update, line(), other stuff...
- Posted by Hawke <mdeland at NWINFO.NET> Oct 24, 1998
- 418 views
jiri babor wrote: >Go to the Archives and fetch my ratpack (SVGA mouse routines). >In it you will find a little library called xor.e. >From memory, among other graphic elements it also contains >an xor_line routine. ummm... i looked all thru all the files in rat.zip and i couldn't find xor_line. i looked pretty thoroughly... >It is based on Bresenham's line algorithm, knowing this however, i was able to find that algorithm and implement it (it's pretty quick), so thankee! for the tip... :) --Hawke'