-' Svjatoslav Agejenko\r
-' 1999\r
+' 1999, initial version by Svjatoslav Agejenko\r
+' 2024, used AI to enhance program readability\r
\r
-DECLARE SUB newns ()\r
-DECLARE SUB getcor ()\r
-DECLARE SUB show (ang1!, ang2!, ang3!)\r
+DECLARE SUB InitializeScene ()\r
+DECLARE SUB UpdateOrientation ()\r
+DECLARE SUB DisplayPoints (angle1 AS SINGLE, angle2 AS SINGLE, angle3 AS SINGLE)\r
RANDOMIZE TIMER\r
SCREEN 12\r
\r
-DIM SHARED px(1 TO 1000)\r
-DIM SHARED py(1 TO 1000)\r
-DIM SHARED pz(1 TO 1000)\r
-\r
-DIM SHARED ox(1 TO 1000)\r
-DIM SHARED oy(1 TO 1000)\r
-\r
-DIM SHARED mitup\r
- \r
-DIM SHARED pallx, pally\r
-DIM SHARED pallxs, pallys\r
-\r
-DIM SHARED paln1s, paln2s, paln3s\r
-\r
-mitup = 500 ' Number of dots\r
-\r
-getcor\r
-\r
-\r
-nrk1 = 0\r
-nrk2 = 0\r
-nrk3 = 0\r
-\r
-1\r
-show nrk1, nrk2, nrk3\r
-\r
-nrk1 = nrk1 + paln1s\r
-nrk2 = nrk2 + paln2s\r
-nrk3 = nrk3 + paln3s\r
-\r
-pallys = pallys + .1\r
-pallx = pallx + pallxs\r
-pally = pally + pallys\r
-\r
-IF pally > 160 THEN pallys = -pallys: pallxs = pallxs + (RND * 2 - 1): newns\r
-IF pallx < -200 THEN pallxs = -pallxs: newns\r
-IF pallx > 200 THEN pallxs = -pallxs: newns\r
-\r
-a$ = INKEY$\r
-IF a$ <> "" THEN CLS : SYSTEM\r
-GOTO 1\r
-\r
-SUB getcor\r
-PRINT "Calculating cordinates"\r
-PRINT "Please wait....."\r
-\r
-FOR a = 1 TO mitup\r
-ang1 = RND * 100\r
-ang2 = RND * 100\r
-ang3 = RND * 100\r
-\r
-s1 = SIN(ang1)\r
-c1 = COS(ang1)\r
-s2 = SIN(ang2)\r
-c2 = COS(ang2)\r
-s3 = SIN(ang3)\r
-c3 = COS(ang3)\r
-\r
-x = 50\r
-y = 0\r
-z = 0\r
-\r
-x1 = x * s1 + y * c1\r
-y1 = x * c1 - y * s1\r
-\r
-z1 = z * s2 + y1 * c2\r
-y2 = z * c2 - y1 * s2\r
-\r
-z2 = z1 * s3 + x1 * c3\r
-x2 = z1 * c3 - x1 * s3\r
-\r
-px(a) = x2\r
-py(a) = y2\r
-pz(a) = z2\r
-\r
-NEXT a\r
-\r
-\r
-pallxs = 2 + RND\r
-pally = -100\r
-\r
-newns\r
-\r
-CLS\r
+' Shared arrays to hold the positions of points in 3D space\r
+DIM SHARED pointX(1 TO 1000) AS SINGLE\r
+DIM SHARED pointY(1 TO 1000) AS SINGLE\r
+DIM SHARED pointZ(1 TO 1000) AS SINGLE\r
+\r
+' Shared arrays to hold the previous on-screen positions of points\r
+DIM SHARED prevX(1 TO 1000) AS INTEGER\r
+DIM SHARED prevY(1 TO 1000) AS INTEGER\r
+\r
+' Shared variables for simulation control\r
+DIM SHARED totalPoints AS INTEGER\r
+DIM SHARED ballX\r
+DIM SHARED ballY\r
+DIM SHARED ballVelocityX\r
+DIM SHARED ballVelocityY\r
+\r
+' Shared variables for rotation angles and their velocities\r
+DIM SHARED rotationAngle1\r
+DIM SHARED rotationAngle2\r
+DIM SHARED rotationAngle3\r
+DIM SHARED angularVelocity1\r
+DIM SHARED angularVelocity2\r
+DIM SHARED angularVelocity3\r
+\r
+' Initialize the total number of points to be displayed\r
+totalPoints = 500\r
+\r
+CALL InitializeScene\r
+\r
+' Initialization of rotation angles and ball position\r
+rotationAngle1 = 0\r
+rotationAngle2 = 0\r
+rotationAngle3 = 0\r
+\r
+' Main loop\r
+DO\r
+ CALL DisplayPoints(rotationAngle1, rotationAngle2, rotationAngle3)\r
+\r
+ ' Update the rotation angles based on their velocities\r
+ rotationAngle1 = rotationAngle1 + angularVelocity1\r
+ rotationAngle2 = rotationAngle2 + angularVelocity2\r
+ rotationAngle3 = rotationAngle3 + angularVelocity3\r
+\r
+ ' Add force of gravity\r
+ ballVelocityY = ballVelocityY + .1\r
+\r
+ ' Update the ball's position and velocity\r
+ ballY = ballY + ballVelocityY\r
+ ballX = ballX + ballVelocityX\r
+\r
+ ' Check for ball bounce conditions\r
+ IF ballY > 160 THEN\r
+ ballVelocityY = -ballVelocityY\r
+ ballVelocityX = ballVelocityX + (RND * 2 - 1)\r
+ CALL UpdateOrientation\r
+ END IF\r
+\r
+ IF ballX < -200 OR ballX > 200 THEN\r
+ ballVelocityX = -ballVelocityX\r
+ CALL UpdateOrientation\r
+ END IF\r
+\r
+ ' Check for user input to exit the program\r
+ a$ = INKEY$\r
+ IF a$ <> "" THEN\r
+ CLS\r
+ SYSTEM\r
+ END IF\r
+LOOP\r
+\r
+' Subroutine to display the points on the screen\r
+SUB DisplayPoints (angle1 AS SINGLE, angle2 AS SINGLE, angle3 AS SINGLE)\r
+\r
+ ' Calculate the sine and cosine for rotation angles\r
+ s1 = SIN(angle1)\r
+ c1 = COS(angle1)\r
+ s2 = SIN(angle2)\r
+ c2 = COS(angle2)\r
+ s3 = SIN(angle3)\r
+ c3 = COS(angle3)\r
+\r
+ ' For each point, apply rotation transformations and project to 2D\r
+ FOR a = 1 TO totalPoints\r
+ x = pointX(a)\r
+ y = pointY(a)\r
+ z = pointZ(a)\r
+\r
+ x1 = x * s1 + y * c1\r
+ y1 = x * c1 - y * s1\r
+\r
+ z1 = z * s2 + y1 * c2\r
+ y2 = z * c2 - y1 * s2\r
+\r
+ z2 = z1 * s3 + x1 * c3\r
+ x2 = z1 * c3 - x1 * s3\r
+\r
+ ' Perspective projection\r
+ z2 = z2 + 200\r
+\r
+ ' Convert to screen coordinates and apply ball offset\r
+ xScreen = x2 / z2 * 320 + 320 + ballX\r
+ yScreen = y2 / z2 * 300 + 240 + ballY\r
+\r
+ ' Erase the previous point position and draw the new one\r
+ PSET (prevX(a), prevY(a)), 0\r
+ PSET (xScreen, yScreen), 3\r
+\r
+ ' Update the previous on-screen positions\r
+ prevX(a) = xScreen\r
+ prevY(a) = yScreen\r
+ NEXT a\r
END SUB\r
\r
-SUB newns\r
-paln1s = (RND - .5) / 16\r
-paln2s = (RND - .5) / 16\r
-paln3s = (RND - .5) / 16\r
-END SUB\r
-\r
-SUB show (ang1, ang2, ang3)\r
-\r
-\r
-s1 = SIN(ang1)\r
-c1 = COS(ang1)\r
-s2 = SIN(ang2)\r
-c2 = COS(ang2)\r
-s3 = SIN(ang3)\r
-c3 = COS(ang3)\r
+' Subroutine to initialize the 3D points and ball properties\r
+SUB InitializeScene\r
+ PRINT "Calculating coordinates"\r
+ PRINT "Please wait....."\r
\r
+ ' Generate random 3D coordinates for each point\r
+ FOR a = 1 TO totalPoints\r
+ ang1 = RND * 100\r
+ ang2 = RND * 100\r
+ ang3 = RND * 100\r
\r
-FOR a = 1 TO mitup\r
+ s1 = SIN(ang1)\r
+ c1 = COS(ang1)\r
+ s2 = SIN(ang2)\r
+ c2 = COS(ang2)\r
+ s3 = SIN(ang3)\r
+ c3 = COS(ang3)\r
\r
-x = px(a)\r
-y = py(a)\r
-z = pz(a)\r
+ ' Apply rotation transformations to the point\r
+ x = 50\r
+ y = 0\r
+ z = 0\r
\r
-x1 = x * s1 + y * c1\r
-y1 = x * c1 - y * s1\r
+ x1 = x * s1 + y * c1\r
+ y1 = x * c1 - y * s1\r
\r
-z1 = z * s2 + y1 * c2\r
-y2 = z * c2 - y1 * s2\r
+ z1 = z * s2 + y1 * c2\r
+ y2 = z * c2 - y1 * s2\r
\r
-z2 = z1 * s3 + x1 * c3\r
-x2 = z1 * c3 - x1 * s3\r
+ z2 = z1 * s3 + x1 * c3\r
+ x2 = z1 * c3 - x1 * s3\r
\r
-z2 = z2 + 200\r
-\r
-x = x2 / z2 * 320 + 320 + pallx\r
-y = y2 / z2 * 300 + 240 + pally\r
-\r
-PSET (ox(a), oy(a)), 0\r
-PSET (x, y), 3\r
-ox(a) = x\r
-oy(a) = y\r
-\r
-NEXT a\r
+ pointX(a) = x2\r
+ pointY(a) = y2\r
+ pointZ(a) = z2\r
+ NEXT a\r
\r
+ ' Set the initial ball velocity\r
+ ballVelocityX = 2 + RND\r
+ ballY = -100\r
\r
+ CALL UpdateOrientation\r
\r
+ CLS\r
+END SUB\r
\r
+' Subroutine to update the angular velocities for rotation\r
+SUB UpdateOrientation\r
+ angularVelocity1 = (RND - .5) / 16\r
+ angularVelocity2 = (RND - .5) / 16\r
+ angularVelocity3 = (RND - .5) / 16\r
END SUB\r
\r