From 8c57405723af4e6af1564d15859181199ca293e2 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Wed, 21 Aug 2024 14:02:36 +0300 Subject: [PATCH] Using AI to improve code readability --- Graphics/Animations/water1.bas | 83 ++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/Graphics/Animations/water1.bas b/Graphics/Animations/water1.bas index 062af8a..12e5559 100755 --- a/Graphics/Animations/water1.bas +++ b/Graphics/Animations/water1.bas @@ -1,46 +1,59 @@ -' Wave simulation -' made by Svjatoslav Agejenko -' in 2003.12 -' H-Page: svjatoslav.eu -' E-Mail: svjatoslav@svjatoslav.eu - -SCREEN 13 +' Program simulate wave propagation across surface. +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 2003.12, Initial version +' 2024.08, Improved program readability using AI -DIM SHARED yh(1 TO 300) -DIM SHARED yhs(1 TO 300) +SCREEN 13 +DIM SHARED yHigh(1 TO 300) ' surface height +DIM SHARED yVelocity(1 TO 300) ' surface movement direction and velocity +' Initialize the arrays FOR x = 1 TO 300 -yhs(x) = 0 -yh(x) = 100 + yVelocity(x) = 0 + yHigh(x) = 100 NEXT x +' Create an initial wave shape FOR x = 140 TO 160 -yh(x) = 150 -NEXT x - - - -1 -FOR x = 1 TO 300 - LINE (x, 0)-(x, 200 - yh(x)), 0 - LINE (x, 200 - yh(x))-(x, 200), 15 -NEXT x - -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 + yHigh(x) = 150 NEXT x -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 -NEXT x - -SOUND 0, .5 -IF INKEY$ <> "" THEN SYSTEM +' Main simulation loop +1 : + ' Draw the wave + FOR x = 1 TO 300 + LINE (x, 0)-(x, 200 - yHigh(x)), 0 + LINE (x, 200 - yHigh(x))-(x, 200), 15 + NEXT x + + ' Calculate the average height of neighboring points + FOR x = 10 TO 290 + avgHeight = (yHigh(x - 1) + yHigh(x + 1) + yHigh(x + 2) + yHigh(x - 2)) / 4 + ' Update the smooth wave height + yVelocity(x) = yVelocity(x) + (avgHeight - yHigh(x)) / 5 + ' Apply a damping factor + yVelocity(x) = yVelocity(x) / 1.01 + NEXT x + + ' Update the wave height based on the smooth values + FOR x = 10 TO 290 + yHigh(x) = yHigh(x) + yVelocity(x) + ' Apply smoothing to neighboring points + yHigh(x - 1) = yHigh(x - 1) + yVelocity(x) / 2 + yHigh(x + 1) = yHigh(x + 1) + yVelocity(x) / 2 + NEXT x + + ' Play a sound + SOUND 0, .5 + + ' Check for user input to exit + IF INKEY$ <> "" THEN SYSTEM + +' Loop back to the start of the simulation loop GOTO 1 - -- 2.20.1