Damn, missed something:

1for i=1to 100
2a$="":if i mod 3=0:a$="FIZZ"
3if i mod 5=0:a$=a$&"BUZZ"
4print i,a$:next

(89 bytes including 4 LF)

Marcel
Never mind FIZZBUZZ... (and this afternoon's solutions only work on SBASIC what with NEXT with no variable and uninitialised variables...

Reminds me of ZX81 days, trying to save a byte here and a byte there...not so much oneupmanship as "onelessship" :-)

I'm sat here surrounded by snow (well, outside the house). So, what better than to write a snowfall simulator?

Admittedly, Per should be the expert on this in Norway... we Brits ain't exactly known for our skills in handling snow ;-)

This should run in SuperBASIC and you can EX it as a SBASIC program as well. It compiles with QLiberator if you prefer. If you are using a hires screen, change the screen coordinate values in line 880 to shove it somewhere out of the way on the screen. Obviosuly, you'll need to save the listing as text from this email and copy it to your QL or emulator (and possibly fix end-of-line characters if my email prog has added CRs).

Could probably be adapted to work as a screen saver with my LPsaver program if you try really hard :-)

Dilwyn Jones
==========

100 REMark snowfall
110 OPEN #3,con
120 RANDOMISE
130 Screen_Size
140 flakes% = 200 : REMark change for more snowflakes at slower speed
150 :
160 DIM flakex%(flakes%-1),flakey%(flakes%-1),flakew%(flakes%-1),ground%(w%-1)
170 :
180 Start : REMark initialise this snowfall
190 :
200 REPeat snowfall
210   IF INKEY$(#3) = CHR$(27) THEN EXIT snowfall
220   :
230   REMark change density of snowfall at random
240   IF RND(1 TO 5) = 1 THEN density% = RND(2 TO 5)
250   :
260   REMark change wind direction at random every now and then
270   IF RND(1 TO 1000) = 1 THEN
280     gradient% = RND(-2 TO 2) : slope% = 5*ABS(gradient%)
290   END IF
300   :
310   IF RND(1 TO 5-density%) = 1 THEN
320     REPeat make_a_flake
330       rand% = RND(0 TO flakes%-1)
340       IF flakey%(rand%) = -1 THEN
350         flakew%(rand%)=1+RND(0 TO 1) : REMark flake size
360         IF gradient% <> 0 AND RND(1 TO 10) = 1 THEN
370           REMark random flake from edge of screen
380           flakey%(rand%) = RND(.25*h% TO .75*h%)
390 IF gradient% < 0 THEN flakex%(rand%) = w%-flakew%(rand%) : ELSE flakex%(rand%) = 0
400         ELSE
410           REMark from top of screen
420 flakex%(rand%) = RND(0 TO w%-flakew%(rand%)) : flakey%(rand%) = 0
430         END IF
440 BLOCK #3,flakew%(rand%),1,flakex%(rand%),flakey%(rand%),7 : EXIT make_a_flake
450       END IF
460     END REPeat make_a_flake
470   END IF
480   :
490   REMark make it snow by moving the flakes down the screen
500   FOR x = 0 TO flakes%-1
510     IF flakey%(x) > -1 THEN
520       REMark erase original flake position...
530       BLOCK #3,flakew%(x),1,flakex%(x),flakey%(x),0
540       :
550       IF RND(1 TO slope%) = 1 THEN
560         REMark which way is the wind blowing?
570         flakex%(x) = flakex%(x)+gradient%
580         IF flakex%(x) < 0 OR flakex%(x) >= (w%-1) THEN
590           REMark flake off screen, back to top until reactivated
600           flakey%(x) = -1 : NEXT x : EXIT x
610         END IF
620       END IF
630       :
640 flakey%(x) = flakey%(x)+RND(1 TO 2) : REMark random falling speed
650       :
660       IF flakey%(x) < ground%(flakex%(x)) THEN
670         REMark not yet reached ground
680 BLOCK #3,flakew%(x),1,flakex%(x),flakey%(x),7 : REMark print snowflake
690       ELSE
700         REMark reached ground, so ground snow builds up
710 FOR a = 0 TO flakew%(x)-1 : ground%(flakex%(x)+a) = ground%(flakex%(x)+a)-1
720         flakey%(x) = -1 : REMark stop this flake
730 BLOCK #3,flakew%(x),h%-ground%(flakex%(x)),flakex%(x),ground%(flakex%(x)),7
740         FOR a = 0 TO flakew%(x)-1
750 IF ground%(flakex%(x)+a) < 1 THEN Start : EXIT x : REMark restart snowfall when screen full
760         END FOR a
770       END IF
780     END IF
790   END FOR x
800 END REPeat snowfall
810 :
820 CLOSE #3
830 :
840 STOP
850 :
860 DEFine PROCedure Screen_Size
870   REMark set window size and location
880   w% = 256 : h% = 128 : ox% = 256 : oy% = 128
890 WINDOW #3,w%,h%,ox%,oy% : BORDER #3,1,2 : PAPER #3,0 : INK#3,7 : CLS #3
900   w% = w%-4 : h% = h%-2 : REMark allow for border
910 END DEFine Screen_Size
920 :
930 DEFine PROCedure Start
940   LOCal x
950   density% = RND(2 TO 5)
960   gradient% = RND(-2 TO 2)  : REMark which way the snow blows
970   slope% = 5*ABS(gradient%) : REMark
980   FOR x = 0 TO flakes%-1 : flakey%(x) = -1
990   FOR x = 0 TO w%-1 : ground%(x) = h%-1
1000   CLS #3
1010 END DEFine Start



_______________________________________________
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm

Reply via email to