Set Display Mode 640, 480, 32
Sync On
SYnc rate 60
 
Type pixel
	loc as integer
	col as DWORD
	R as integer
	G As integer
	B As integer
endtype
 
PrevX As pixel
PrevY As pixel
Current As pixel
 
Make Memblock 1, 640*480*4
 
mem_point = get memblock ptr(1)
 
Write Memblock Dword 1, 0, RGB(255,0,0)
Write Memblock Dword 1, 100*640*4, RGB(0,255,0)
Write Memblock Dword 1, 100*4, RGB(0,0,255)
 
 
While 1
	inc Timesgoneby, 1
	For y = 479 To 0 Step -1
		For x = 639 To 0 Step -1
			If x <> 0
				prevx.loc = (y*640+(x-1))*4
				prevx.col = Memblock Dword(1,prevx.loc)
				prevx.R = RGBR(prevx.col)
				prevx.G = RGBG(prevx.col)
				prevx.B = RGBB(prevx.col)			
			Else
				prevx.R = 0
				prevx.G = 0
				prevx.B = 0				
			Endif
 
			if y <> 0
				prevy.loc = ((y-1)*640+x)*4
				prevy.col = Memblock Dword(1,prevy.loc)
				prevy.R = RGBR(prevy.col)
				prevy.G = RGBG(prevy.col)
				prevy.B = RGBB(prevy.col)
			Else
				prevy.R = 0
				prevy.G = 0
				prevy.B = 0
			Endif
 
			current.loc = (y*640+x)*4
			current.col = Memblock Dword(1,current.loc)
			current.R = RGBR(current.col)
			current.G = RGBG(current.col)
			current.B = RGBB(current.col)
 
			If current.R < prevx.R Then inc current.R,RND(prevx.R-current.R): if current.R > 255 Then current.R = 255
			If current.R < prevy.R THen inc current.R,RND(prevy.R-current.R): if current.R > 255 Then current.R = 255
			If current.G < prevx.G Then inc current.G,RND(prevx.G-current.G): if current.G > 255 Then current.G = 255
			If current.G < prevy.G THen inc current.G,RND(prevy.G-current.G): if current.G > 255 Then current.G = 255
			If current.B < prevx.B Then inc current.B,RND(prevx.B-current.B): if current.B > 255 Then current.B = 255
			If current.B < prevy.B THen inc current.B,RND(prevy.B-current.B): if current.B > 255 Then current.B = 255
 
			current.col = RGB(current.R, current.G,current.B)
			Write Memblock Dword 1, current.loc, current.col
 
		next x
	next y
 
	lock pixels
   copy memory get pixels pointer(), mem_point, 640*480*4
   unlock pixels
 
	Text 600,460,str$(TimesGoneBy)
	Sync
endwhile