-- -- demo\rosetta\Forest_fire.exw -- include pGUI.e Ihandle dlg, canvas, hTimer cdCanvas cddbuffer, cdcanvas constant TITLE = "Forest Fire" sequence f = {} -- the forest atom P = 0.03 -- probability of new tree growing atom F = 0.00003 -- probability of new fire starting enum EMPTY,TREE,FIRE -- (1,2,3) constant colours = {CD_BLACK,CD_GREEN,CD_YELLOW} function randomf() return rand(1000000)/1000000 -- returns 0.000001..1.000000 end function function redraw_cb(Ihandle /*ih*/, integer /*posx*/, integer /*posy*/) integer {w, h} = IupGetIntInt(canvas, "DRAWSIZE") cdCanvasActivate(cddbuffer) if length(f)!=w+2 or length(f[1])!=h+2 then f = sq_rand(repeat(repeat(2,h+2),w+2)) -- (EMPTY or TREE) end if sequence fn = f for x = 2 to w+1 do for y = 2 to h+1 do integer fnxy switch f[x,y] do case EMPTY: fnxy = EMPTY+(randomf()