From: Svjatoslav Agejenko Date: Thu, 15 Aug 2024 11:15:34 +0000 (+0300) Subject: Using AI to improve code readability X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=ab423dc2111e1a7587a7c4a9b671be0ed44db7bc;p=qbasicapps.git Using AI to improve code readability --- diff --git a/Graphics/Spirals/spiral2.bas b/Graphics/Spirals/spiral2.bas index 6cac232..be7e47f 100644 --- a/Graphics/Spirals/spiral2.bas +++ b/Graphics/Spirals/spiral2.bas @@ -6,7 +6,7 @@ DECLARE SUB DrawLine (startX AS DOUBLE, startY AS DOUBLE, endX AS DOUBLE, endY A ' ' Changelog: ' 2003.12, Initial version -' 2024.08, Imroved program readability using AI +' 2024.08, Improved program readability using AI DIM SHARED lineVertexX(1 TO 100) AS DOUBLE DIM SHARED lineVertexY(1 TO 100) AS DOUBLE diff --git a/Graphics/Spirals/spiral4.bas b/Graphics/Spirals/spiral4.bas index f98bff5..583500c 100644 --- a/Graphics/Spirals/spiral4.bas +++ b/Graphics/Spirals/spiral4.bas @@ -5,7 +5,7 @@ ' ' Changelog: ' 2003.12, Initial version -' 2024.08, Imroved program readability using AI +' 2024.08, Improved program readability using AI DIM SHARED spiralX(1 TO 10000) AS SINGLE ' X coordinates of the spiral points DIM SHARED spiralY(1 TO 10000) AS SINGLE ' Y coordinates of the spiral points diff --git a/Graphics/Spirals/spiral6.bas b/Graphics/Spirals/spiral6.bas index d5700ab..9c84465 100644 --- a/Graphics/Spirals/spiral6.bas +++ b/Graphics/Spirals/spiral6.bas @@ -1,50 +1,79 @@ -' spiral -' made by Svjatoslav Agejenko -' in 2003.12 -' H-Page: svjatoslav.eu -' E-Mail: svjatoslav@svjatoslav.eu - -DIM SHARED torux(1 TO 10000) -DIM SHARED toruy(1 TO 10000) -DIM SHARED sinus1(1 TO 10000) -DIM SHARED sinus2(1 TO 10000) -DIM SHARED tor +' Program to render fancy looking spiral with shaded surface. +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 2003.12, Initial version +' 2024.08, Improved program readability using AI + +' Declare shared arrays for storing coordinates and sine values +DIM SHARED spiralX(1 TO 10000) +DIM SHARED spiralY(1 TO 10000) +DIM SHARED sineValue1(1 TO 10000) +DIM SHARED sineValue2(1 TO 10000) + + +' Set the screen mode to 640x480 with 16 colors SCREEN 12 -su = 200 -tor = 0 -FOR a = 1 TO 150 STEP .05 -tor = tor + 1 -su = 150 - a -x = SIN(a) * su * 3 + 320 -y = COS(a) * su + 300 -y = y + (SIN((a + 20) / 10) * (a / 5 + 1)) -sinus1(tor) = SIN(a) -sinus2(tor) = SIN((a + 20) / 10) -torux(tor) = x -toruy(tor) = y -PSET (x, y), 15 -NEXT a - -FOR a = 1 TO tor - 127 -LINE (torux(a), toruy(a))-(torux(a + 126), toruy(a + 126)), 15 - -tee = 1 -IF sinus1(a) > .8 AND sinus2(a) < sinus2(a + 125) THEN tee = 0 -IF sinus1(a) < -.2 AND sinus2(a) - .4 > sinus2(a + 125) THEN tee = 0 -IF tee = 1 THEN LINE (torux(a), toruy(a))-(torux(a + 1), toruy(a + 1)), 15 - -tee = 0 -IF sinus1(a) > .8 AND sinus2(a) > sinus2(a + 125) THEN tee = 1 -IF sinus1(a) < -.2 AND sinus2(a) < sinus2(a + 125) THEN tee = 1 -IF tee = 1 THEN LINE (torux(a), toruy(a))-(torux(a + 127), toruy(a + 127)), 15 - -tee = 0 -IF sinus1(a) > .9 AND sinus2(a) > sinus2(a + 125) THEN tee = 1 -IF sinus1(a) < -.5 AND sinus2(a) < sinus2(a + 125) THEN tee = 1 -IF tee = 1 THEN LINE (torux(a), toruy(a))-(torux(a + 125), toruy(a + 125)), 15 - -NEXT a +' Initialize the spiral rotation parameter +DIM spiralRotation AS SINGLE +spiralRotation = 0 + +' Generate and draw the spiral points +FOR angle = 0 TO 150 STEP .05 + spiralRotation = spiralRotation + 1 + scaleFactor = 150 - angle + + ' Calculate the X and Y coordinates for the current point + spiralX(spiralRotation) = SIN(angle) * scaleFactor * 3 + 320 + spiralY(spiralRotation) = COS(angle) * scaleFactor + 300 + + ' Apply additional vertical displacement based on a secondary sine function + spiralY(spiralRotation) = spiralY(spiralRotation) + (SIN((angle + 20) / 10) * (angle / 5 + 1)) + + ' Store the current sine values for later use + sineValue1(spiralRotation) = SIN(angle) + sineValue2(spiralRotation) = SIN((angle + 20) / 10) + + ' Draw the current point on the screen + PSET (spiralX(spiralRotation), spiralY(spiralRotation)), 15 +NEXT angle + +' Connect the points to form a continuous line +FOR index = 1 TO spiralRotation - 127 + ' Draw a line segment between points 126 steps apart + LINE (spiralX(index), spiralY(index))-(spiralX(index + 126), spiralY(index + 126)), 15 + + ' Initialize the line drawing flag + DIM drawLine AS INTEGER + drawLine = 1 + + ' Check conditions to determine if a line segment should be drawn + IF sineValue1(index) > .8 AND sineValue2(index) < sineValue2(index + 125) THEN drawLine = 0 + IF sineValue1(index) < -.2 AND (sineValue2(index) - .4) > sineValue2(index + 125) THEN drawLine = 0 + + ' Draw a line segment if the conditions are met + IF drawLine = 1 THEN LINE (spiralX(index), spiralY(index))-(spiralX(index + 1), spiralY(index + 1)), 15 + + ' Reset the line drawing flag and check for different conditions + drawLine = 0 + IF sineValue1(index) > .8 AND sineValue2(index) > sineValue2(index + 125) THEN drawLine = 1 + IF sineValue1(index) < -.2 AND sineValue2(index) < sineValue2(index + 125) THEN drawLine = 1 + + ' Draw a line segment if the conditions are met + IF drawLine = 1 THEN LINE (spiralX(index), spiralY(index))-(spiralX(index + 127), spiralY(index + 127)), 15 + + ' Reset the line drawing flag and check for another set of conditions + drawLine = 0 + IF sineValue1(index) > .9 AND sineValue2(index) > sineValue2(index + 125) THEN drawLine = 1 + IF sineValue1(index) < -.5 AND sineValue2(index) < sineValue2(index + 125) THEN drawLine = 1 + + ' Draw a line segment if the conditions are met + IF drawLine = 1 THEN LINE (spiralX(index), spiralY(index))-(spiralX(index + 125), spiralY(index + 125)), 15 +NEXT index + +' Wait for a key press before exiting a$ = INPUT$(1) -SYSTEM