From: Svjatoslav Agejenko Date: Thu, 15 Aug 2024 06:53:33 +0000 (+0300) Subject: Using AI to improve code readability X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=4b52c0413a98cc5c5f8b1694b976192ddb15cc38;p=qbasicapps.git Using AI to improve code readability --- diff --git a/Graphics/Spirals/spiral2.bas b/Graphics/Spirals/spiral2.bas index a127ddb..6cac232 100644 --- a/Graphics/Spirals/spiral2.bas +++ b/Graphics/Spirals/spiral2.bas @@ -1,40 +1,56 @@ -' spiral -' made by Svjatoslav Agejenko -' in 2003.12 -' H-Page: svjatoslav.eu -' E-Mail: svjatoslav@svjatoslav.eu - -DECLARE SUB linem (x1!, y1!, x2!, y2!, col!) -DIM SHARED linevx(1 TO 100) -DIM SHARED linevy(1 TO 100) -DIM SHARED z -DIM SHARED zz +DECLARE SUB DrawLine (startX AS DOUBLE, startY AS DOUBLE, endX AS DOUBLE, endY AS DOUBLE, col AS INTEGER) +' Program to render fancy looking spiral. +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 2003.12, Initial version +' 2024.08, Imroved program readability using AI + +DIM SHARED lineVertexX(1 TO 100) AS DOUBLE +DIM SHARED lineVertexY(1 TO 100) AS DOUBLE +DIM SHARED depth AS INTEGER +DIM SHARED tempDepth AS INTEGER SCREEN 12 -su = 200 -z = 0 -FOR a = 1 TO 30 STEP .1 -su = (30 - a) * 7 -x = SIN(a) * su + 200 -y = COS(a) * su + 200 -zz = a -linem x + (x / 2) + (a * 3), (y - (x / 3)) + (a * 3), x + 25, y + 25 - (a * 3), z -z = 15 -NEXT a -a$ = INPUT$(1) -SYSTEM +' Initialize the scale factor for the spiral +spiralScaleFactor = 200 +depth = 0 -SUB linem (x1, y1, x2, y2, col) -x3 = (x2 - x1) / zz -y3 = (y2 - y1) / zz +' Generate the spiral by iterating through angles and scaling appropriately +FOR angle = 1 TO 30 STEP .1 + ' Calculate the current scale based on the remaining distance to the center + spiralScaleFactor = (30 - angle) * 7 + ' Convert polar coordinates to cartesian for the current point + xPosition = SIN(angle) * spiralScaleFactor + 200 + yPosition = COS(angle) * spiralScaleFactor + 200 + ' Store the current depth (z-axis value) + tempDepth = angle + ' Draw a line from the previous point to the current point with a color based on depth + DrawLine xPosition + (xPosition / 2) + (angle * 3), (yPosition - (xPosition / 3)) + (angle * 3), xPosition + 25, yPosition + 25 - (angle * 3), depth + ' Set the color for the next segment + depth = 15 +NEXT angle -FOR a = 1 TO zz -IF linevx(a) > 0 THEN LINE (linevx(a), linevy(a))-(x1, y1), col -linevx(a) = x1 -linevy(a) = y1 -x1 = x1 + x3 -y1 = y1 + y3 -LINE (linevx(a), linevy(a))-(x1, y1), col -NEXT a -END SUB +' Wait for user input to close the program +userInput$ = INPUT$(1) +SUB DrawLine (startX AS DOUBLE, startY AS DOUBLE, endX AS DOUBLE, endY AS DOUBLE, col AS INTEGER) + ' Calculate the step increments for x and y based on the depth + deltaX = (endX - startX) / tempDepth + deltaY = (endY - startY) / tempDepth + + FOR segmentIndex = 1 TO tempDepth + ' If there is a previous vertex, draw a line to the new starting point + IF lineVertexX(segmentIndex) > 0 THEN LINE (lineVertexX(segmentIndex), lineVertexY(segmentIndex))-(startX, startY), col + ' Store the current starting point as the next vertex + lineVertexX(segmentIndex) = startX + lineVertexY(segmentIndex) = startY + ' Increment the starting point by the calculated deltas + startX = startX + deltaX + startY = startY + deltaY + ' Draw a line from the stored vertex to the new starting point + LINE (lineVertexX(segmentIndex), lineVertexY(segmentIndex))-(startX, startY), col + NEXT segmentIndex +END SUB diff --git a/Graphics/Spirals/spiral4.bas b/Graphics/Spirals/spiral4.bas index 3431132..f98bff5 100644 --- a/Graphics/Spirals/spiral4.bas +++ b/Graphics/Spirals/spiral4.bas @@ -1,30 +1,43 @@ -' 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 tor -SCREEN 12 -su = 200 -tor = 0 -FOR a = 1 TO 100 STEP .05 -tor = tor + 1 -su = 100 - a -x = SIN(a) * su * 3 + 320 -y = COS(a) * su + 300 -y = y + (SIN((a + 20) / 10) * a) -torux(tor) = x -toruy(tor) = y -PSET (x, y), 15 -NEXT a - -FOR a = 1 TO tor - 125 -LINE (torux(a), toruy(a))-(torux(a + 125), toruy(a + 125)), 15 -NEXT a +' Program to render fancy looking spiral. +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 2003.12, Initial version +' 2024.08, Imroved program readability using AI -a$ = INPUT$(1) -SYSTEM +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 +DIM SHARED pointCount AS INTEGER ' Total number of points plotted +SCREEN 12 ' Set screen resolution to 640x480 with 16 colors + +' Initialize the scale factor for the spiral +scaleFactor = 200 +pointCount = 0 + +' Calculate and plot each point on the spiral +FOR angle = 1 TO 100 STEP .05 + pointCount = pointCount + 1 + scaleFactor = 100 - angle ' Update the scaling factor as the loop progresses + + ' Calculate the X and Y coordinates based on the sine and cosine of the angle + spiralX(pointCount) = SIN(angle) * scaleFactor * 3 + 320 + spiralY(pointCount) = COS(angle) * scaleFactor + 300 + ' Apply a vertical displacement to create a more dynamic effect + spiralY(pointCount) = spiralY(pointCount) + (SIN((angle + 20) / 10) * angle) + + ' Plot the point on the screen + PSET (spiralX(pointCount), spiralY(pointCount)), 15 +NEXT angle + +' Draw lines between points to create the spiral effect +FOR segmentStart = 1 TO pointCount - 125 + LINE (spiralX(segmentStart), spiralY(segmentStart)) - _ + (spiralX(segmentStart + 125), spiralY(segmentStart + 125)), 15 +NEXT segmentStart + +' Wait for user input before exiting +a$ = INPUT$(1) +END ' Exit the program