From 11d74d4e4b9563dee797f92667274e355af8a685 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sat, 26 Oct 2024 11:01:58 +0300 Subject: [PATCH] Using AI to improve code readability --- Graphics/Animations/snow.bas | 79 ++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/Graphics/Animations/snow.bas b/Graphics/Animations/snow.bas index 5665707..528724e 100755 --- a/Graphics/Animations/snow.bas +++ b/Graphics/Animations/snow.bas @@ -1,7 +1,7 @@ ' Svjatoslav Agejenko 2003.04 DEFINT A-Z -DECLARE SUB fall (a) +DECLARE SUB fall (particleIndex) DECLARE SUB start () amo = 500 @@ -9,69 +9,88 @@ amo = 500 DIM SHARED fx(1 TO amo) DIM SHARED fy(1 TO amo) +' Initialize particle positions FOR a = 1 TO amo -fx(a) = RND * 300 + 10 -fy(a) = RND * 100 + 10 + fx(a) = RND * 300 + 10 + fy(a) = RND * 100 + 10 NEXT a start 1 +' Main loop to simulate snowfall FOR b = 1 TO 100 -a = INT(RND * amo) + 1 -fall a + a = INT(RND * amo) + 1 + fall a NEXT b SOUND 0, .1 IF INKEY$ <> "" THEN SYSTEM GOTO 1 -SUB fall (a) +SUB fall (particleIndex) t = 0 2 -PSET (fx(a), fy(a)), 0 +' Draw the particle at its current position +PSET (fx(particleIndex), fy(particleIndex)), 0 -ny = fy(a) + 1 -nx = fx(a) + INT(RND * 3) - 1 +ny = fy(particleIndex) + 1 +nx = fx(particleIndex) + INT(RND * 3) - 1 + +' Check for collision with another particle IF POINT(nx, ny) > 0 THEN - IF t < 10 THEN t = t + 1: GOTO 2 - PSET (fx(a), fy(a)), 15 - nx = RND * 300 + 10 - ny = 1 + ' If collision detected and t is less than 10, increment t and retry + IF t < 10 THEN + t = t + 1 + GOTO 2 + END IF + ' If collision persists, change particle color to indicate collision + PSET (fx(particleIndex), fy(particleIndex)), 15 + nx = RND * 300 + 10 + ny = 1 END IF -IF fy(a) > 198 THEN - PSET (fx(a), fy(a)), 15 - nx = RND * 300 + 10 - ny = 1 +' Check if the particle has reached the bottom of the screen +IF fy(particleIndex) > 198 THEN + PSET (fx(particleIndex), fy(particleIndex)), 15 + nx = RND * 300 + 10 + ny = 1 END IF -fx(a) = nx -fy(a) = ny -PSET (fx(a), fy(a)), 15 +' Update particle position +fx(particleIndex) = nx +fy(particleIndex) = ny + +' Draw the particle at its new position +PSET (fx(particleIndex), fy(particleIndex)), 15 + END SUB DEFSNG A-Z SUB start SCREEN 13 +' Create nice and curvy surface for snow particles to fall onto. +' Here we draw "SNOW" with big and wobbly letters to the screen +' to serve as an obstacle for snow particles. + LOCATE 1, 1 PRINT "SNOW" FOR y = 0 TO 15 STEP .2 - xp = SIN(y / 1) * 3 + 65 - FOR x = 0 TO 30 STEP .1 - ys = 4 + COS(x / 5) - yp = COS(x / 4 + 3) * 5 + 130 - c = POINT(x, y) - IF c > 0 THEN - LINE (x * 6 + xp, y * ys + yp)-(x * 6 + xp + 1, y * ys + yp + 1), 11, BF - END IF - NEXT x + xp = SIN(y / 1) * 3 + 65 + FOR x = 0 TO 30 STEP .1 + ys = 4 + COS(x / 5) + yp = COS(x / 4 + 3) * 5 + 130 + c = POINT(x, y) + ' Draw a line if the point is not black + IF c > 0 THEN + LINE (x * 6 + xp, y * ys + yp)-(x * 6 + xp + 1, y * ys + yp + 1), 11, BF + END IF + NEXT x NEXT y LOCATE 1, 1 PRINT " " END SUB - -- 2.20.1