Using AI to improve code readability
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Wed, 21 Aug 2024 05:23:44 +0000 (08:23 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Wed, 21 Aug 2024 05:23:44 +0000 (08:23 +0300)
Graphics/Animations/matrix4.bas
Graphics/Animations/movdna.bas
Graphics/Animations/ssaver.bas
Graphics/Animations/ssaver2.bas
Graphics/Animations/strange.bas

index bc29cdf..ecf14b9 100755 (executable)
-' by Svjatoslav Agejenko svjatoslav@svjatoslav.eu\r
-' 2003.04\r
-\r
-DECLARE FUNCTION getc% ()\r
-DECLARE SUB mks ()\r
-DEFINT A-Y\r
-DECLARE SUB disp ()\r
-DECLARE SUB shpal ()\r
-DECLARE SUB start ()\r
-\r
-DIM SHARED buf(1 TO 40, 1 TO 25) AS INTEGER\r
-DIM SHARED col(1 TO 40, 1 TO 25) AS INTEGER\r
-DIM SHARED snd(1 TO 20)\r
-DIM SHARED sndp\r
-\r
-start\r
-'shpal\r
-\r
-FOR y = 1 TO 25\r
-  FOR x = 1 TO 40\r
-    buf(x, y) = getc\r
-  NEXT x\r
-NEXT y\r
-\r
-FOR y = 1 TO 25\r
-  FOR x = 1 TO 40\r
-    col(x, y) = 1\r
-  NEXT x\r
-NEXT y\r
-\r
-act = 0\r
-1\r
-mks\r
-frm = frm + 1\r
-IF frm > 10000 THEN frm = 1\r
-FOR y = 25 TO 2 STEP -1\r
-  FOR x = 1 TO 40\r
-    buf(x, y) = buf(x, y - 1)\r
-  NEXT x\r
-NEXT y\r
-mks\r
-FOR x = 1 TO 40\r
-  buf(x, 1) = buf(x, 25)\r
-NEXT x\r
-buf(RND * 39 + 1, RND * 10 + 1) = getc\r
-act = act + 1\r
-disp\r
-SELECT CASE act\r
+' Program to render animation inspired by Matrix movie.\r
+' By Svjatoslav Agejenko.\r
+' Email: svjatoslav@svjatoslav.eu\r
+' Homepage: http://www.svjatoslav.eu\r
+'\r
+' Changelog:\r
+' 2003.04, Initial version\r
+' 2024.08, Improved program readability using AI\r
+\r
+\r
+DECLARE FUNCTION getCharacter% ()\r
+DECLARE SUB makeSound ()\r
+DEFINT A-Z\r
+DECLARE SUB displayScreen ()\r
+DECLARE SUB showPalette ()\r
+DECLARE SUB initializeGame ()\r
+\r
+DIM SHARED screenBuffer(1 TO 40, 1 TO 25) AS INTEGER\r
+DIM SHARED colorBuffer(1 TO 40, 1 TO 25) AS INTEGER\r
+DIM SHARED soundArray(1 TO 20)\r
+DIM SHARED soundPointer\r
+\r
+initializeGame\r
+'showPalette()\r
+\r
+' Initialize the screen buffer with random characters\r
+FOR row = 1 TO 25\r
+  FOR col = 1 TO 40\r
+    screenBuffer(col, row) = getCharacter\r
+  NEXT col\r
+NEXT row\r
+\r
+' Initialize the color buffer with a default color\r
+FOR row = 1 TO 25\r
+  FOR col = 1 TO 40\r
+    colorBuffer(col, row) = 1\r
+  NEXT col\r
+NEXT row\r
+\r
+actionCounter = 0\r
+\r
+10 ' Main game loop\r
+makeSound\r
+frameCounter = frameCounter + 1\r
+IF frameCounter > 10000 THEN frameCounter = 1\r
+\r
+' Shift the screen buffer contents down by one row\r
+FOR row = 25 TO 2 STEP -1\r
+  FOR col = 1 TO 40\r
+    screenBuffer(col, row) = screenBuffer(col, row - 1)\r
+  NEXT col\r
+NEXT row\r
+makeSound\r
+\r
+' Move the top row to the bottom\r
+FOR col = 1 TO 40\r
+  screenBuffer(col, 1) = screenBuffer(col, 25)\r
+NEXT col\r
+\r
+' Randomly change a character in the buffer\r
+screenBuffer(INT(RND * 39 + 1), INT(RND * 10 + 1)) = getCharacter\r
+actionCounter = actionCounter + 1\r
+displayScreen\r
+\r
+SELECT CASE actionCounter\r
 CASE 1\r
-        FOR a = 1 TO 20\r
-          snd(a) = 0\r
-          IF RND * 100 < 2 THEN snd(a) = RND * 4000 + 4000\r
-        NEXT a\r
-        b = SIN(frm / 100) * 3 + 6\r
-        FOR a = 1 TO 20 STEP b\r
-          snd(a) = 10000\r
-        NEXT a\r
+  ' Initialize sound array with random values\r
+  FOR a = 1 TO 20\r
+    soundArray(a) = 0\r
+    IF RND * 100 < 2 THEN soundArray(a) = INT(RND * 4000 + 4000)\r
+  NEXT a\r
+  ' Set sound frequencies based on sine wave\r
+  b = SIN(frameCounter / 100) * 3 + 6\r
+  FOR a = 1 TO 20 STEP b\r
+    soundArray(a) = 10000\r
+  NEXT a\r
 \r
 CASE 2\r
-        c = RND * 5\r
-        x1 = RND * 38 + 1\r
-        y = RND * 23 + 1\r
-        x2 = RND * 38 + 1\r
-        IF x1 > x2 THEN SWAP x1, x2\r
-        FOR x = x1 TO x2\r
-          col(x, y) = c\r
-        NEXT x\r
+  ' Draw a horizontal line with random color\r
+  c = INT(RND * 5)\r
+  x1 = INT(RND * 38 + 1)\r
+  y = INT(RND * 23 + 1)\r
+  x2 = INT(RND * 38 + 1)\r
+  IF x1 > x2 THEN SWAP x1, x2\r
+  FOR x = x1 TO x2\r
+    colorBuffer(x, y) = c\r
+  NEXT x\r
+\r
 CASE 3\r
-        c = RND * 5\r
-        y1 = RND * 23 + 1\r
-        x = RND * 38 + 1\r
-        y2 = RND * 23 + 1\r
-        IF y1 > y2 THEN SWAP x1, x2\r
-        FOR y = y1 TO y2\r
-          col(x, y) = c\r
-        NEXT y\r
+  ' Draw a vertical line with random color\r
+  c = INT(RND * 5)\r
+  y1 = INT(RND * 23 + 1)\r
+  x = INT(RND * 38 + 1)\r
+  y2 = INT(RND * 23 + 1)\r
+  IF y1 > y2 THEN SWAP y1, y2\r
+  FOR y = y1 TO y2\r
+    colorBuffer(x, y) = c\r
+  NEXT y\r
+\r
 CASE 4\r
-       IF RND * 100 < 20 THEN\r
-       FOR y = 1 TO 25\r
-          FOR x = 1 TO 40\r
-            IF col(x, y) > 1 THEN col(x, y) = col(x, y) - 1\r
-          NEXT x\r
-        NEXT y\r
-       END IF\r
+  ' Decrease the intensity of colors on the screen\r
+  IF RND * 100 < 20 THEN\r
+    FOR y = 1 TO 25\r
+      FOR x = 1 TO 40\r
+        IF colorBuffer(x, y) > 1 THEN colorBuffer(x, y) = colorBuffer(x, y) - 1\r
+      NEXT x\r
+    NEXT y\r
+  END IF\r
+\r
 CASE 5\r
-       IF RND * 100 < 5 THEN\r
-       FOR y = 1 TO 25 STEP 2\r
-          FOR x = 1 TO 40\r
-            col(x, y) = 1\r
-          NEXT x\r
-        NEXT y\r
-       END IF\r
+  ' Reset every second row to default color\r
+  IF RND * 100 < 5 THEN\r
+    FOR y = 1 TO 25 STEP 2\r
+      FOR x = 1 TO 40\r
+        colorBuffer(x, y) = 1\r
+      NEXT x\r
+    NEXT y\r
+  END IF\r
+\r
 CASE 6\r
-       IF RND * 100 < 5 THEN\r
-       FOR x = 1 TO 40 STEP 2\r
-          FOR y = 1 TO 25\r
-            col(x, y) = 1\r
-          NEXT y\r
-        NEXT x\r
-       END IF\r
+  ' Reset every second column to default color\r
+  IF RND * 100 < 5 THEN\r
+    FOR x = 1 TO 40 STEP 2\r
+      FOR y = 1 TO 25\r
+        colorBuffer(x, y) = 1\r
+      NEXT y\r
+    NEXT x\r
+  END IF\r
+\r
 CASE 7\r
-       FOR a = 1 TO 30\r
-         col(RND * 39 + 1, RND * 23 + 1) = RND * 4 + 1\r
-       NEXT a\r
+  ' Randomly set some characters to random colors\r
+  FOR a = 1 TO 30\r
+    colorBuffer(INT(RND * 39 + 1), INT(RND * 23 + 1)) = INT(RND * 4 + 1)\r
+  NEXT a\r
+\r
 CASE 8\r
-       IF INKEY$ <> "" THEN SYSTEM\r
-       act = 0\r
+  ' Check for user input to exit the game\r
+  IF INKEY$ <> "" THEN SYSTEM\r
+  actionCounter = 0\r
 END SELECT\r
-GOTO 1\r
 \r
-SYSTEM\r
+GOTO 10\r
+\r
+SYSTEM:\r
+' Exit the game\r
+END\r
 \r
-SUB disp\r
+SUB displayScreen\r
 \r
-mks\r
+makeSound\r
 LOCATE 1, 1\r
+\r
+' Display the top half of the screen\r
 FOR y = 1 TO 10\r
-FOR x = 1 TO 40\r
-COLOR col(x, y), 0\r
-PRINT CHR$(buf(x, y));\r
-NEXT x\r
+  FOR x = 1 TO 40\r
+    COLOR colorBuffer(x, y), 0\r
+    PRINT CHR$(screenBuffer(x, y));\r
+  NEXT x\r
 NEXT y\r
-mks\r
+\r
+makeSound\r
+' Display the middle part of the screen\r
 FOR y = 11 TO 20\r
-FOR x = 1 TO 40\r
-COLOR col(x, y), 0\r
-PRINT CHR$(buf(x, y));\r
-NEXT x\r
+  FOR x = 1 TO 40\r
+    COLOR colorBuffer(x, y), 0\r
+    PRINT CHR$(screenBuffer(x, y));\r
+  NEXT x\r
 NEXT y\r
-mks\r
+\r
+makeSound\r
+' Display the bottom half of the screen\r
 FOR y = 21 TO 25\r
-FOR x = 1 TO 40\r
-COLOR col(x, y), 0\r
-PRINT CHR$(buf(x, y));\r
-NEXT x\r
+  FOR x = 1 TO 40\r
+    COLOR colorBuffer(x, y), 0\r
+    PRINT CHR$(screenBuffer(x, y));\r
+  NEXT x\r
 NEXT y\r
-mks\r
+\r
+makeSound\r
 \r
 END SUB\r
 \r
-FUNCTION getc\r
+FUNCTION getCharacter\r
+' Generate a random character based on probability\r
 IF RND * 100 > 50 THEN\r
-  a = RND * 9 + 48\r
+  getCharacter = INT(RND * 9 + 48)\r
 ELSE\r
-  a = RND * 25 + 65\r
+  getCharacter = INT(RND * 25 + 65)\r
 END IF\r
-IF RND * 100 < 15 THEN a = 32\r
-getc = a\r
+IF RND * 100 < 15 THEN getCharacter = 32 ' 15% chance to return a space\r
 END FUNCTION\r
 \r
-SUB mks\r
-sndp = sndp + 1\r
-IF sndp > 20 THEN sndp = 1\r
-SOUND snd(sndp), .07\r
-'SOUND 0, .07\r
-END SUB\r
-\r
-SUB shpal\r
-\r
-FOR a = 0 TO 16\r
-COLOR a\r
-PRINT a, "Palette test"\r
-NEXT a\r
-a$ = INPUT$(1)\r
-END SUB\r
+SUB initializeGame\r
 \r
-SUB start\r
-RANDOMIZE TIMER\r
-CLS\r
-WIDTH 40, 25\r
-VIEW PRINT 1 TO 25\r
+RANDOMIZE TIMER ' Seed the random number generator\r
+CLS ' Clear the screen\r
+WIDTH 40, 25 ' Set screen dimensions\r
+VIEW PRINT 1 TO 25 ' Set the print area\r
 \r
-  OUT &H3C8, 0\r
-  OUT &H3C9, 0\r
-  OUT &H3C9, 0\r
-  OUT &H3C9, 0\r
+' Initialize palette registers for color text mode\r
+OUT &H3C8, 0\r
+OUT &H3C9, 0\r
+OUT &H3C9, 0\r
+OUT &H3C9, 0\r
 \r
+' Set up color palettes\r
 FOR a = 1 TO 5\r
   OUT &H3C8, a\r
 \r
@@ -182,6 +211,7 @@ FOR a = 1 TO 5
   g = a * 10 + 20\r
   r = a * 0\r
 \r
+  ' Ensure RGB values do not exceed the maximum value\r
   IF r > 63 THEN r = 63\r
   IF g > 63 THEN g = 63\r
   IF b > 63 THEN b = 63\r
@@ -192,3 +222,22 @@ NEXT a
 \r
 END SUB\r
 \r
+SUB makeSound\r
+' Update the sound pointer and play a sound\r
+soundPointer = soundPointer + 1\r
+IF soundPointer > 20 THEN soundPointer = 1\r
+SOUND soundArray(soundPointer), .07\r
+' SOUND 0, .07 ' Uncomment to play a continuous tone\r
+END SUB\r
+\r
+SUB showPalette\r
+\r
+' Display a palette test on the screen\r
+FOR a = 0 TO 15\r
+  COLOR a\r
+  PRINT a; " Palette test"\r
+NEXT a\r
+a$ = INPUT$(1) ' Wait for user input\r
+\r
+END SUB\r
+\r
index 51d02be..70c45d6 100755 (executable)
@@ -1,4 +1,8 @@
-' Svjatoslav Agejenko\r
+' Program to render animated DNA.\r
+' By Svjatoslav Agejenko.\r
+' Email: svjatoslav@svjatoslav.eu\r
+' Homepage: http://www.svjatoslav.eu\r
+'\r
 \r
 DEFINT A-Y\r
 \r
@@ -9,42 +13,41 @@ DIM SHARED cc(1 TO 100)
 \r
 SCREEN 7, , , 1\r
 f = 0\r
-1\r
+\r
+1:\r
 b = 0\r
-zf = zf + .1\r
+zf = zf + 0.1\r
 FOR a = 1 TO 20\r
-\r
-b = b + 1\r
-cx(b) = SIN(a / 2 + zf) * 30 + 150\r
-cz(b) = SIN(a / 2 + zf + 1.6) * 2 + 2\r
-cy(b) = a * 8 + cz(b)\r
-cc(b) = 3\r
-b = b + 1\r
-cx(b) = SIN(a / 2 + zf + 2.5) * 30 + 150\r
-cz(b) = SIN(a / 2 + zf + 1.6 + 2.5) * 2 + 2\r
-cy(b) = a * 8 + cz(b)\r
-cc(b) = 4\r
+    b = b + 1\r
+    cx(b) = SIN(a / 2 + zf) * 30 + 150\r
+    cz(b) = SIN(a / 2 + zf + 1.6) * 2 + 2\r
+    cy(b) = a * 8 + cz(b)\r
+    cc(b) = 3\r
+\r
+    b = b + 1\r
+    cx(b) = SIN(a / 2 + zf + 2.5) * 30 + 150\r
+    cz(b) = SIN(a / 2 + zf + 1.6 + 2.5) * 2 + 2\r
+    cy(b) = a * 8 + cz(b)\r
+    cc(b) = 4\r
 NEXT a\r
 \r
 CLS\r
 FOR b = 0 TO 4\r
-\r
-IF b = 1 THEN\r
-FOR a = 1 TO 40 STEP 2\r
-LINE (cx(a), cy(a))-(cx(a + 1), cy(a + 1)), 15\r
-NEXT a\r
-END IF\r
-\r
-FOR a = 1 TO 40\r
-IF cz(a) = b THEN\r
-CIRCLE (cx(a), cy(a)), b + 5, cc(a)\r
-PAINT (cx(a), cy(a)), cc(a)\r
-CIRCLE (cx(a), cy(a)), b + 5, 0\r
-END IF\r
-NEXT a\r
+    IF b = 1 THEN\r
+        FOR a = 1 TO 40 STEP 2\r
+            LINE (cx(a), cy(a))-(cx(a + 1), cy(a + 1)), 15\r
+        NEXT a\r
+    END IF\r
+\r
+    FOR a = 1 TO 40\r
+        IF cz(a) = b THEN\r
+            CIRCLE (cx(a), cy(a)), b + 5, cc(a)\r
+            PAINT (cx(a), cy(a)), cc(a)\r
+            CIRCLE (cx(a), cy(a)), b + 5, 0\r
+        END IF\r
+    NEXT a\r
 NEXT b\r
 PCOPY 0, 1\r
 CLS\r
 IF INKEY$ = "" THEN GOTO 1\r
 SYSTEM\r
-\r
index 4d8daaf..aca7239 100755 (executable)
@@ -1,28 +1,45 @@
 ' Mystery screensaver\r
-' made by Svjatoslav Agejenko\r
-' last edit 2004.01\r
-' H-Page: svjatoslav.eu\r
-' E-Mail: svjatoslav@svjatoslav.eu\r
\r
+' By Svjatoslav Agejenko.\r
+' Email: svjatoslav@svjatoslav.eu\r
+' Homepage: http://www.svjatoslav.eu\r
+'\r
+' Changelog:\r
+' 2004.01, Initial version\r
+' 2024.08, Improved program readability using AI\r
+\r
 SCREEN 7, , , 1\r
 \r
+' Main loop for animation\r
+DO\r
+    ' Increment frame counter\r
+    frameCounter = frameCounter + 1\r
+\r
+    ' Calculate scaling factor based on frame counter\r
+    scaleFactor = (SIN(frameCounter / 100) + 1.1) * 2\r
+\r
+    ' Draw lines to create animation effect\r
+    FOR s = 1 TO 20 STEP .1\r
+        ' Calculate x and y coordinates for the first point\r
+        x = SIN(s / 1 + frameCounter / 7) * 100\r
+        y = COS(s / 1 + frameCounter / 10) * 100\r
+\r
+        ' Calculate x and y coordinates for the second point\r
+        x1 = SIN(s / 1 - frameCounter / 8) * 100\r
+        y1 = COS(s / 1 + frameCounter / 15) * 100\r
 \r
-1\r
-frm = frm + 1\r
+        ' Draw a line between the two points with varying thickness\r
+        LINE (x + 160, y + 100)-(x1 + 160, y1 + 100), s MOD 15\r
+    NEXT s\r
 \r
-f = (SIN(frm / 100) + 1.1) * 2\r
-FOR s = 1 TO 20 STEP .1\r
-  x = SIN(s / 1 + frm / 7) * 100\r
-  y = COS(s / 1 + frm / 10) * 100\r
-  x1 = SIN(s / 1 - frm / 8) * 100\r
-  y1 = COS(s / 1 + frm / 15) * 100\r
-  LINE (x + 160, y + 100)-(x1 + 160, y1 + 100), s MOD 15\r
-NEXT s\r
+    ' Copy screen buffer to display the animation\r
+    PCOPY 0, 1\r
 \r
+    ' Generate a sound effect\r
+    SOUND 0, 1\r
 \r
-PCOPY 0, 1\r
-SOUND 0, 1\r
-CLS\r
-IF INKEY$ <> "" THEN SYSTEM\r
-GOTO 1\r
+    ' Clear the screen for the next frame\r
+    CLS\r
 \r
+    ' Check if a key is pressed and exit if so\r
+    IF INKEY$ <> "" THEN SYSTEM\r
+LOOP\r
index 5cd885b..ac8cac9 100755 (executable)
@@ -1,31 +1,62 @@
-' Svjatoslav Agejenko 2003.04\r
+' Screensaver\r
+' By Svjatoslav Agejenko.\r
+' Email: svjatoslav@svjatoslav.eu\r
+' Homepage: http://www.svjatoslav.eu\r
+'\r
+' Changelog:\r
+' 2003.04, Initial version\r
+' 2024.08, Improved program readability using AI\r
+\r
 \r
 SCREEN 7, , , 1\r
 \r
-1\r
-IF frm > 10000 THEN frm = -10000\r
-FOR c = 1 TO 6\r
-  OUT &H3C8, c\r
-  OUT &H3C9, SIN(c + frm * 3) * 30 + 31\r
-  OUT &H3C9, COS(c * 1 + frm * 5) * 30 + 31\r
-  OUT &H3C9, SIN(c * .7 + frm * 2.23) * 30 + 31\r
-NEXT c\r
-\r
-frm = frm + .01\r
-\r
-FOR b = 1 TO 10\r
-  c = (b MOD 6) + 1\r
-  x = SIN(b + frm) * 100 + 150\r
-  y = COS(b * 1.2 + frm * 1.81) * 80 + 100\r
-  xs = SIN(b * frm * 2.3)\r
-  FOR xp = -50 TO 50 STEP 10\r
-  ys = COS(xp / 60 + frm * 1 + b) * 50\r
-  LINE (x, y)-(x + xp * xs, y - ys), c\r
-  NEXT xp\r
-NEXT b\r
-PCOPY 0, 1\r
-CLS\r
-SOUND 0, .4\r
-IF INKEY$ <> "" THEN SYSTEM\r
+' Main animation loop\r
+1 :\r
+    ' Adjust frame counter if it exceeds a certain threshold\r
+    IF frameCounter > 10000 THEN frameCounter = -10000\r
+\r
+    ' Update the positions of six points based on the frame counter\r
+    FOR pointIndex = 1 TO 6\r
+        OUT &H3C8, pointIndex\r
+        OUT &H3C9, SIN(pointIndex + frameCounter * 3) * 30 + 31\r
+        OUT &H3C9, COS(pointIndex * 1 + frameCounter * 5) * 30 + 31\r
+        OUT &H3C9, SIN(pointIndex * .7 + frameCounter * 2.23) * 30 + 31\r
+    NEXT pointIndex\r
+\r
+    ' Increment the frame counter for the next iteration\r
+    frameCounter = frameCounter + .01\r
+\r
+    ' Render lines connecting points\r
+    FOR objectIndex = 1 TO 10\r
+        ' Determine the color based on the remainder of objectIndex divided by 6\r
+        pointColor = (objectIndex MOD 6) + 1\r
+        ' Calculate the X coordinate for the starting point of the line\r
+        xCoordinate = SIN(objectIndex + frameCounter) * 100 + 150\r
+        ' Calculate the Y coordinate for the starting point of the line\r
+        yCoordinate = COS(objectIndex * 1.2 + frameCounter * 1.81) * 80 + 100\r
+        ' Calculate the sine component for the line's angle\r
+        xSineComponent = SIN(objectIndex * frameCounter * 2.3)\r
+        ' Draw lines from the starting point with varying lengths and angles\r
+        FOR xPositionOffset = -50 TO 50 STEP 10\r
+            ' Calculate the cosine component for the line's angle based on xPositionOffset\r
+            yCosineComponent = COS(xPositionOffset / 60 + frameCounter * 1 + objectIndex) * 50\r
+            ' Draw a line segment with varying thickness and color\r
+            LINE (xCoordinate, yCoordinate)-(xCoordinate + xPositionOffset * xSineComponent, yCoordinate - yCosineComponent), pointColor\r
+        NEXT xPositionOffset\r
+    NEXT objectIndex\r
+\r
+    ' Copy the graphics from the hidden page to the visible page\r
+    PCOPY 0, 1\r
+\r
+    ' Clear the screen for the next frame\r
+    CLS\r
+\r
+    ' Play a sound at a specific frequency and duration\r
+    SOUND 0, .4\r
+\r
+    ' Check if any key is pressed; if so, exit the program\r
+    IF INKEY$ <> "" THEN SYSTEM\r
+\r
+    ' Loop back to the start of the animation\r
 GOTO 1\r
 \r
index 6d7f2bd..abdfebb 100755 (executable)
@@ -1,27 +1,51 @@
-' Svjatoslav Agejenko 2000\r
+' Yin and yang animation\r
+' By Svjatoslav Agejenko.\r
+' Email: svjatoslav@svjatoslav.eu\r
+' Homepage: http://www.svjatoslav.eu\r
+'\r
+' Changelog:\r
+' 2000, Initial version\r
+' 2024.08, Improved program readability using AI\r
 \r
-DECLARE SUB cir (x!, y!, r!, c!)\r
+DECLARE SUB Cir (x!, y!, r!, c!)\r
 SCREEN 13\r
 pi = 3.1415926#\r
 PAINT (1, 1), 1\r
-1\r
-x = SIN(a) * 40 + 160\r
-x1 = SIN(a + pi) * 40 + 160\r
-y = COS(a) * 34 + 100\r
-y1 = COS(a + pi) * 34 + 100\r
-cir x, y, 40, 0\r
-cir x1, y1, 40, 1\r
-a = a + .05\r
-IF INKEY$ <> "" THEN SYSTEM\r
-GOTO 1\r
-\r
-SUB cir (x, y, r, c)\r
-cc1 = 0\r
-cc2 = 15\r
-IF c = 1 THEN SWAP cc1, cc2\r
-FOR a = 1 TO r\r
-IF a < r / 2 THEN c1 = cc1 ELSE c1 = cc2\r
-CIRCLE (x, y), a, c1\r
-NEXT a\r
-END SUB\r
 \r
+' Main animation loop\r
+DO\r
+    ' Calculate the x and y positions for both circles using sine and cosine functions\r
+    x = SIN(a) * 40 + 160\r
+    x1 = SIN(a + pi) * 40 + 160\r
+    y = COS(a) * 34 + 100\r
+    y1 = COS(a + pi) * 34 + 100\r
+\r
+    ' Draw the first circle with color 0 (black)\r
+    Cir x, y, 40, 0\r
+    ' Draw the second circle with color 1 (blue)\r
+    Cir x1, y1, 40, 1\r
+\r
+    ' Increment the angle to animate the circles\r
+    a = a + .05\r
+\r
+    ' Check for user input to exit the program\r
+    IF INKEY$ <> "" THEN SYSTEM\r
+LOOP\r
+\r
+' Subroutine to draw a circle with specified center (x, y), radius r, and color c\r
+SUB Cir (x, y, r, c)\r
+    ' Define colors for the circle outline\r
+    cc1 = 0 ' Black\r
+    cc2 = 15 ' White\r
+\r
+    ' Swap colors if the second color is desired for the inner part of the circle\r
+    IF c = 1 THEN SWAP cc1, cc2\r
+\r
+    ' Draw the circle from radius 1 to r\r
+    FOR a = 1 TO r\r
+        ' Determine the color for the current circle segment\r
+        IF a < r / 2 THEN c1 = cc1 ELSE c1 = cc2\r
+        ' Draw the circle segment with the determined color\r
+        CIRCLE (x, y), a, c1\r
+    NEXT a\r
+END SUB\r