01-01-2006, 08:12 AM
Here's a simple little app I made to simulate snowfall.
Since I started programming again a couple of weeks ago, this is probably my best program so far. Both the code and the result are aesthetically pleasing. For a while, anyway. Maybe I'll make this my screensaver.
The code is uncommented, but everything is fairly clear. Change MAX_PARTICLES as you please, and the delay (CLS_DELAY) as well.
Tell me what you think.
Since I started programming again a couple of weeks ago, this is probably my best program so far. Both the code and the result are aesthetically pleasing. For a while, anyway. Maybe I'll make this my screensaver.
The code is uncommented, but everything is fairly clear. Change MAX_PARTICLES as you please, and the delay (CLS_DELAY) as well.
Tell me what you think.
Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'SNOWFALL.BAS '
'Snowfall simulator '
'Created by Zachary Vernon '
'Change MAX_PARTICLES at will, as well as the delay (CLS_DELAY). '
'Enjoy! '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#INCLUDE "fbgfx.bi"
DECLARE SUB InitParticles()
DECLARE SUB DrawParticles()
DECLARE SUB UpdateParticles()
OPTION EXPLICIT
CONST MAX_PARTICLES AS INTEGER=5000
CONST SCREEN_XRES AS INTEGER=800
CONST SCREEN_YRES AS INTEGER=600
CONST CLS_DELAY AS INTEGER=10
TYPE Particle
Clr AS INTEGER
X AS INTEGER
Y AS INTEGER
X_Drift AS INTEGER
Y_Speed AS INTEGER
END TYPE
DIM SHARED Particles(1 TO MAX_PARTICLES) AS Particle
DIM SHARED Num_Particles,Particle_Increase,I,WorkPage AS INTEGER
DIM SHARED K AS STRING
CALL InitParticles()
SCREENRES SCREEN_XRES,SCREEN_YRES,8,2,GFX_FULLSCREEN
SETMOUSE 0,0,0
DO UNTIL K=CHR$(27)
SCREENSET WorkPage,WorkPage XOR 1
FOR I=1 TO CLS_DELAY
CLS
NEXT I
CALL DrawParticles()
CALL UpdateParticles()
WorkPage=WorkPage XOR 1
K$=INKEY$
LOOP
SUB InitParticles()
RANDOMIZE TIMER
FOR I=1 TO MAX_PARTICLES
Particles(I).Clr=INT((31 - 19 + 1) * RND(1) + 19)
Particles(I).Y=CINT(RND(1) * SCREEN_YRES)
Particles(I).X=CINT(RND(1) * SCREEN_XRES)
Particles(I).X_Drift=CINT(RND(1) * 1)
Particles(I).Y_Speed=CINT(RND(1) * 3) + 1
NEXT I
END SUB
SUB DrawParticles()
FOR I=1 TO MAX_PARTICLES
PSET (Particles(I).X,Particles(I).Y - 1),Particles(I).Clr - 1
PSET (Particles(I).X,Particles(I).Y),Particles(I).Clr
NEXT I
END SUB
SUB UpdateParticles()
RANDOMIZE TIMER
FOR I=1 TO MAX_PARTICLES
Particles(I).Y=Particles(I).Y + Particles(I).Y_Speed
Particles(I).X=Particles(I).X + Particles(I).X_Drift
Particles(I).X_Drift=-(Particles(I).X_Drift)
IF Particles(I).X >= SCREEN_XRES THEN Particles(I).X=INT(RND(1) * SCREEN_XRES)
IF Particles(I).Y >= SCREEN_YRES THEN Particles(I).Y=0
NEXT
END SUB
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
--------------------------------------
Freebasic is like QB, except it doesn't suck.