-' Wave simulation\r
-' made by Svjatoslav Agejenko\r
-' in 2003.12\r
-' H-Page: svjatoslav.eu\r
-' E-Mail: svjatoslav@svjatoslav.eu\r
- \r
-SCREEN 13\r
+' Program renders 2D surface of a water. Water surface is disturbed by random rain droplets.\r
+' Program simulates and visualizes propagating waves on the water surface.\r
+'\r
+' By Svjatoslav Agejenko.\r
+' Email: svjatoslav@svjatoslav.eu\r
+' Homepage: http://www.svjatoslav.eu\r
+'\r
+' Changelog:\r
+' 2003, Initial version\r
+' 2024, Improved program readability using AI\r
\r
-DIM SHARED yh(1 TO 300)\r
-DIM SHARED yhs(1 TO 300)\r
+SCREEN 13\r
\r
+DIM SHARED surfaceHeight(1 TO 300)\r
+DIM SHARED verticalMovementSpeed(1 TO 300)\r
\r
FOR x = 1 TO 300\r
-yhs(x) = 0\r
-yh(x) = 50\r
+ verticalMovementSpeed(x) = 0\r
+ surfaceHeight(x) = 50\r
NEXT x\r
\r
-\r
-\r
+' Main loop\r
1\r
\r
CLS\r
FOR x = 1 TO 300\r
-' LINE (x, 0)-(x, 200 - yh(x)), 0\r
-' LINE (x, 200 - yh(x))-(x, 200), 15\r
- PSET (x, 200 - yh(x)), 31\r
+ ' Draw the current wave height at each point\r
+ PSET (x, 200 - surfaceHeight(x)), 31\r
NEXT x\r
\r
-\r
+' Calculate new wave heights based on neighboring points\r
FOR x = 10 TO 290\r
- hk = (yh(x - 1) + yh(x + 1) + yh(x + 2) + yh(x - 2)) / 4\r
- yhs(x) = yhs(x) + (hk - yh(x)) / 5\r
- yhs(x) = yhs(x) / 1.01\r
+ averageNeighborHeights = (surfaceHeight(x - 1) + surfaceHeight(x + 1) + surfaceHeight(x + 2) + surfaceHeight(x - 2)) / 4\r
+ verticalMovementSpeed(x) = verticalMovementSpeed(x) + (averageNeighborHeights - surfaceHeight(x)) / 5\r
+ ' Smooth the new wave heights\r
+ verticalMovementSpeed(x) = verticalMovementSpeed(x) / 1.01\r
NEXT x\r
\r
+' Update the current wave heights with the newly calculated values\r
FOR x = 10 TO 290\r
- yh(x) = yh(x) + yhs(x)\r
-' yh(x - 1) = yh(x - 1) + yhs(x) / 2\r
-' yh(x + 1) = yh(x + 1) + yhs(x) / 2\r
-'SOUND 0, .05\r
+ surfaceHeight(x) = surfaceHeight(x) + verticalMovementSpeed(x)\r
NEXT x\r
\r
-'FOR x = 10 TO 290\r
-' yh(x) = (yh(x) * 100 + yh(x + 1) + yh(x - 1)) / 102\r
-'NEXT x\r
-\r
+' Randomly generate a new wave at the start point\r
IF RND * 100 < 2 THEN\r
- p = RND * 200\r
- s = RND * 10 + 2\r
- FOR x = 0 TO 3.14 STEP 3.14 / s\r
- yh(p) = yh(p) + SIN(x) * s * 3\r
- p = p + 1\r
- NEXT x\r
+ newWaveIndex = RND * 200\r
+ waveAmplitude = RND * 10 + 2\r
+ FOR x = 0 TO 3.14 STEP 3.14 / waveAmplitude\r
+ surfaceHeight(newWaveIndex) = surfaceHeight(newWaveIndex) + SIN(x) * waveAmplitude * 3\r
+ newWaveIndex = newWaveIndex + 1\r
+ NEXT x\r
END IF\r
\r
+' Check for user input to exit the program\r
IF INKEY$ <> "" THEN SYSTEM\r
-GOTO 1\r
-\r
\r
+' Go back to the main loop\r
+GOTO 1\r