--- /dev/null
+' 3D animation of point-cloud ball bouncing around the screen\r
+'\r
+' by Svjatoslav Agejenko\r
+' homepage: svjatoslav.eu\r
+' email: svjatoslav@svjatoslav.eu\r
+'\r
+' 1999, Initial version.\r
+' 2024.07, Used AI to enhance program readability.\r
+\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
+' 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
+' 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
+ 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
+ ' 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
+\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
+ 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
--- /dev/null
+DECLARE SUB DrawBox (x1%, y1%, x2%, y2%, x3%, y3%, x4%, y4%, c1%)\r
+\r
+' Program to render 3D shaded landscape with perspective and distortion effects.\r
+' By Svjatoslav Agejenko.\r
+' Email: svjatoslav@svjatoslav.eu\r
+' Homepage: http://www.svjatoslav.eu\r
+'\r
+' Changelog:\r
+' 1999, Initial version\r
+' 2024.08, Improved program readability using AI\r
+\r
+DECLARE SUB SetPalette ()\r
+DEFINT A-Z\r
+\r
+' Declare shared arrays for X and Y coordinates\r
+DIM SHARED xCoordinates(1 TO 40, 1 TO 40)\r
+DIM SHARED yCoordinates(1 TO 40, 1 TO 40)\r
+\r
+' Set screen mode to 12\r
+SCREEN 12\r
+\r
+' Initialize color palette\r
+SetPalette\r
+\r
+' Set initial scaling factor\r
+scalingFactor = 1.5\r
+\r
+' Main loop start\r
+1 :\r
+' Loop through each point in the grid\r
+FOR rowIndex = 1 TO 40\r
+ FOR colIndex = 1 TO 40\r
+ ' Calculate the position with distortion\r
+ xPosition = 120 + (colIndex * 10)\r
+ yPosition = 200 + (rowIndex * 3)\r
+\r
+ ' Apply a cosine distortion based on distance from center\r
+ yPosition = yPosition - COS(SQR((colIndex - 20) ^ 2 + (rowIndex - 20) ^ 2) / scalingFactor) * 20\r
+\r
+ ' Apply perspective transformation\r
+ xPosition = (xPosition - 320) * (rowIndex + 50) / 50 + 320\r
+ yPosition = (yPosition - 240) * (rowIndex + 50) / 50 + 240\r
+\r
+ ' Store the transformed coordinates\r
+ xCoordinates(colIndex, rowIndex) = xPosition\r
+ yCoordinates(colIndex, rowIndex) = yPosition\r
+ NEXT colIndex\r
+NEXT rowIndex\r
+\r
+' Draw boxes based on the stored coordinates\r
+FOR rowIndex = 1 TO 39\r
+ FOR colIndex = 1 TO 39\r
+ ' Alternate colors for each box\r
+ IF (colIndex + rowIndex) \ 2 <> (colIndex + rowIndex + 1) \ 2 THEN colorIndex = 0 ELSE colorIndex = 5\r
+ ' Calculate a brightness factor\r
+ brightnessFactor = rowIndex + (colIndex / 3)\r
+\r
+ ' Draw the box with the calculated color and brightness\r
+ DrawBox xCoordinates(colIndex, rowIndex), yCoordinates(colIndex, rowIndex), xCoordinates(colIndex + 1, rowIndex), yCoordinates(colIndex + 1, rowIndex), xCoordinates(colIndex, rowIndex + 1), yCoordinates(colIndex, rowIndex + 1), xCoordinates( _\r
+colIndex + 1, rowIndex + 1), yCoordinates(colIndex + 1, rowIndex + 1), colorIndex\r
+ NEXT colIndex\r
+NEXT rowIndex\r
+\r
+' Wait for user input and adjust the scaling factor\r
+userInput$ = INPUT$(1)\r
+scalingFactor = scalingFactor * 1.9\r
+\r
+' Clear the screen for the next iteration\r
+CLS\r
+\r
+' If the scaling factor is too large, exit the program\r
+IF scalingFactor > 10 THEN SYSTEM\r
+\r
+' Jump back to the main loop start\r
+GOTO 1\r
+\r
+' Subroutine to draw a filled box using line drawing\r
+SUB DrawBox (x1, y1, x2, y2, x3, y3, x4, y4, c1)\r
+ ' Adjust color index based on position and brightness factor\r
+ c1 = c1 + (y2 - y1) / 3.5 + (brightnessFactor / 8) + 4\r
+\r
+ ' Ensure the color index is within valid range\r
+ IF c1 < 0 THEN c1 = 0\r
+ IF c1 > 15 THEN c1 = 15\r
+\r
+ ' Calculate the length of the longer side\r
+ a = SQR((x1 - x2) ^ 2 + (y1 - y2) ^ 2)\r
+ b = SQR((x3 - x4) ^ 2 + (y3 - y4) ^ 2)\r
+ IF b < a THEN b = a\r
+\r
+ ' Draw the box using lines\r
+ FOR lineIndex = 1 TO b\r
+ x5 = (x2 - x1) * lineIndex / b + x1\r
+ y5 = (y2 - y1) * lineIndex / b + y1\r
+ x6 = (x4 - x3) * lineIndex / b + x3\r
+ y6 = (y4 - y3) * lineIndex / b + y3\r
+\r
+ ' Draw two adjacent lines to create a filled effect\r
+ LINE (x5, y5)-(x6, y6), c1\r
+ LINE (x5 + 1, y5)-(x6 + 1, y6), c1\r
+ NEXT lineIndex\r
+END SUB\r
+\r
+' Subroutine to initialize color palette\r
+SUB SetPalette\r
+ FOR paletteIndex = 1 TO 16\r
+ ' Set the color values for each palette entry\r
+ OUT &H3C8, paletteIndex\r
+ OUT &H3C9, paletteIndex * 4\r
+ OUT &H3C9, paletteIndex * 4\r
+ OUT &H3C9, paletteIndex * 3\r
+ NEXT paletteIndex\r
+END SUB\r
+\r
+++ /dev/null
-' 3D animation of point-cloud ball bouncing around the screen\r
-'\r
-' by Svjatoslav Agejenko\r
-' homepage: svjatoslav.eu\r
-' email: svjatoslav@svjatoslav.eu\r
-'\r
-' 1999, Initial version.\r
-' 2024.07, Used AI to enhance program readability.\r
-\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
-' 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
-' 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
- 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
- ' 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
-\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
- 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
+++ /dev/null
-DECLARE SUB DrawBox (x1%, y1%, x2%, y2%, x3%, y3%, x4%, y4%, c1%)\r
-\r
-' Program to render 3D shaded landscape with perspective and distortion effects.\r
-' By Svjatoslav Agejenko.\r
-' Email: svjatoslav@svjatoslav.eu\r
-' Homepage: http://www.svjatoslav.eu\r
-'\r
-' Changelog:\r
-' 1999, Initial version\r
-' 2024.08, Improved program readability using AI\r
-\r
-DECLARE SUB SetPalette ()\r
-DEFINT A-Z\r
-\r
-' Declare shared arrays for X and Y coordinates\r
-DIM SHARED xCoordinates(1 TO 40, 1 TO 40)\r
-DIM SHARED yCoordinates(1 TO 40, 1 TO 40)\r
-\r
-' Set screen mode to 12\r
-SCREEN 12\r
-\r
-' Initialize color palette\r
-SetPalette\r
-\r
-' Set initial scaling factor\r
-scalingFactor = 1.5\r
-\r
-' Main loop start\r
-1 :\r
-' Loop through each point in the grid\r
-FOR rowIndex = 1 TO 40\r
- FOR colIndex = 1 TO 40\r
- ' Calculate the position with distortion\r
- xPosition = 120 + (colIndex * 10)\r
- yPosition = 200 + (rowIndex * 3)\r
-\r
- ' Apply a cosine distortion based on distance from center\r
- yPosition = yPosition - COS(SQR((colIndex - 20) ^ 2 + (rowIndex - 20) ^ 2) / scalingFactor) * 20\r
-\r
- ' Apply perspective transformation\r
- xPosition = (xPosition - 320) * (rowIndex + 50) / 50 + 320\r
- yPosition = (yPosition - 240) * (rowIndex + 50) / 50 + 240\r
-\r
- ' Store the transformed coordinates\r
- xCoordinates(colIndex, rowIndex) = xPosition\r
- yCoordinates(colIndex, rowIndex) = yPosition\r
- NEXT colIndex\r
-NEXT rowIndex\r
-\r
-' Draw boxes based on the stored coordinates\r
-FOR rowIndex = 1 TO 39\r
- FOR colIndex = 1 TO 39\r
- ' Alternate colors for each box\r
- IF (colIndex + rowIndex) \ 2 <> (colIndex + rowIndex + 1) \ 2 THEN colorIndex = 0 ELSE colorIndex = 5\r
- ' Calculate a brightness factor\r
- brightnessFactor = rowIndex + (colIndex / 3)\r
-\r
- ' Draw the box with the calculated color and brightness\r
- DrawBox xCoordinates(colIndex, rowIndex), yCoordinates(colIndex, rowIndex), xCoordinates(colIndex + 1, rowIndex), yCoordinates(colIndex + 1, rowIndex), xCoordinates(colIndex, rowIndex + 1), yCoordinates(colIndex, rowIndex + 1), xCoordinates( _\r
-colIndex + 1, rowIndex + 1), yCoordinates(colIndex + 1, rowIndex + 1), colorIndex\r
- NEXT colIndex\r
-NEXT rowIndex\r
-\r
-' Wait for user input and adjust the scaling factor\r
-userInput$ = INPUT$(1)\r
-scalingFactor = scalingFactor * 1.9\r
-\r
-' Clear the screen for the next iteration\r
-CLS\r
-\r
-' If the scaling factor is too large, exit the program\r
-IF scalingFactor > 10 THEN SYSTEM\r
-\r
-' Jump back to the main loop start\r
-GOTO 1\r
-\r
-' Subroutine to draw a filled box using line drawing\r
-SUB DrawBox (x1, y1, x2, y2, x3, y3, x4, y4, c1)\r
- ' Adjust color index based on position and brightness factor\r
- c1 = c1 + (y2 - y1) / 3.5 + (brightnessFactor / 8) + 4\r
-\r
- ' Ensure the color index is within valid range\r
- IF c1 < 0 THEN c1 = 0\r
- IF c1 > 15 THEN c1 = 15\r
-\r
- ' Calculate the length of the longer side\r
- a = SQR((x1 - x2) ^ 2 + (y1 - y2) ^ 2)\r
- b = SQR((x3 - x4) ^ 2 + (y3 - y4) ^ 2)\r
- IF b < a THEN b = a\r
-\r
- ' Draw the box using lines\r
- FOR lineIndex = 1 TO b\r
- x5 = (x2 - x1) * lineIndex / b + x1\r
- y5 = (y2 - y1) * lineIndex / b + y1\r
- x6 = (x4 - x3) * lineIndex / b + x3\r
- y6 = (y4 - y3) * lineIndex / b + y3\r
-\r
- ' Draw two adjacent lines to create a filled effect\r
- LINE (x5, y5)-(x6, y6), c1\r
- LINE (x5 + 1, y5)-(x6 + 1, y6), c1\r
- NEXT lineIndex\r
-END SUB\r
-\r
-' Subroutine to initialize color palette\r
-SUB SetPalette\r
- FOR paletteIndex = 1 TO 16\r
- ' Set the color values for each palette entry\r
- OUT &H3C8, paletteIndex\r
- OUT &H3C9, paletteIndex * 4\r
- OUT &H3C9, paletteIndex * 4\r
- OUT &H3C9, paletteIndex * 3\r
- NEXT paletteIndex\r
-END SUB\r
-\r