From a56103559ceab50e04b8c02b5e059f1c08eea1c2 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sat, 17 Aug 2024 00:28:46 +0300 Subject: [PATCH] Using AI to improve code readability --- Graphics/Spirals/spiral7.bas | 135 ++++++++++++++++++++--------------- 1 file changed, 79 insertions(+), 56 deletions(-) diff --git a/Graphics/Spirals/spiral7.bas b/Graphics/Spirals/spiral7.bas index 3e14472..f820839 100644 --- a/Graphics/Spirals/spiral7.bas +++ b/Graphics/Spirals/spiral7.bas @@ -1,65 +1,88 @@ -' 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 +' 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, Improved program readability using AI + +' Declare shared arrays to hold the x and y coordinates of the spiral +DIM SHARED spiralX(1 TO 10000) +DIM SHARED spiralY(1 TO 10000) + +' Initialize the screen to a graphics mode with 640x480 resolution and 16 colors SCREEN 12 -su = 200 -tor = 0 -FOR a = 0 TO 97.35 STEP .15 -tor = tor + 1 -su = SIN(a / 31) * 100 -x = SIN(a) * su * 3 + 320 -y = COS(a) * su + 250 -y = y - (COS(a / 31) * 200) -torux(tor) = x -toruy(tor) = y -PSET (x, y), 15 -NEXT a -FOR a = 97.35 TO 0 STEP -.15 -tor = tor + 1 -su = SIN(a / 31) * 50 -x = SIN(a) * su * 3 + 320 -y = COS(a) * su + 350 -y = y - (COS(a / 31) * 100) -torux(tor) = x -toruy(tor) = y -PSET (x, y), 15 -NEXT a +' Constants for the initial size and the starting value of the index +CONST InitialSize = 100 +CONST StartIndex = 0 + +' Variable to keep track of the current position in the spiral arrays +DIM torusIndex AS DOUBLE +torusIndex = StartIndex + +' Loop parameters +DIM angle AS DOUBLE +DIM scaleFactor AS DOUBLE + +' Generate the first arm of the spiral +FOR angle = 0 TO 97.35 STEP .15 + torusIndex = torusIndex + 1 + scaleFactor = SIN(angle / 31) * InitialSize + spiralX(torusIndex) = SIN(angle) * scaleFactor * 3 + 320 + spiralY(torusIndex) = COS(angle) * scaleFactor + 250 + spiralY(torusIndex) = spiralY(torusIndex) - (COS(angle / 31) * 200) + PSET (spiralX(torusIndex), spiralY(torusIndex)), 15 +NEXT angle + +' Generate the second arm of the spiral +FOR angle = 97.35 TO 0 STEP -.15 + torusIndex = torusIndex + 1 + scaleFactor = SIN(angle / 31) * (InitialSize / 2) + spiralX(torusIndex) = SIN(angle) * scaleFactor * 3 + 320 + spiralY(torusIndex) = COS(angle) * scaleFactor + 350 + spiralY(torusIndex) = spiralY(torusIndex) - (COS(angle / 31) * 100) + PSET (spiralX(torusIndex), spiralY(torusIndex)), 15 +NEXT angle -FOR a = 0 TO 97.35 STEP .15 -tor = tor + 1 -su = SIN(a / 31) * 25 -x = SIN(a) * su * 3 + 320 -y = COS(a) * su + 300 -y = y - (COS(a / 31) * 50) -torux(tor) = x -toruy(tor) = y -PSET (x, y), 15 -NEXT a +' Generate the third arm of the spiral +FOR angle = 0 TO 97.35 STEP .15 + torusIndex = torusIndex + 1 + scaleFactor = SIN(angle / 31) * (InitialSize / 4) + spiralX(torusIndex) = SIN(angle) * scaleFactor * 3 + 320 + spiralY(torusIndex) = COS(angle) * scaleFactor + 300 + spiralY(torusIndex) = spiralY(torusIndex) - (COS(angle / 31) * 50) + PSET (spiralX(torusIndex), spiralY(torusIndex)), 15 +NEXT angle -FOR a = 97.35 TO 0 STEP -.15 -tor = tor + 1 -su = SIN(a / 31) * 12.5 -x = SIN(a) * su * 3 + 320 -y = COS(a) * su + 325 -y = y - (COS(a / 31) * 25) -torux(tor) = x -toruy(tor) = y -PSET (x, y), 15 -NEXT a +' Generate the fourth arm of the spiral +FOR angle = 97.35 TO 0 STEP -.15 + torusIndex = torusIndex + 1 + scaleFactor = SIN(angle / 31) * (InitialSize / 8) + spiralX(torusIndex) = SIN(angle) * scaleFactor * 3 + 320 + spiralY(torusIndex) = COS(angle) * scaleFactor + 325 + spiralY(torusIndex) = spiralY(torusIndex) - (COS(angle / 31) * 25) + PSET (spiralX(torusIndex), spiralY(torusIndex)), 15 +NEXT angle -zzx = (tor - 42) / 4 +' Calculate the number of lines to draw based on the current index +DIM totalSegments AS DOUBLE +totalSegments = (torusIndex - 42) / 4 + +a$ = INPUT$(1) +' Clear the screen before drawing the lines CLS -FOR a = 1 TO zzx * 4 -LINE (torux(a), toruy(a))-(torux(a + 42), toruy(a + 42)), 15 -LINE (torux(a), toruy(a))-(torux(a + 1), toruy(a + 1)), 15 -NEXT a + +' Draw the lines between points in the spiral +FOR angle = 1 TO totalSegments * 4 + LINE (spiralX(angle), spiralY(angle))-(spiralX(angle + 42), spiralY(angle + 42)), 15 + LINE (spiralX(angle), spiralY(angle))-(spiralX(angle + 1), spiralY(angle + 1)), 15 +NEXT angle + +' Wait for the user to press a key before exiting a$ = INPUT$(1) + +' End of program SYSTEM -- 2.20.1