From 8b3a6ecc97c20515fc3327f3a2307a32bab7f903 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sun, 27 Oct 2024 16:44:32 +0200 Subject: [PATCH] Using AI to improve code readability --- Graphics/Animations/water2.bas | 71 +++++++++++++++++----------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/Graphics/Animations/water2.bas b/Graphics/Animations/water2.bas index a11bd00..1d5e856 100755 --- a/Graphics/Animations/water2.bas +++ b/Graphics/Animations/water2.bas @@ -1,59 +1,58 @@ -' Wave simulation -' made by Svjatoslav Agejenko -' in 2003.12 -' H-Page: svjatoslav.eu -' E-Mail: svjatoslav@svjatoslav.eu - -SCREEN 13 +' Program renders 2D surface of a water. Water surface is disturbed by random rain droplets. +' Program simulates and visualizes propagating waves on the water surface. +' +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 2003, Initial version +' 2024, Improved program readability using AI -DIM SHARED yh(1 TO 300) -DIM SHARED yhs(1 TO 300) +SCREEN 13 +DIM SHARED surfaceHeight(1 TO 300) +DIM SHARED verticalMovementSpeed(1 TO 300) FOR x = 1 TO 300 -yhs(x) = 0 -yh(x) = 50 + verticalMovementSpeed(x) = 0 + surfaceHeight(x) = 50 NEXT x - - +' Main loop 1 CLS FOR x = 1 TO 300 -' LINE (x, 0)-(x, 200 - yh(x)), 0 -' LINE (x, 200 - yh(x))-(x, 200), 15 - PSET (x, 200 - yh(x)), 31 + ' Draw the current wave height at each point + PSET (x, 200 - surfaceHeight(x)), 31 NEXT x - +' Calculate new wave heights based on neighboring points FOR x = 10 TO 290 - hk = (yh(x - 1) + yh(x + 1) + yh(x + 2) + yh(x - 2)) / 4 - yhs(x) = yhs(x) + (hk - yh(x)) / 5 - yhs(x) = yhs(x) / 1.01 + averageNeighborHeights = (surfaceHeight(x - 1) + surfaceHeight(x + 1) + surfaceHeight(x + 2) + surfaceHeight(x - 2)) / 4 + verticalMovementSpeed(x) = verticalMovementSpeed(x) + (averageNeighborHeights - surfaceHeight(x)) / 5 + ' Smooth the new wave heights + verticalMovementSpeed(x) = verticalMovementSpeed(x) / 1.01 NEXT x +' Update the current wave heights with the newly calculated values FOR x = 10 TO 290 - yh(x) = yh(x) + yhs(x) -' yh(x - 1) = yh(x - 1) + yhs(x) / 2 -' yh(x + 1) = yh(x + 1) + yhs(x) / 2 -'SOUND 0, .05 + surfaceHeight(x) = surfaceHeight(x) + verticalMovementSpeed(x) NEXT x -'FOR x = 10 TO 290 -' yh(x) = (yh(x) * 100 + yh(x + 1) + yh(x - 1)) / 102 -'NEXT x - +' Randomly generate a new wave at the start point IF RND * 100 < 2 THEN - p = RND * 200 - s = RND * 10 + 2 - FOR x = 0 TO 3.14 STEP 3.14 / s - yh(p) = yh(p) + SIN(x) * s * 3 - p = p + 1 - NEXT x + newWaveIndex = RND * 200 + waveAmplitude = RND * 10 + 2 + FOR x = 0 TO 3.14 STEP 3.14 / waveAmplitude + surfaceHeight(newWaveIndex) = surfaceHeight(newWaveIndex) + SIN(x) * waveAmplitude * 3 + newWaveIndex = newWaveIndex + 1 + NEXT x END IF +' Check for user input to exit the program IF INKEY$ <> "" THEN SYSTEM -GOTO 1 - +' Go back to the main loop +GOTO 1 -- 2.20.1