From 03f14809dfbda081d4733ff78f182fe8e1aca16e Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Wed, 23 Oct 2024 19:46:38 +0300 Subject: [PATCH] Using AI to improve code readability --- Graphics/Presentations/christmas.bas | 129 +++++++++++++++++++++------ 1 file changed, 103 insertions(+), 26 deletions(-) diff --git a/Graphics/Presentations/christmas.bas b/Graphics/Presentations/christmas.bas index e6fbfac..f0f9b3e 100755 --- a/Graphics/Presentations/christmas.bas +++ b/Graphics/Presentations/christmas.bas @@ -3,65 +3,89 @@ DECLARE SUB turnon () DECLARE SUB ellips (x!, y!, s!, v!, t!) DECLARE SUB prn (x!, y!, msg$, siz!, col1!) DECLARE SUB timerAdd (element!, time!, value!) -DECLARE SUB timerdisp () DECLARE SUB timerinit () DECLARE SUB timerprocess () DECLARE SUB mo (x!, y!, an!, s!, w!) + +' Shared variables for global state DIM SHARED depth DIM SHARED pi +' Variables to store shapes and timers DIM SHARED sh1, sh2, sv1, sv2, hp, vp DIM SHARED timerTime(0 TO 50, 0 TO 100) DIM SHARED timerValue(0 TO 50, 0 TO 100) +' Variables to store current timer states DIM SHARED timerCplace(0 TO 50) DIM SHARED timerCtime(0 TO 50) DIM SHARED timerCvalue(0 TO 50) DIM SHARED timerLast +' Initialize pi with a constant value pi = 3.14128 +' Turn on the screen and initialize timers turnon +' Set up graphics mode SCREEN 7, , , 1 +' Initialize the timer system timerinit + +' Main loop variable s = 50 + ' Main loop label 2 + +' Calculate sine and cosine values for animation s1 = SIN(timerCvalue(1) * 1.3) * .5 + 1.1 s2 = COS(timerCvalue(1) * 1.3) * .5 + 1.1 +' Increment frame counter frm = frm + 1 + +' Calculate shape sizes and positions sv1 = 5 * s1 sv2 = 2 vp = SIN(timerCvalue(1) * 1.3) - sh1 = 2 * s2 sh2 = 1.4 hp = SIN(timerCvalue(1)) * .7 -' Draw main object +' Draw the main object mo timerCvalue(2), timerCvalue(3), timerCvalue(4), timerCvalue(0), 0 ' Draw ellipses ellips 100, timerCvalue(6), timerCvalue(7) + 4, 14, .5 ellips 100, timerCvalue(6), timerCvalue(7) + 2, 10, .5 ellips 100, timerCvalue(6), timerCvalue(7), 0, .5 -prn timerCvalue(5), 10, "KHK", 7, 250 ' Print messages +prn timerCvalue(5), 10, "KHK", 7, 250 prn timerCvalue(8), 130, "Infotehno-", 2, 0 prn timerCvalue(8), 150, " loogia", 2, 0 +' Process the timers timerprocess + LOCATE 1, 1 -'PRINT timerCtime(0) + +' Check if the main loop should exit IF timerCtime(0) > 26 THEN SYSTEM + +' Make off-screen buffer visible PCOPY 0, 1 + +' Clear off-screen buffer with white background color in preparation to draw new frame LINE (0, 0)-(319, 199), 15, BF + +' Go back to the main loop GOTO 2 +' Subroutine to draw an ellipse SUB ellips (x!, y!, s!, v!, t!) ' Draw an ellipse if x and y are positive IF x > 0 THEN @@ -72,7 +96,15 @@ SUB ellips (x!, y!, s!, v!, t!) END IF END SUB +' Subroutine to draw animated fractal SUB mo (x!, y!, an!, s!, w!) + ' variables + ' w - indicates fractal branch direction + ' s - fractal fragment current size + ' an - fractal twist angle + ' x and y - fractal fragment current position + + ' Increment fragment depth counter depth = depth + 1 ' If size is less than .2, skip drawing @@ -81,9 +113,11 @@ SUB mo (x!, y!, an!, s!, w!) ' Determine color based on depth IF depth / 2 = depth \ 2 THEN c = 1 ELSE c = 3 + ' Draw the circle and fill it with the determined color CIRCLE (x!, y!), s!, c PAINT (x!, y!), c + ' Recursively draw child objects of the fractal if w is not equal to 1 IF w <> 1 THEN x1 = SIN(an!) * s! * 2.5 + x! y1 = COS(an!) * s! * 2.5 + y! @@ -94,6 +128,7 @@ SUB mo (x!, y!, an!, s!, w!) mo x1, y1, an! + vp, ns, 3 END IF + ' Recursively draw child objects if w is not equal to 2 IF w <> 2 THEN x1 = SIN(an! - pi / 2) * s! * 2.5 + x! y1 = COS(an! - pi / 2) * s! * 2.5 + y! @@ -104,6 +139,7 @@ SUB mo (x!, y!, an!, s!, w!) mo x1, y1, an! + hp, ns, 4 END IF + ' Recursively draw child objects if w is not equal to 3 IF w <> 3 THEN x1 = SIN(an! - pi) * s! * 2.5 + x! y1 = COS(an! - pi) * s! * 2.5 + y! @@ -114,6 +150,7 @@ SUB mo (x!, y!, an!, s!, w!) mo x1, y1, an! + vp, ns, 1 END IF + ' Recursively draw child objects if w is not equal to 4 IF w <> 4 THEN x1 = SIN(an! - pi * 1.5) * s! * 2.5 + x! y1 = COS(an! - pi * 1.5) * s! * 2.5 + y! @@ -125,30 +162,40 @@ SUB mo (x!, y!, an!, s!, w!) END IF 1 + ' Decrement depth counter depth = depth - 1 END SUB +' Subroutine to print a message on the screen SUB prn (x!, y!, msg$, siz!, col1!) + ' Check if x is out of bounds IF x < 0 THEN GOTO prn1 IF x > 319 THEN GOTO prn1 + ' Buffer to save a portion of the screen DIM bck(10000) ' Save a portion of the screen to buffer GET (0, 0)-(100, 7), bck + ' Print the message on the screen LOCATE 1, 1 PRINT msg$ + ' Determine the color for the text col = col1! + ' Loop through each character in the message FOR x1 = 0 TO LEN(msg$) * 8 - 1 + ' Loop through each pixel in the character FOR y1 = 0 TO 7 + ' Check if the pixel is part of the character IF POINT(x1, y1) > 0 THEN - ' Calculate the coordinates for the enlarged character + ' Calculate the coordinates for the enlarged pixel rx = x1 * siz! + x! ry = y1 * siz! + y! + ' Draw the pixel based on the color value IF col1! > 100 THEN col = RND * 4 + 10 @@ -168,46 +215,43 @@ SUB prn (x!, y!, msg$, siz!, col1!) prn1: END SUB +' Subroutine to add a timer element SUB timerAdd (element!, time!, value!) + ' Loop through each element in the timer array FOR a = 0 TO 100 + ' Check if the current element is empty IF (timerTime(element!, a) = 0) AND (timerValue(element!, a) = 0) THEN GOTO timer3 NEXT a timer3: + ' Add the new timer element timerTime(element!, a) = time! timerValue(element!, a) = value! END SUB -SUB timerdisp - LOCATE 1, 1 - - ' Display the current state of timers - FOR a = 0 TO 10 - PRINT timerCplace(a), timerCtime(a), timerCvalue(a) - NEXT a - -END SUB - +' Subroutine to initialize the timer system SUB timerinit + ' Store the current time timerLast = TIMER + ' Set the pause duration paus = 24 - ' Initialize stuff size + ' Initialize size values timerAdd 0, 0, 50 timerAdd 0, 7, 10 timerAdd 0, 20, 10 timerAdd 0, 24, 0 timerAdd 0, 1000, 0 - ' Initialize stuff speed + ' Initialize speed values timerAdd 1, 0, .1 timerAdd 1, 1000, 1000 - ' Initialize stuff X & Y + ' Initialize X & Y positions timerAdd 2, 0, 160 timerAdd 3, 0, 100 @@ -226,14 +270,13 @@ SUB timerinit timerAdd 2, 1000, 40 timerAdd 3, 1000, 160 - ' Initialize stuff rotations + ' Initialize rotation values timerAdd 4, 0, .1 timerAdd 4, 10, .1 timerAdd 4, 22, 18 timerAdd 4, 2000, 10000 - ' Initialize KHK message X - + ' Initialize KHK message X position timerAdd 5, 0, -1 timerAdd 5, 5, -1 timerAdd 5, 9, 50 @@ -241,7 +284,7 @@ SUB timerinit timerAdd 5, paus, 30 timerAdd 5, paus + 2, 321 - ' Initialize Ellips Y & radius + ' Initialize ellips Y & radius timerAdd 6, 0, -1 timerAdd 6, 4, -1 timerAdd 6, 10, 30 @@ -254,8 +297,7 @@ SUB timerinit timerAdd 7, paus, 130 timerAdd 7, paus + 2, 1 - ' Initialize "Infotehnoloogia" message - + ' Initialize "Infotehnoloogia" message X position timerAdd 8, 0, 320 timerAdd 8, 11, 320 timerAdd 8, 20, 100 @@ -264,39 +306,56 @@ SUB timerinit END SUB +' Subroutine to process the timers SUB timerprocess + ' Store the current time timerCurrent = TIMER + + ' Calculate the time difference since last frame timerDiff = timerCurrent - timerLast + + ' Update the last frame time timerLast = timerCurrent + ' Loop through each timer element FOR a = 0 TO 50 + ' Calculate the current time and value of each element ctim = timerCtime(a) + timerDiff Cplace = timerCplace(a) + timer2: + ' Check if the next timer element is empty IF timerTime(a, Cplace + 1) = -1 THEN + ' Reset the current time and value ctim = 0 Cplace = 0 END IF ' Update the current time and value of each element IF timerTime(a, Cplace + 1) < ctim THEN + ' Check if the next timer element is empty IF timerTime(a, Cplace + 1) = 0 THEN + ' Set the current value to the current timer value timerCvalue(a) = timerValue(a, Cplace) GOTO timer1 END IF + ' Move to the next timer element Cplace = Cplace + 1 GOTO timer2 END IF + ' Interpolate the current value based on time difference v1 = timerValue(a, Cplace) t1 = timerTime(a, Cplace) v2 = timerValue(a, Cplace + 1) t2 = timerTime(a, Cplace + 1) IF v1 = v2 THEN + ' Set the current value to the first value timerCvalue(a) = v1 ELSE + ' Calculate the time difference and value difference Tdiff1 = t2 - t1 Tdiff2 = ctim - t1 Vdiff = v2 - v1 @@ -304,26 +363,35 @@ timer2: ' Interpolate the current value timerCvalue(a) = Tdiff2 / Tdiff1 * Vdiff + v1 END IF + timer1: + ' Update the current place and time of each element timerCplace(a) = Cplace timerCtime(a) = ctim NEXT a END SUB +' Subroutine to turn on the screen SUB turnon + ' Set up graphics mode SCREEN 7, , , 1 + ' Draw initial shapes FOR x = 0 TO 160 STEP 15 LINE (160 - x - 5, 90 - 5)-(160 + x + 5, 110 + 5), 1, BF LINE (160 - x - 3, 90 - 3)-(160 + x + 3, 110 + 3), 3, BF LINE (160 - x, 90)-(160 + x, 110), 15, BF + ' Copy screen buffer and clear the screen PCOPY 0, 1 CLS + + ' use sound function to create delay, to limit animation speed SOUND 0, .5 NEXT x + ' Draw additional shapes FOR y = 10 TO 100 STEP 15 CLS @@ -335,22 +403,30 @@ SUB turnon SOUND 0, .5 NEXT y + ' Draw zeroes and ones at random locations for decoration FOR a = 1 TO 25 prn RND * 250, RND * 180, STR$(INT(RND * 2)), 3, 0 + + ' Copy screen buffer and clear the screen PCOPY 0, 1 + + ' use sound function to create delay, to limit animation speed SOUND 0, 1 NEXT a + ' Buffer to save parts of the screen DIM buf(1 TO 1000) + ' Shift parts of the screen randomly FOR b = 1 TO 30 FOR a = 0 TO 195 t = ABS(100 - a) + ' Check if a random condition is met IF RND * 50 < t THEN GET (1, a)-(318, a + 1), buf - ' Randomly shift parts of the screen + ' Shift the screen buffer IF a > 100 THEN PUT (0, a), buf, PSET ELSE @@ -359,6 +435,7 @@ SUB turnon END IF NEXT a + ' Copy screen buffer and clear the screen PCOPY 0, 1 NEXT b -- 2.20.1