-' Sun; Earth and Moon\r
-' made by Svjatoslav Agejenko\r
-' in 1999\r
-' H-Page: svjatoslav.eu\r
-' E-Mail: svjatoslav@svjatoslav.eu\r
- \r
-\r
-DECLARE SUB maa (a2%, b2%, c2%)\r
-DEFINT A-Y\r
-DIM SHARED zw\r
-DIM SHARED zy\r
+' Projects animation of the sun, earth and moon.\r
+' The moon orbits the earth, and the earth orbits the sun.\r
+' The program uses clever trickery to determine\r
+' the drawing order of the objects based on their y-coordinates.\r
+\r
+' By Svjatoslav Agejenko.\r
+' Email: svjatoslav@svjatoslav.eu\r
+' Homepage: http://www.svjatoslav.eu\r
+\r
+' Changelog:\r
+' 1999, Initial version\r
+' 2024, Improved program readability using AI\r
+\r
+\r
+DECLARE SUB drawEarthMoonSystem (a2!, b2!, c2!)\r
+\r
+DIM SHARED moonX\r
+DIM SHARED moonY\r
SCREEN 7, , , 1\r
\r
+' Initialize the earth rotation angle\r
+earthRotationAngle = 0\r
+\r
+' Main loop to update and draw the objects\r
+1 : \r
+ ' Increment the earthRotationAngle for every frame\r
+ earthRotationAngle = earthRotationAngle + .01\r
+\r
+ ' Calculate the x and y coordinates of the earth\r
+ earthX = SIN(earthRotationAngle) * 100 + 100\r
+ earthY = COS(earthRotationAngle) * 30 + 100\r
+\r
+ ' Because we dont do proper earth, moon and sun Z-sorting,\r
+ ' instead we implement clever trickery to determine, should\r
+ ' sun be drawn before earth-moon system, or after.\r
+ IF earthY >= 100 THEN\r
+ ' Draw the sun\r
+ CIRCLE (100, 100), 50, 12\r
+ PAINT (100, 100), 12\r
+ END IF\r
+\r
+ ' Call the subroutine to draw the earth-moon system\r
+ drawEarthMoonSystem earthX, earthY, (earthY - 70) / 2 + 2\r
+\r
+ IF earthY < 100 THEN\r
+ ' Draw the sun\r
+ CIRCLE (100, 100), 50, 12\r
+ PAINT (100, 100), 12\r
+ END IF\r
+\r
+ ' Copy the screen to buffer\r
+ PCOPY 0, 1\r
+\r
+ ' Clear the screen\r
+ CLS\r
\r
+ ' Check if a key is pressed\r
+ IF INKEY$ = "" THEN GOTO 1\r
\r
-z = 0\r
-1\r
-z = z + .01\r
-a1 = SIN(z) * 100 + 100\r
-b1 = COS(z) * 30 + 100\r
-IF b1 >= 100 THEN CIRCLE (100, 100), 50, 12: PAINT (100, 100), 12\r
-maa a1, b1, (b1 - 70) / 2 + 2\r
-IF b1 < 100 THEN CIRCLE (100, 100), 50, 12: PAINT (100, 100), 12\r
-PCOPY 0, 1\r
-CLS\r
-IF INKEY$ = "" THEN GOTO 1\r
+' End the program\r
SYSTEM\r
\r
-SUB maa (a2, b2, c2)\r
-ed = (b2 - 70) / 2 + 2\r
+SUB drawEarthMoonSystem (a2, b2, c2)\r
+ moonSize = (b2 - 70) / 2 + 2\r
\r
-zw = zw + .1\r
-zy = zy + .01\r
+ ' Increment the moon's x and y coordinates\r
+ moonX = moonX + .1\r
+ moonY = moonY + .01\r
\r
-a1 = SIN(zw) * ed * 2\r
-b1 = COS(zw) * 10\r
+ ' Calculate the x and y offsets for the moon\r
+ moonOffsetX = SIN(moonX) * moonSize * 2\r
+ moonOffsetY = COS(moonX) * 10\r
\r
-IF b1 > 0 THEN CIRCLE (a2, b2), c2, 1: PAINT (a2, b2), 1\r
+ ' Because we don't do proper earth and moon Z-sorting,\r
+ ' instead we implement clever trickery to determine, should\r
+ ' earth be drawn before moon or after.\r
+ IF moonOffsetY > 0 THEN\r
+ ' Draw the earth\r
+ CIRCLE (a2, b2), c2, 1\r
+ PAINT (a2, b2), 1\r
+ END IF\r
\r
-CIRCLE (a1 + a2, b1 + b2), ((b1 + 20) * ed) \ 50, 14\r
-PAINT (a1 + a2, b1 + b2), 14\r
+ ' Calculate the x and y coordinates of the moon and draw it\r
+ moonXCoord = moonOffsetX + a2\r
+ moonYCoord = moonOffsetY + b2\r
+ CIRCLE (moonXCoord, moonYCoord), ((moonOffsetY + 20) * moonSize) \ 50, 14\r
+ PAINT (moonXCoord, moonYCoord), 14\r
\r
-IF b1 <= 0 THEN CIRCLE (a2, b2), c2, 1: PAINT (a2, b2), 1\r
+ IF moonOffsetY <= 0 THEN\r
+ ' Draw the earth\r
+ CIRCLE (a2, b2), c2, 1\r
+ PAINT (a2, b2), 1\r
+ END IF\r
END SUB\r
\r