Re: xor_line
- Posted by jiri babor <jbabor at PARADISE.NET.NZ> Oct 25, 1998
- 501 views
Sorry, Hawke, I should not rely on my memory that much, it's like a sieve. I just checked the archive version of rat.e, and you are right, the xor library is not there. I completely forgot I had not released the complete widget set with the ratpack, just a cut-down version, in other words only the routines necessary for the demo (I think, Irv had already been pushing his 'windoz', and I did not want to create unfair competition). If you still want to compare notes, or for anybody else possibly interested, the routine is attached below. Sorry again, but I told you to give me a yell, if you strike a problem..jiri global procedure xor_line(integer c, sequence p) -- c is line color - same usage as draw_line, but limited -- to single line segment between 2 points in sequence p integer ai,bi,d,x,y,x2,y2,xi,yi,dx,dy p=floor(p) x=p[1][1] x2=p[2][1] y=p[1][2] y2=p[2][2] if y=y2 then -- horizontal line if x<x2 then pixel(xor_bits(get_pixel({x,y,x2-x+1}),repeat(c,x2-x+1)),{x,y}) else end if elsif x=x2 then -- vertical line if y<y2 then for i=y to y2 do pixel(xor_bits(get_pixel({x,i}),c),{x,i}) end for else for i=y2 to y do pixel(xor_bits(get_pixel({x,i}),c),{x,i}) end for end if else if x<x2 then xi=1 dx=x2-x else xi=-1 dx=x-x2 end if if y<y2 then yi=1 dy=y2-y else yi=-1 dy=y-y2 end if pixel(xor_bits(get_pixel({x,y}),c),{x,y}) if dx>dy then ai=2*(dy-dx) bi=2*dy d=bi-dx while x!=x2 do if d>=0 then y=y+yi d=d+ai else d=d+bi end if x=x+xi pixel(xor_bits(get_pixel({x,y}),c),{x,y}) end while else ai=2*(dx-dy) bi=2*dx d=bi-dy while y!=y2 do if d>=0 then x=x+xi d=d+ai else d=d+bi end if y=y+yi pixel(xor_bits(get_pixel({x,y}),c),{x,y}) end while end if end if end procedure -- xor_line global procedure xor_draw_line(integer c, sequence p) -- same usage as draw_line: c is line color, p is sequence of -- points ({x,y} coordinates) to be connected -- works ok for single line segments, but xor_line() above is faster for i=1 to length(p)-1 do xor_line(c,p[i..i+1]) end for -- compensate for cancellations at line joints for i=2 to length(p)-1 do pixel(xor_bits(get_pixel(p[i]),c),p[i]) end for -- compensate for cancellation at closure for line loops if not compare(p[1],p[length(p)]) then pixel(xor_bits(get_pixel(p[1]),c),p[1]) end if end procedure -----Original Message----- From: Hawke <mdeland at NWINFO.NET> To: EUPHORIA at LISTSERV.MUOHIO.EDU <EUPHORIA at LISTSERV.MUOHIO.EDU> Date: Sunday, October 25, 1998 3:03 PM Subject: Re: truecolr.e update, line(), other stuff... >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' >