Posted: 3rd Jan 2004 21:08
I played for two days (hmm.. not really, I've done other things : I slept, ate, went shopping, and used the toilets) with the memblocks.. I wrote several functions that I may use in a game I'm going to do (no, I won't tell you that it's a bomberman ^^)
I always say that one should share as often as possible, so here you are

+ Code Snippet
rem memblock number, size x, size y
function m_bitmap(m, tx as integer, ty as integer)
   make memblock m,12+tx*ty*4
   write memblock dword m, 0, tx
   write memblock dword m, 4, ty
   write memblock dword m, 8, 32
endfunction

rem memblock, position x, position y, rgb color
function m_dot(m, x as integer, y as integer, c as dword)
   sizex = memblock byte(m,0)+256*memblock byte(1,1)
   sizey = memblock byte(m,4)+256*memblock byte(1,5)
   if x>-1 and x<sizex
      if y>-1 and y<sizey
         n as double integer
         n = (4*((y*sizex)+x))+12
         write memblock dword m,n,c
      endif
   endif
endfunction

rem memblock, position x, position y
function m_point(m,x as integer,y as integer)
   sizex = memblock byte(m,0)+256*memblock byte(1,1)
   sizey = memblock byte(m,4)+256*memblock byte(1,5)
   if x>-1 and x<sizex
      if y>-1 and y<sizey
         n as double integer
         c as dword
         n = (4*((y*sizex)+x))+12
         c = rgb(memblock byte(m,n+2),memblock byte(m,n+1),memblock byte(m,n))
      endif
   endif
endfunction c

rem memblock, start x, start y, end x, end y, color
function m_line(m, xa as float, ya as float, xb as float, yb as float, c as dword)
   pente as float
   y as float
   pente = (yb-ya)/(xb-xa)
   if xb>xa then xs=xa: xe=xb: y=ya else xs=xb: xe=xa: y=yb
   dec y,pente
   if pente<>0
      for x=xs to xe
         y = y+pente
         m_dot(m,x,y,c)
      next x
   else
      if xb<>xa
         for x=xs to xe
            m_dot(m,x,y,c)
         next x
      else
         if yb<>ya
            if yb>ya then ys=ya: ye=yb else ys=yb: ye=ya
            for y=100.0 to 150.0
               m_dot(m,20,y,c)
            next y
         endif
      endif
   endif
endfunction

rem memblock, start x, start y, end x, end y, first rgb color, second rgb color
function m_line_degrade(m, xa as float, ya as float, xb as float, yb as float, ca as dword, cb as dword)
   pente as float
   y as float
   r as float
   g as float
   b as float
   dr as float
   dg as float
   db as float
   dist as float
   pente = (yb-ya)/(xb-xa)
   if xb>xa then xs=xa: xe=xb: y=ya else xs=xb: xe=xa: y=yb
   dec y,pente
   if xa<>xb then dist = abs(xa-xb) else dist = abs(ya-yb)
   dr = (rgbr(cb)-rgbr(ca))/dist
   dg = (rgbg(cb)-rgbg(ca))/dist
   db = (rgbb(cb)-rgbb(ca))/dist
   r = rgbr(ca)
   g = rgbg(ca)
   b = rgbb(ca)
   if pente<>0
      for x=xs to xe
         y = y+pente
         m_dot(m,x,y,rgb(r,g,b))
         inc r,dr
         inc g,dg
         inc b,db
      next x
   else
      if xb<>xa
         for x=xs to xe
            m_dot(m,x,y,rgb(r,g,b))
            inc r,dr
            inc g,dg
            inc b,db
         next x
      else
         if yb<>ya
            if yb>ya then ys=ya: ye=yb else ys=yb: ye=ya
            for y=100.0 to 150.0
               m_dot(m,20,y,rgb(r,g,b))
               inc r,dr
               inc g,dg
               inc b,db
            next y
         endif
      endif
   endif
endfunction

rem memblock, center x, center y, radius (! not diameter !), rgb color
function m_cercle(m, xc as float, yc as float, r as float, c as dword)
   x as float
   y as float
   for y=yc-r to yc+r
      for x=xc-sqrt(r^2-abs(y-yc)^2) to xc+sqrt(r^2-abs(y-yc)^2)
         m_dot(m, x,y,c)
      next x
   next y
endfunction

rem memblock, center x, center y, radius (!...!), rgb color center, rgb color border
function m_cercle_degrade(m, xc as float, yc as float, r as float, cc as dword, ce as dword)
   x as float
   y as float
   dr as float
   dg as float
   db as float
   dr = (rgbr(ce)-rgbr(cc)) / r
   dg = (rgbg(ce)-rgbg(cc)) / r
   db = ((rgbb(ce)-rgbb(cc)) / r)
   for y=yc-r to yc+r
      for x=xc-sqrt(r^2-abs(y-yc)^2) to xc+sqrt(r^2-abs(y-yc)^2)
         m_dot(m, x,y,rgb(rgbr(cc)+dr*sqrt((x-xc)^2 + (y-yc)^2),rgbg(cc)+dg*sqrt((x-xc)^2 + (y-yc)^2),rgbb(cc)+db*sqrt((x-xc)^2 + (y-yc)^2)))
      next x
   next y
endfunction


hmm.. I didn't translate the functions names, but I'm sure you'll understand what they do
if you've never used the memblocks, don't worry, it isn't very hard.. to test my code, here's an example
(you need the functions above !)

+ Code Snippet
rem the size of the bitmap... you're allowed to change it if you don't like them, but who wouldn't like 256*256 pixels ?!
tx = 256
ty = 256
rem building the bitmap
m_bitmap(1,tx,ty)
rem making the bitmap a bit grey...
for x=0 to tx
   for y=0 to tx
      m_dot(1,x,y,rgb(10,10,10))
   next y
next x
rem a lovely line :)
m_line_degrade(1,0,0,256,256,rgb(0,255,150),rgb(255,0,0))
rem doesn't the circle look like a 3d object ?
m_cercle_degrade(1,100,100,50,rgb(255,0,255),rgb(0,0,0))

rem then, we make a bitmap from the memblock, and get an image :)
make bitmap from memblock 1,1
set current bitmap 1
get image 1,0,0,bitmap width(1),bitmap height(1)
set current bitmap 0

rem ...displaying the results...
do
   cls
   paste image 1,5,5
   set cursor 0,bitmap height(1)+5
   print "{",mousex()," ",mousey(),"}"
   print "RGB(",rgbr(point(mousex(),mousey()))," ",rgbg(point(mousex(),mousey()))," ",rgbb(point(mousex(),mousey())),")"
   sync
loop