From 7b9e9c34f30ad0952a7ce50cf40690d9bfb6c7cf Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sat, 26 Oct 2024 11:19:36 +0300 Subject: [PATCH] Using AI to improve code readability --- Graphics/Animations/sun&eart.bas | 114 ++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 32 deletions(-) diff --git a/Graphics/Animations/sun&eart.bas b/Graphics/Animations/sun&eart.bas index eededed..ee277cc 100755 --- a/Graphics/Animations/sun&eart.bas +++ b/Graphics/Animations/sun&eart.bas @@ -1,45 +1,95 @@ -' Sun; Earth and Moon -' made by Svjatoslav Agejenko -' in 1999 -' H-Page: svjatoslav.eu -' E-Mail: svjatoslav@svjatoslav.eu - - -DECLARE SUB maa (a2%, b2%, c2%) -DEFINT A-Y -DIM SHARED zw -DIM SHARED zy +' Projects animation of the sun, earth and moon. +' The moon orbits the earth, and the earth orbits the sun. +' The program uses clever trickery to determine +' the drawing order of the objects based on their y-coordinates. + +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu + +' Changelog: +' 1999, Initial version +' 2024, Improved program readability using AI + + +DECLARE SUB drawEarthMoonSystem (a2!, b2!, c2!) + +DIM SHARED moonX +DIM SHARED moonY SCREEN 7, , , 1 +' Initialize the earth rotation angle +earthRotationAngle = 0 + +' Main loop to update and draw the objects +1 : + ' Increment the earthRotationAngle for every frame + earthRotationAngle = earthRotationAngle + .01 + + ' Calculate the x and y coordinates of the earth + earthX = SIN(earthRotationAngle) * 100 + 100 + earthY = COS(earthRotationAngle) * 30 + 100 + + ' Because we dont do proper earth, moon and sun Z-sorting, + ' instead we implement clever trickery to determine, should + ' sun be drawn before earth-moon system, or after. + IF earthY >= 100 THEN + ' Draw the sun + CIRCLE (100, 100), 50, 12 + PAINT (100, 100), 12 + END IF + + ' Call the subroutine to draw the earth-moon system + drawEarthMoonSystem earthX, earthY, (earthY - 70) / 2 + 2 + + IF earthY < 100 THEN + ' Draw the sun + CIRCLE (100, 100), 50, 12 + PAINT (100, 100), 12 + END IF + + ' Copy the screen to buffer + PCOPY 0, 1 + + ' Clear the screen + CLS + ' Check if a key is pressed + IF INKEY$ = "" THEN GOTO 1 -z = 0 -1 -z = z + .01 -a1 = SIN(z) * 100 + 100 -b1 = COS(z) * 30 + 100 -IF b1 >= 100 THEN CIRCLE (100, 100), 50, 12: PAINT (100, 100), 12 -maa a1, b1, (b1 - 70) / 2 + 2 -IF b1 < 100 THEN CIRCLE (100, 100), 50, 12: PAINT (100, 100), 12 -PCOPY 0, 1 -CLS -IF INKEY$ = "" THEN GOTO 1 +' End the program SYSTEM -SUB maa (a2, b2, c2) -ed = (b2 - 70) / 2 + 2 +SUB drawEarthMoonSystem (a2, b2, c2) + moonSize = (b2 - 70) / 2 + 2 -zw = zw + .1 -zy = zy + .01 + ' Increment the moon's x and y coordinates + moonX = moonX + .1 + moonY = moonY + .01 -a1 = SIN(zw) * ed * 2 -b1 = COS(zw) * 10 + ' Calculate the x and y offsets for the moon + moonOffsetX = SIN(moonX) * moonSize * 2 + moonOffsetY = COS(moonX) * 10 -IF b1 > 0 THEN CIRCLE (a2, b2), c2, 1: PAINT (a2, b2), 1 + ' Because we don't do proper earth and moon Z-sorting, + ' instead we implement clever trickery to determine, should + ' earth be drawn before moon or after. + IF moonOffsetY > 0 THEN + ' Draw the earth + CIRCLE (a2, b2), c2, 1 + PAINT (a2, b2), 1 + END IF -CIRCLE (a1 + a2, b1 + b2), ((b1 + 20) * ed) \ 50, 14 -PAINT (a1 + a2, b1 + b2), 14 + ' Calculate the x and y coordinates of the moon and draw it + moonXCoord = moonOffsetX + a2 + moonYCoord = moonOffsetY + b2 + CIRCLE (moonXCoord, moonYCoord), ((moonOffsetY + 20) * moonSize) \ 50, 14 + PAINT (moonXCoord, moonYCoord), 14 -IF b1 <= 0 THEN CIRCLE (a2, b2), c2, 1: PAINT (a2, b2), 1 + IF moonOffsetY <= 0 THEN + ' Draw the earth + CIRCLE (a2, b2), c2, 1 + PAINT (a2, b2), 1 + END IF END SUB -- 2.20.1