type Constants
   ScreenWidth as word
   ScreenHeight as word
endtype
 
Global System as Constants
System.ScreenWidth = 320
System.ScreenHeight = 120
 
Global flame as float
flame = 4.02
 
sync on
backdrop on
color backdrop 0
 
make memblock 1, System.ScreenWidth*System.ScreenHeight*4 + 12
write memblock dword 1,0,System.ScreenWidth
write memblock dword 1,4,System.ScreenHeight
write memblock dword 1,8,32
 
 
 
REM get the image's width and height
width = memblock dword(1,0)
height = memblock dword(1,4)
 
REM create a new image from the memblock data
make image from memblock 3, 1
 
REM display the new image
repeat
 
 
   for y = 1 to System.Screenheight
      for x = 1 to System.ScreenWidth
         if y < System.ScreenHeight
            changePixel(x,y,newValue(x,y))
         else
            r = rnd(255)
            g = rnd(255)
            if g>r then g = r
            changePixel(x,System.ScreenHeight,rgb(r,g,0))
         endif
      next x
   next y
 
   make image from memblock 3, 1
 
 
 
   sprite 2,mousex(), mousey(), 3
 
   set cursor 0,0
   print screen fps()
 
   fastsync
until spacekey()
 
 
 
 
function getColor(x as integer, y as integer)
   if x < 1 or x > System.ScreenWidth or y < 1 or y > System.ScreenHeight then exitfunction rgb(0,0,0)
   mem = 1
   pos = ((y-1)*System.ScreenWidth + x - 1)*4 + 12
   c as dword
   c = memblock dword(mem, pos)
endfunction c
 
 
 
function changePixel(x as integer, y as integer, color as dword)
   if x > 0 and x <= System.ScreenWidth and y > 0 and y <= System.Screenheight
      mem = 1
      pos = ((y-1)*System.ScreenWidth + x - 1)*4 + 12
      write memblock dword mem, pos, color
   endif
endfunction
 
 
 
function newValue(x as integer, y as integer)
   local c as dword
   local r as integer
   local g as integer
   local b as integer
 
   c = getColor(x,y+1)
   r = rgbr(c)
   g = rgbg(c)
   b = rgbb(c)
   c = getColor(x-1,y+1)
   r = r + rgbr(c)
   g = g + rgbg(c)
   b = b + rgbb(c)
   c = getColor(x+1,y+1)
   r = r + rgbr(c)
   g = g + rgbg(c)
   b = b + rgbb(c)
   c = getColor(x,y+2)
   r = r + rgbr(c)
   g = g + rgbg(c)
   b = b + rgbb(c)
 
   r = r/flame
   g = g/flame
   b = b/flame
 
   c = rgb(r,g,b)
endfunction c