Re: snow!
- Posted by jiri babor <jbabor at PARADISE.NET.NZ> Dec 19, 1999
- 498 views
Colin wrote: >>>Hey... How about making us some sunshine? Most of us could use a little. (This should ideally be programmed by somone who has actually _seen_ sunshine, automatically disqualifying many of you BC types, not to mention Jiri...)<<< I thought *you* would be sick of sunshine, moving all the time, as you do, in the cocaine territories. And what do you know, we had a cracker of a Sunday, glorious sunshine all day. Windy Wellington is an anachronic label. But the truth is, those BC boys obviously do not even know their snow. So I decided to teach them a lesson :). It is attached. jiri -- <snip> -- xmas.ex jiri babor 99-12-19 include graphics.e include machine.e constant n=200, textscreen=allocate(64000), foreground=allocate(64000), background=allocate(64000) object o, flake, fallen atom t, et integer r, x, y, frame procedure init() text_color(YELLOW) position(11,16) puts(1, "Merry Xmas") position(13,19) puts(1, "and") position(15,14) puts(1, "Happy New Year") mem_copy(textscreen,#A0000,64000) mem_copy(background,textscreen,64000) for i=1 to n do flake[i]={rand(319), rand(200)-1, rand(3)} -- {x,y,speed} end for end procedure procedure snow() mem_copy(foreground, background, 64000) for i=1 to n do x=flake[i][1] r=rand(20) -- add tumble / jitter if r=1 and x<319 then x+=1 flake[i][1]=x elsif r=11 and x>1 then x-=1 flake[i][1]=x end if y=flake[i][2]+flake[i][3] if y<fallen[x] then poke(foreground+320*y+x, BRIGHT_WHITE) flake[i][2]=y else if x>1 and fallen[x-1]>fallen[x] then x-=1 end if if x<318 and fallen[x+2]>fallen[x] then x+=2 end if y=fallen[x]-1 poke(background+320*y+x, BRIGHT_WHITE) fallen[x]=y flake[i]={rand(319), -1, rand(3)} end if end for end procedure -- main -------------------------------------------------------------- tick_rate(200) o=graphics_mode(19) flake=repeat({}, n) fallen=repeat(200,319) init() frame=0 et=time() t=time()+0.03 while get_key()=-1 do snow() while time()<t do end while frame+=1 if and_bits(frame, #3FFF)=0 then -- reset background mem_copy(background,textscreen,64000) fallen=repeat(200,319) end if mem_copy(#A0000, foreground, 64000) t=time()+0.04 -- speed control: 33.3 fps end while et=time()-et o=graphics_mode(-1) printf(1, "%6.2f fps\n", frame/et)