' Svjatoslav Agejenko 2003.04\r
\r
DEFINT A-Z\r
-DECLARE SUB fall (a)\r
+DECLARE SUB fall (particleIndex)\r
DECLARE SUB start ()\r
\r
amo = 500\r
DIM SHARED fx(1 TO amo)\r
DIM SHARED fy(1 TO amo)\r
\r
+' Initialize particle positions\r
FOR a = 1 TO amo\r
-fx(a) = RND * 300 + 10\r
-fy(a) = RND * 100 + 10\r
+ fx(a) = RND * 300 + 10\r
+ fy(a) = RND * 100 + 10\r
NEXT a\r
\r
start\r
\r
1\r
+' Main loop to simulate snowfall\r
FOR b = 1 TO 100\r
-a = INT(RND * amo) + 1\r
-fall a\r
+ a = INT(RND * amo) + 1\r
+ fall a\r
NEXT b\r
SOUND 0, .1\r
IF INKEY$ <> "" THEN SYSTEM\r
GOTO 1\r
\r
-SUB fall (a)\r
+SUB fall (particleIndex)\r
\r
t = 0\r
2\r
-PSET (fx(a), fy(a)), 0\r
+' Draw the particle at its current position\r
+PSET (fx(particleIndex), fy(particleIndex)), 0\r
\r
-ny = fy(a) + 1\r
-nx = fx(a) + INT(RND * 3) - 1\r
+ny = fy(particleIndex) + 1\r
+nx = fx(particleIndex) + INT(RND * 3) - 1\r
+\r
+' Check for collision with another particle\r
IF POINT(nx, ny) > 0 THEN\r
- IF t < 10 THEN t = t + 1: GOTO 2\r
- PSET (fx(a), fy(a)), 15\r
- nx = RND * 300 + 10\r
- ny = 1\r
+ ' If collision detected and t is less than 10, increment t and retry\r
+ IF t < 10 THEN\r
+ t = t + 1\r
+ GOTO 2\r
+ END IF\r
+ ' If collision persists, change particle color to indicate collision\r
+ PSET (fx(particleIndex), fy(particleIndex)), 15\r
+ nx = RND * 300 + 10\r
+ ny = 1\r
END IF\r
\r
-IF fy(a) > 198 THEN\r
- PSET (fx(a), fy(a)), 15\r
- nx = RND * 300 + 10\r
- ny = 1\r
+' Check if the particle has reached the bottom of the screen\r
+IF fy(particleIndex) > 198 THEN\r
+ PSET (fx(particleIndex), fy(particleIndex)), 15\r
+ nx = RND * 300 + 10\r
+ ny = 1\r
END IF\r
\r
-fx(a) = nx\r
-fy(a) = ny\r
-PSET (fx(a), fy(a)), 15\r
+' Update particle position\r
+fx(particleIndex) = nx\r
+fy(particleIndex) = ny\r
+\r
+' Draw the particle at its new position\r
+PSET (fx(particleIndex), fy(particleIndex)), 15\r
+\r
END SUB\r
\r
DEFSNG A-Z\r
SUB start\r
SCREEN 13\r
\r
+' Create nice and curvy surface for snow particles to fall onto.\r
+' Here we draw "SNOW" with big and wobbly letters to the screen\r
+' to serve as an obstacle for snow particles.\r
+\r
LOCATE 1, 1\r
PRINT "SNOW"\r
\r
FOR y = 0 TO 15 STEP .2\r
- xp = SIN(y / 1) * 3 + 65\r
- FOR x = 0 TO 30 STEP .1\r
- ys = 4 + COS(x / 5)\r
- yp = COS(x / 4 + 3) * 5 + 130\r
- c = POINT(x, y)\r
- IF c > 0 THEN\r
- LINE (x * 6 + xp, y * ys + yp)-(x * 6 + xp + 1, y * ys + yp + 1), 11, BF\r
- END IF\r
- NEXT x\r
+ xp = SIN(y / 1) * 3 + 65\r
+ FOR x = 0 TO 30 STEP .1\r
+ ys = 4 + COS(x / 5)\r
+ yp = COS(x / 4 + 3) * 5 + 130\r
+ c = POINT(x, y)\r
+ ' Draw a line if the point is not black\r
+ IF c > 0 THEN\r
+ LINE (x * 6 + xp, y * ys + yp)-(x * 6 + xp + 1, y * ys + yp + 1), 11, BF\r
+ END IF\r
+ NEXT x\r
NEXT y\r
\r
LOCATE 1, 1\r
PRINT " "\r
\r
END SUB\r
-\r