From b4fa86cfee02b55ab70bdc99b5efe438dfa4a293 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sat, 26 Oct 2024 10:25:53 +0300 Subject: [PATCH] Using AI to improve code readability --- Graphics/Animations/mkcircle.bas | 223 ++++++++++++++++--------------- 1 file changed, 115 insertions(+), 108 deletions(-) diff --git a/Graphics/Animations/mkcircle.bas b/Graphics/Animations/mkcircle.bas index 76b3f6b..6646bee 100755 --- a/Graphics/Animations/mkcircle.bas +++ b/Graphics/Animations/mkcircle.bas @@ -1,20 +1,29 @@ -' Svjatoslav Agejenko svjatoslav@svjatoslav.eu -' 2003.10 - - -DECLARE SUB textpage () -DECLARE SUB mkcircle () -DECLARE SUB mklines () -DECLARE SUB disp () -DECLARE SUB fill () +' Program to render fancy looking text mode animations. +' Various effects are overlaid on top of each other +' while program scrolls it's own source code in the background. +' +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 2003.10, Initial version +' 2024, Improved program readability using AI + +DECLARE SUB displayScreen () +DECLARE SUB drawCircle () +DECLARE SUB drawLines () +DECLARE SUB fillBuffer () +DECLARE SUB updateDisplay () DIM SHARED pi -DIM SHARED an -DIM SHARED frm -DIM SHARED buf2(1 TO 50, 1 TO 80) AS STRING * 1 -DIM SHARED buf(1 TO 50, 1 TO 80) AS STRING * 1 -DIM SHARED col(1 TO 50, 1 TO 80) AS INTEGER +DIM SHARED angle +DIM SHARED frameCounter +DIM SHARED buffer2(1 TO 50, 1 TO 80) AS STRING * 1 +DIM SHARED buffer(1 TO 50, 1 TO 80) AS STRING * 1 +DIM SHARED colors(1 TO 50, 1 TO 80) AS INTEGER -DIM SHARED vl, hl, vls, hls +DIM SHARED verticalLinePosition, horizontalLinePosition +DIM SHARED verticalLineSpeed, horizontalLineSpeed WIDTH 80, 50 VIEW PRINT 1 TO 50 @@ -23,172 +32,170 @@ OPEN "mkcircle.bas" FOR INPUT AS #1 CLS -hl = 20 -hls = 1 -vl = 20 -vls = 1 +horizontalLinePosition = 20 +horizontalLineSpeed = 1 +verticalLinePosition = 20 +verticalLineSpeed = 1 1 -frm = frm + 1 +frameCounter = frameCounter + 1 -textpage -fill -mklines -mkcircle -disp +displayScreen +fillBuffer +drawLines +drawCircle +updateDisplay IF INKEY$ <> "" THEN GOTO 2 GOTO 1 2 CLOSE #1 SYSTEM -SUB disp +SUB updateDisplay +' This subroutine updates the display with the contents of the buffer COLOR 7, 0 LOCATE 1, 1 FOR y = 1 TO 50 FOR x = 1 TO 80 - COLOR col(y, x) - PRINT buf(y, x); - buf(y, x) = buf2(y, x) - col(y, x) = 4 + COLOR colors(y, x) + PRINT buffer(y, x); + ' Swap the contents of buffer and buffer2 + buffer(y, x) = buffer2(y, x) + colors(y, x) = 4 NEXT x NEXT y END SUB -SUB fill +SUB fillBuffer +' This subroutine fills the buffer with a pattern COLOR 4, 0 -siz = SIN(frm / 7) + 1.1 +sizeMultiplier = SIN(frameCounter / 7) + 1.1 -an = an + SIN(frm / 30) / 10 -rsx = 50 - SIN(an + pi / 4) * 12 * 20 * siz -rsy = 50 - COS(an + pi / 4) * 12 * 20 * siz +angle = angle + SIN(frameCounter / 30) / 10 +radiusXPosition = 50 - SIN(angle + pi / 4) * 12 * 20 * sizeMultiplier +radiusYPosition = 50 - COS(angle + pi / 4) * 12 * 20 * sizeMultiplier -sxp = SIN(an) * 6 * siz -syp = COS(an) * 6 * siz -rsxp = SIN(an + pi / 2) * 6 * siz -rsyp = COS(an + pi / 2) * 6 * siz +stepXPosition = SIN(angle) * 6 * sizeMultiplier +stepYPosition = COS(angle) * 6 * sizeMultiplier +radiusStepXPosition = SIN(angle + pi / 2) * 6 * sizeMultiplier +radiusStepYPosition = COS(angle + pi / 2) * 6 * sizeMultiplier FOR y = 1 TO 50 -rsx = rsx + rsxp -rsy = rsy + rsyp + radiusXPosition = radiusXPosition + radiusStepXPosition + radiusYPosition = radiusYPosition + radiusStepYPosition 4 -IF rsx > 100 THEN rsx = rsx - 100: GOTO 4 -IF rsx < 0 THEN rsx = rsx + 100: GOTO 4 -IF rsy > 100 THEN rsy = rsy - 100: GOTO 4 -IF rsy < 0 THEN rsy = rsy + 100: GOTO 4 +IF radiusXPosition > 100 THEN radiusXPosition = radiusXPosition - 100: GOTO 4 +IF radiusXPosition < 0 THEN radiusXPosition = radiusXPosition + 100: GOTO 4 +IF radiusYPosition > 100 THEN radiusYPosition = radiusYPosition - 100: GOTO 4 +IF radiusYPosition < 0 THEN radiusYPosition = radiusYPosition + 100: GOTO 4 -sx = rsx -sy = rsy +currentXPosition = radiusXPosition +currentYPosition = radiusYPosition FOR x = 1 TO 80 - c = 0 - sx = sx + sxp - sy = sy + syp - + characterCode = 0 + currentXPosition = currentXPosition + stepXPosition + currentYPosition = currentYPosition + stepYPosition + 3 - IF sx > 100 THEN sx = sx - 100: GOTO 3 - IF sx < 0 THEN sx = sx + 100: GOTO 3 - IF sy > 100 THEN sy = sy - 100: GOTO 3 - IF sy < 0 THEN sy = sy + 100: GOTO 3 +IF currentXPosition > 100 THEN currentXPosition = currentXPosition - 100: GOTO 3 +IF currentXPosition < 0 THEN currentXPosition = currentXPosition + 100: GOTO 3 +IF currentYPosition > 100 THEN currentYPosition = currentYPosition - 100: GOTO 3 +IF currentYPosition < 0 THEN currentYPosition = currentYPosition + 100: GOTO 3 - IF sx < 12 OR sy < 12 THEN buf(y, x) = "*": col(y, x) = 9 - NEXT x +IF currentXPosition < 12 OR currentYPosition < 12 THEN buffer(y, x) = "*": colors(y, x) = 9 +NEXT x NEXT y END SUB -SUB mkcircle -cs = (SIN(frm / 10) + 1.01) * 30 -cy = SIN(frm / 12) * 30 + 40 -cx = COS(frm / 17) * 15 + 25 +SUB drawCircle +' This subroutine draws a circle on the screen +circleSize = (SIN(frameCounter / 10) + 1.01) * 30 +circleYPosition = SIN(frameCounter / 12) * 30 + 40 +circleXPosition = COS(frameCounter / 17) * 15 + 25 FOR y = 1 TO 50 -xp = SIN(y / 5 + frm / 30) * cs / 10 - -IF (y >= cy - cs) AND (y <= cy + cs) THEN + xPositionOffset = SIN(y / 5 + frameCounter / 30) * circleSize / 10 -h1 = SQR((y - (cy - cs)) * ((cy + cs) - y)) -IF (y >= cy - cs / 2) AND (y <= cy + cs / 2) THEN h2 = SQR((y - (cy - cs / 2)) * ((cy + cs / 2) - y)) ELSE h2 = 0 +IF (y >= circleYPosition - circleSize) AND (y <= circleYPosition + circleSize) THEN +halfHeight1 = SQR((y - (circleYPosition - circleSize)) * ((circleYPosition + circleSize) - y)) +IF (y >= circleYPosition - circleSize / 2) AND (y <= circleYPosition + circleSize / 2) THEN halfHeight2 = SQR((y - (circleYPosition - circleSize / 2)) * ((circleYPosition + circleSize / 2) - y)) ELSE halfHeight2 = 0 -s = cx - h1 + xp -IF s < 1 THEN s = 1 -e = cx - h2 + xp -IF e > 80 THEN e = 80 +startXPosition = circleXPosition - halfHeight1 + xPositionOffset +IF startXPosition < 1 THEN startXPosition = 1 +endXPosition = circleXPosition - halfHeight2 + xPositionOffset +IF endXPosition > 80 THEN endXPosition = 80 -FOR x = s TO e -buf(y, x) = CHR$(RND * 40 + 48) -col(y, x) = RND * 15 +FOR x = startXPosition TO endXPosition + buffer(y, x) = CHR$(RND * 40 + 48) + colors(y, x) = RND * 15 NEXT x +startXPosition = circleXPosition + halfHeight2 + xPositionOffset +IF startXPosition < 1 THEN startXPosition = 1 +endXPosition = circleXPosition + halfHeight1 + xPositionOffset +IF endXPosition > 80 THEN endXPosition = 80 -s = cx + h2 + xp -IF s < 1 THEN s = 1 -e = cx + h1 + xp -IF e > 80 THEN e = 80 - -FOR x = s TO e -buf(y, x) = CHR$(RND * 200 + 32) -col(y, x) = RND * 15 +FOR x = startXPosition TO endXPosition + buffer(y, x) = CHR$(RND * 200 + 32) + colors(y, x) = RND * 15 NEXT x END IF - NEXT y - - END SUB -SUB mklines -vl = vl + vls -IF vl > 49 THEN vls = -1 -IF vl < 2 THEN vls = 1 +SUB drawLines +' This subroutine draws vertical and horizontal lines on the screen +verticalLinePosition = verticalLinePosition + verticalLineSpeed +IF verticalLinePosition > 49 THEN verticalLineSpeed = -1 +IF verticalLinePosition < 2 THEN verticalLineSpeed = 1 -hl = hl + hls -IF hl > 79 THEN hls = -1 -IF hl < 2 THEN hls = 1 +horizontalLinePosition = horizontalLinePosition + horizontalLineSpeed +IF horizontalLinePosition > 79 THEN horizontalLineSpeed = -1 +IF horizontalLinePosition < 2 THEN horizontalLineSpeed = 1 FOR x = 1 TO 80 - IF buf(vl, x) = "*" THEN c = 31 ELSE c = 10 - buf(vl, x) = "#" - col(vl, x) = c + IF buffer(verticalLinePosition, x) = "*" THEN characterCode = 31 ELSE characterCode = 10 + buffer(verticalLinePosition, x) = "#" + colors(verticalLinePosition, x) = characterCode NEXT x FOR y = 1 TO 50 - IF buf(y, hl) = "*" THEN c = 31 ELSE c = 10 - buf(y, hl) = "#" - col(y, hl) = c + IF buffer(y, horizontalLinePosition) = "*" THEN characterCode = 31 ELSE characterCode = 10 + buffer(y, horizontalLinePosition) = "#" + colors(y, horizontalLinePosition) = characterCode NEXT y END SUB -SUB textpage +SUB displayScreen +' This subroutine displays the text from a file on the screen IF EOF(1) <> 0 THEN CLOSE 1 OPEN "mkcircle.bas" FOR INPUT AS #1 END IF -LINE INPUT #1, a$ +LINE INPUT #1, lineText$ FOR y = 1 TO 49 FOR x = 1 TO 80 - buf2(y, x) = buf2(y + 1, x) + buffer2(y, x) = buffer2(y + 1, x) NEXT x NEXT y FOR x = 1 TO 80 - buf2(50, x) = " " + buffer2(50, x) = " " NEXT x -IF LEN(a$) > 80 THEN a$ = LEFT$(a$, 80) -FOR b = 1 TO LEN(a$) - c$ = RIGHT$(LEFT$(a$, b), 1) - buf2(50, b) = c$ +IF LEN(lineText$) > 80 THEN lineText$ = LEFT$(lineText$, 80) +FOR b = 1 TO LEN(lineText$) + character$ = RIGHT$(LEFT$(lineText$, b), 1) + buffer2(50, b) = character$ NEXT b - - END SUB - -- 2.20.1