snooow.eDenna kod är public domain. Om ni hittar fel eller vill ändra något i koden blir jag jätteglad om ni skickar dessa ändringar till jesper [at] fantasi [punkt] se.
MODULE 'intuition/intuition',
'intuition/screens',
'graphics/rastport',
'utility/tagitem'
ENUM ARG_MAX, ARG_WIND, ARG_X, ARG_Y, ARG_W, ARG_H, ARG_PUBSCREEN
RAISE "wnd" IF OpenW() = 0,
"scr" IF LockPubScreen() = 0,
"args" IF ReadArgs() = 0
PROC main() HANDLE
DEF rdargs = 0, args:PTR TO LONG,
max, wind, -> max flakes and wind speed
left, top, width, height, -> drawing edges and dimensions
wnd_x, wnd_y, wnd_w, wnd_h, -> _window_ edges and dimensions
scr = 0 : PTR TO screen,
rp : PTR TO rastport,
wnd = 0 : PTR TO window,
x, t, sts, run,
sx[5000]:ARRAY OF LONG,
sy[5000]:ARRAY OF LONG
args := [0,0,0,0,0,0,0] -> enough space for all args
run := TRUE
rdargs := ReadArgs('MAXFLAKES/N,WIND/N,LEFTEDGE/N,TOPEDGE/N,'+
'WIDTH/N,HEIGHT/N,PUBSCREEN/K', args, NIL)
-> max = 1 to 5000, default 100
max := IF args[ARG_MAX] THEN Bounds(Long(args[ARG_MAX]), 1, 5000) ELSE 100
-> wind = -4 to 4, default 0
wind := IF args[ARG_WIND] THEN Bounds(Long(args[ARG_WIND]), -4, 4) ELSE 0
scr := LockPubScreen(args[ARG_PUBSCREEN]) -> NIL will go for default pubscreen
rp := scr.rastport
left := scr.wborleft -> left edge of window
top := rp.txheight + scr.wbortop + 1 -> top edge of window
-> width = 50 to screen width, default 100
width := IF args[ARG_W] THEN Bounds(Long(args[ARG_W]), 50, scr.width) ELSE 100
-> height = 50 to screen height, default 100
height := IF args[ARG_H] THEN Bounds(Long(args[ARG_H]), 50, scr.height) ELSE 100
wnd_w := width + left + scr.wborright
wnd_h := height + top + scr.wborbottom
wnd_x := IF args[ARG_X] THEN Bounds(Long(args[ARG_X]), 0, scr.width-wnd_w) ELSE 270
wnd_y := IF args[ARG_Y] THEN Bounds(Long(args[ARG_Y]), 0, scr.height-wnd_h) ELSE 50
wnd := OpenW(wnd_x, wnd_y, wnd_w, wnd_h, IDCMP_CLOSEWINDOW,
WFLG_DRAGBAR OR WFLG_CLOSEGADGET OR WFLG_DEPTHGADGET,
'SnoOow!', 0, 0, [WA_PUBSCREEN,scr,TAG_DONE])
-> drawing area is from (left,top) to (left+width,top+height)
prepScreen(width,height,top)
sts := 0
FOR x:= 0 TO max - 1
sx[x] := Rnd(width - 10) + 5
sy[x] := Rnd(height - 25) - height
ENDFOR
WHILE sts < height
IF sts > 0 THEN sts := sts + 1
FOR x := 0 TO max - 1
IF sy[x] > top THEN Plot(sx[x], sy[x], 0)
sy[x] := sy[x] + 1
IF sy[x] > top
t := Rnd(3 + wind) - 1
IF ReadPixel(stdrast, sx[x] + t, sy[x]) = 0 THEN sx[x] := sx[x] + t
IF (ReadPixel(stdrast, sx[x], sy[x] + 1) <> 0) AND
(ReadPixel(stdrast, sx[x], sy[x] + 2) <> 0)
IF ReadPixel(stdrast, sx[x] + 1, sy[x] + 1) = 0
sx[x] := sx[x] + 1
ELSEIF ReadPixel(stdrast, sx[x] - 1, sy[x] + 1) = 0
sx[x] := sx[x] - 1
ELSE
Plot(sx[x], sy[x], 2)
IF sts = 0
IF sy[x] = (top + 4)
prepScreen(width, height, top)
FOR x := 0 TO max - 1
sx[x] := Rnd(width - 10) + 5
sy[x] := Rnd(height - 25) - height
ENDFOR
ELSE
sy[x] := top
sx[x] := Rnd(width - 10) + 5
ENDIF
ELSE
sy[x] := -2 * height
ENDIF
ENDIF
ENDIF
ENDIF
IF sy[x] > top THEN Plot(sx[x], sy[x], 2)
ENDFOR
IF Mouse() = %011 THEN sts := 1
WaitTOF()
ENDWHILE
Raise()
EXCEPT
IF wnd THEN CloseW(wnd)
IF scr THEN UnlockPubScreen(NIL,scr)
IF rdargs THEN FreeArgs(rdargs)
ENDPROC
PROC prepScreen(width,height,top)
DEF x,y,w,h
w := width / 2 - 30
h := height / 2 + 4
Box(3,top,width - 3,height - 3,0)
Colour(3)
TextF(w,h,'SnoOow!')
FOR x := w TO w + 53
FOR y:=h-9 TO h + 1
-> IF (ReadPixel(stdrast, x + 1, y) = 3) AND
-> (ReadPixel(stdrast, x, y) = 0) THEN Plot(x, y, 1)
IF (ReadPixel(stdrast, x - 1, y) = 3) AND
(ReadPixel(stdrast, x, y) = 0) THEN Plot(x, y, 1)
-> IF (ReadPixel(stdrast, x, y + 1) = 3) AND
-> (ReadPixel(stdrast, x, y) = 0) THEN Plot(x, y, 1)
IF (ReadPixel(stdrast, x, y - 1) = 3) AND
(ReadPixel(stdrast, x, y) = 0) THEN Plot(x, y, 1)
ENDFOR
ENDFOR
ENDPROC
CHAR '$VER: SnoOow V1.2 (97.10.24)'
|