From 3eb0ecd48cce3d1e6df26a5294a5dd9ddbd6d9e6 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sat, 26 Oct 2024 10:17:29 +0300 Subject: [PATCH] Using AI to improve code readability --- Graphics/Animations/matrix2.bas | 83 +++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/Graphics/Animations/matrix2.bas b/Graphics/Animations/matrix2.bas index d1865cf..2c06f5e 100755 --- a/Graphics/Animations/matrix2.bas +++ b/Graphics/Animations/matrix2.bas @@ -1,89 +1,100 @@ -' Program to render animation inspired by movie. +' Program to render animation inspired by opening scene from The Matrix movie. ' By Svjatoslav Agejenko. ' Email: svjatoslav@svjatoslav.eu ' Homepage: http://www.svjatoslav.eu -' + ' Changelog: ' 2002, Initial version -' 2024.08, Improved program readability using AI +' 2024, Improved program readability using AI DEFINT A-Z -DECLARE SUB PutMatrix () -DIM SHARED array(1 TO 20) -DIM SHARED length -DIM SHARED message$ +DECLARE SUB DisplayMatrix () +DIM SHARED matrixArray(1 TO 20) +DIM SHARED lineLength +DIM SHARED displayMessage$ RANDOMIZE 2 CLS COLOR 10, 0 -message$ = "" -counter = 0 -iteration = 0 -PutMatrix +displayMessage$ = "" +frameCounter = 0 +iterationCount = 0 +DisplayMatrix 1 : ' Label for looping -frequency = 0 -IF iteration >= 3 THEN frequency = 10000: iteration = 0 -SOUND frequency, .2 -counter = counter + 1 -iteration = iteration + 1 -IF counter > 100 THEN PutMatrix: counter = 0 + +' Creates high-pitch pulsing sound by toggling it on and off while iterating +soundFrequency = 0 +IF iterationCount >= 3 THEN soundFrequency = 10000: iterationCount = 0 +SOUND soundFrequency, .2 +iterationCount = iterationCount + 1 + +frameCounter = frameCounter + 1 +IF frameCounter > 100 THEN DisplayMatrix: frameCounter = 0 displayLine$ = "" -lineCounter = 1 +lineIndex = 1 FOR column = 1 TO 80 - lineCounter = lineCounter + 1 - char$ = CHR$(INT(RND * 9) + 48) - IF lineCounter > length THEN lineCounter = 1: char$ = " " - displayLine$ = displayLine$ + char$ + lineIndex = lineIndex + 1 + randomCharacter$ = CHR$(INT(RND * 9) + 48) + IF lineIndex > lineLength THEN lineIndex = 1: randomCharacter$ = " " + displayLine$ = displayLine$ + randomCharacter$ NEXT column LOCATE 25, 1 PRINT displayLine$ IF INKEY$ <> "" THEN COLOR 7, 0: CLS : SYSTEM GOTO 1 -SUB PutMatrix +SUB DisplayMatrix + ' Set the viewport to print from line 1 to line 25 VIEW PRINT 1 TO 25 - SELECT CASE length + + ' Display a message based on the code decoding progress + SELECT CASE lineLength CASE 13 - message$ = "Are you sure the line is clear?" + displayMessage$ = "Are you sure the line is clear?" CASE 6 - message$ = " Then I'll go ..." + displayMessage$ = " Then I'll go ..." END SELECT + ' Clear and print the message at position (1, 30) LOCATE 1, 30 - PRINT " "; + PRINT " " LOCATE 1, 30 - PRINT message$ + PRINT displayMessage$ randomValue = INT(RND * 9) + 1 FOR pass = 1 TO 3 FOR value = randomValue TO 10 - IF array(value) = -1 THEN - array(value) = INT(RND * 8) + 1 - length = length - 1 + IF matrixArray(value) = -1 THEN + ' Assign a random value between 1 and 8 to the array element + matrixArray(value) = INT(RND * 8) + 1 + lineLength = lineLength - 1 GOTO 2 END IF NEXT value + ' Reset randomValue if no valid position is found randomValue = 1 NEXT pass - length = 13 + ' Reset the length and initialize the array + lineLength = 13 FOR index = 1 TO 20 - array(index) = -1 + matrixArray(index) = -1 NEXT index CLS - IF message$ <> "" THEN SYSTEM + IF displayMessage$ <> "" THEN SYSTEM 2 : ' Label for continuing after GOTO FOR index = 1 TO 20 LOCATE 1, index - IF array(index) = -1 THEN displayChar$ = " " ELSE displayChar$ = STR$(array(index)) + ' Display a space if the array element is -1, otherwise display the value + IF matrixArray(index) = -1 THEN displayChar$ = " " ELSE displayChar$ = STR$(matrixArray(index)) displayChar$ = RIGHT$(displayChar$, 1) PRINT displayChar$ NEXT index + ' Set the viewport to print from line 2 to line 25 VIEW PRINT 2 TO 25 END SUB - -- 2.20.1