-' Program to render rotating pixels\r
+' This program showcases the rotation of points on an X-Y coordinate\r
+' system using trigonometric functions, specifically sine and cosine. By\r
+' simulating the effect of rotating a collection of grid points around\r
+' the origin, it demonstrates the mathematical principles behind 2D\r
+' rotation.\r
+'\r
' By Svjatoslav Agejenko.\r
' Email: svjatoslav@svjatoslav.eu\r
' Homepage: http://www.svjatoslav.eu\r
-'\r
+\r
' Changelog:\r
' 2003.12, Initial version\r
-' 2024.08, Improved program readability using AI\r
+' 2024, Improved program readability using AI\r
\r
-\r
-DIM SHARED pointX(1000) ' Point x & y location\r
-DIM SHARED pointY(1000)\r
-DIM SHARED oldPointX(1000) ' Old point x & y location\r
-DIM SHARED oldPointY(1000)\r
+DIM SHARED pointXCoordinates(1000) ' Array to store x coordinates of points\r
+DIM SHARED pointYCoordinates(1000) ' Array to store y coordinates of points\r
+DIM SHARED oldPointXCoordinates(1000) ' Array to store previous x coordinates of points\r
+DIM SHARED oldPointYCoordinates(1000) ' Array to store previous y coordinates of points\r
\r
SCREEN 13\r
\r
-numPoints = 0 ' Set points to their place\r
+numPoints = 0 ' Initialize the number of points\r
FOR pointXVal = -10 TO 10\r
FOR pointYVal = -10 TO 10\r
numPoints = numPoints + 1\r
- pointX(numPoints) = pointXVal\r
- pointY(numPoints) = pointYVal\r
+ pointXCoordinates(numPoints) = pointXVal\r
+ pointYCoordinates(numPoints) = pointYVal\r
NEXT pointYVal\r
NEXT pointXVal\r
\r
-' Rotate points now\r
-rotationAngle = 0 ' Start angle\r
+' Main rotation loop\r
+rotationAngle = 0 ' Initialize the rotation angle to 0\r
+\r
1\r
- rotationAngle = rotationAngle + 0.01\r
- sineOfAngle = SIN(rotationAngle)\r
- cosineOfAngle = COS(rotationAngle)\r
+ rotationAngle = rotationAngle + .01 ' Increment the rotation angle by 0.01 radians\r
+\r
+ ' Calculate the sine and cosine of the current rotation angle\r
+ sineOfRotationAngle = SIN(rotationAngle)\r
+ cosineOfRotationAngle = COS(rotationAngle)\r
+\r
+ FOR pointIndex = 1 TO numPoints\r
+ PSET (oldPointXCoordinates(pointIndex), oldPointYCoordinates(pointIndex)), 0 ' Clear the previous position\r
+\r
+ xCoordinate = pointXCoordinates(pointIndex)\r
+ yCoordinate = pointYCoordinates(pointIndex)\r
+\r
+ ' Calculate the new x and y coordinate after rotation\r
+ newXCoordinate = xCoordinate * sineOfRotationAngle + yCoordinate * cosineOfRotationAngle\r
+ newYCoordinate = xCoordinate * cosineOfRotationAngle - yCoordinate * sineOfRotationAngle\r
\r
- FOR a = 1 TO numPoints\r
- PSET (oldPointX(a), oldPointY(a)), 0\r
+ ' Scale and translate the new x and y coordinates to the center of the screen\r
+ newXCoordinate = newXCoordinate * 7 + 160\r
+ newYCoordinate = newYCoordinate * 7 + 100\r
\r
- x = pointX(a)\r
- y = pointY(a)\r
+ ' Store x and y on-screen coordinates for clearing on next iteration\r
+ oldPointXCoordinates(pointIndex) = newXCoordinate\r
+ oldPointYCoordinates(pointIndex) = newYCoordinate\r
\r
- newX = x * sineOfAngle + y * cosineOfAngle\r
- newY = x * cosineOfAngle - y * sineOfAngle\r
- newX = newX * 7 + 160\r
- newY = newY * 7 + 100\r
+ PSET (newXCoordinate, newYCoordinate), 15 ' Draw the point at the new position\r
+ NEXT pointIndex\r
\r
- oldPointX(a) = newX\r
- oldPointY(a) = newY\r
- PSET (newX, newY), 15\r
- NEXT a\r
+IF INKEY$ = "" THEN GOTO 1 ' Continue rotating if no key is pressed\r
\r
-IF INKEY$ = "" THEN GOTO 1
\ No newline at end of file