Log In  

Cart #41917 | 2017-06-24 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
3

While working on my 3d engine I've written a function that I think would be generally useful and I haven't seen it done before. It draws horizontal dithered lines such that odd and even rows have an alternating checkerboard pattern. Code is obviously in the cart but I post below as well.

The code runs just as fast the native LINE function but with the bonus of optional dithered-e-ness

function dither(sx,ex,y,draw_colour,shade_colour)
  if (sx<0 and ex<0) or (sx>127 and ex>127) then return end
  sx = max(0,min(sx,127))
     ex = max(0,min(ex,127))
     if ex < sx then
      sx,ex = ex,sx
     end
     local sos = sx % 2
     local eos = ex % 2
     local yind = y*64+0x6000
     local ctu = -1
     if y%2 == 0 then
      ctu = draw_colour
     else
      ctu = shade_colour
     end

      if sos == 1 then
       sx -= 1     
       poke(yind+sx/2, bor(band(peek(yind+sx/2),0x0f), band(0xf0,ctu)))    
       sx += 2
      end 

      if eos == 0 then            
       poke(yind+flr(ex/2), bor(band(peek(yind+ex/2),0xf0),band(0x0f, ctu)))
       ex -= 1
      end

      memset(yind +sx/2,ctu, (ex/2-sx/2)+1)
end

The tricky bit being to deal with the start and end of the line when they do no perfectly align with the byte boundaries.

P#41918 2017-06-24 17:38 ( Edited 2017-06-24 21:39)


[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-06-04 06:09 | 0.015s | 4194k | Q:24