Better code readability.
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Thu, 26 Jun 2025 13:39:49 +0000 (16:39 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Thu, 26 Jun 2025 13:39:49 +0000 (16:39 +0300)
2D GFX/Textures/circular waves.bas
2D GFX/Textures/old paper.bas

index d2242d0..8312773 100755 (executable)
@@ -1,7 +1,12 @@
-' Draw circular wave pattern.\r
-' Made by Svjatoslav Agejenko in 2003.12\r
-' H-Page: svjatoslav.eu\r
-' E-Mail: svjatoslav@svjatoslav.eu\r
+' Program to render circular wave patterns.\r
+' Algorithm was accidentally discovered while experimenting with sine function.\r
+' By Svjatoslav Agejenko.\r
+' Email: svjatoslav@svjatoslav.eu\r
+' Homepage: http://www.svjatoslav.eu\r
+'\r
+' Changelog:\r
+' 2003, Initial version\r
+' 2025, Improved program readability\r
 \r
 SCREEN 13\r
 \r
index 7fde5c0..22e09cc 100755 (executable)
@@ -1,35 +1,62 @@
-' Old paper surface\r
-' made by Svjatoslav Agejenko\r
-' in 2003.12\r
-' H-Page: svjatoslav.eu\r
-' E-Mail: svjatoslav@svjatoslav.eu\r
\r
+' Program to render surface resembling old paper.\r
+' By Svjatoslav Agejenko.\r
+' Email: svjatoslav@svjatoslav.eu\r
+' Homepage: http://www.svjatoslav.eu\r
+'\r
+' Changelog:\r
+' 2003, Initial version\r
+' 2025, Improved program readability\r
+\r
 DEFINT A-Z\r
 SCREEN 13\r
 RANDOMIZE TIMER\r
-FOR a = 0 TO 63\r
-OUT &H3C8, a\r
-OUT &H3C9, a  'R\r
-OUT &H3C9, a  'G\r
-OUT &H3C9, a  'B\r
-NEXT a\r
 \r
-z = 0\r
+' Initialize the color palette to grayscale. Each color index from 0 to 63 has R, G, B values equal to the index,\r
+' creating a smooth grayscale gradient for the 256-color mode.\r
+FOR paletteIndex = 0 TO 63\r
+    OUT &H3C8, paletteIndex\r
+    OUT &H3C9, paletteIndex  ' Set red component\r
+    OUT &H3C9, paletteIndex  ' Set green component\r
+    OUT &H3C9, paletteIndex  ' Set blue component\r
+NEXT paletteIndex\r
+\r
+noiseOffset = 0\r
 \r
+' Generate a paper-like surface by averaging the color of the pixel above with some randomness.\r
+' This creates a procedural texture that mimics the roughness of paper.\r
 FOR y = 1 TO 190\r
-FOR x = 1 TO 310\r
-p = p + 1\r
-IF p > 10 THEN z = RND * c / 20: p = p - (RND * 20 + 10)\r
-c1 = POINT(x, y - 1)\r
-c = (c1 + c) \ 2 + ((RND * 2) - z)\r
-IF c < 0 THEN c = 0\r
-IF c > 63 THEN c = 63\r
-PSET (x - 1, y), c\r
-\r
-NEXT x\r
-PSET (0, y + 1), c\r
+    FOR x = 1 TO 310\r
+        stepCounter = stepCounter + 1\r
+\r
+        ' Approximately every 10 steps, introduce a new random noise offset to create variation in the pattern.\r
+        ' This prevents the surface from becoming too uniform.\r
+        IF stepCounter > 10 THEN\r
+            noiseOffset = RND * currentColor / 20\r
+            stepCounter = stepCounter - (RND * 20 + 10)\r
+        END IF\r
+\r
+        ' Get the color of the pixel directly above the current position.\r
+        topColor = POINT(x, y - 1)\r
+\r
+        ' Calculate the current color as the average of the top color and the previous current color,\r
+        ' plus a small random noise and minus the noise offset. This creates a smooth transition with\r
+        ' controlled randomness.\r
+        currentColor = (topColor + currentColor) \ 2 + ((RND * 2) - noiseOffset)\r
+\r
+        ' Clamp the color value to stay within the valid palette range (0 to 63).\r
+        IF currentColor < 0 THEN currentColor = 0\r
+        IF currentColor > 63 THEN currentColor = 63\r
+\r
+        ' Plot the current pixel at (x-1, y) using the calculated color.\r
+        PSET (x - 1, y), currentColor\r
+    NEXT x\r
+\r
+    ' Set the starting color for the next row to the last calculated color of the current row.\r
+    ' This ensures continuity between rows.\r
+    PSET (0, y + 1), currentColor\r
 NEXT y\r
-a$ = INPUT$(1)\r
 \r
-SYSTEM\r
+' Wait for a single key press before exiting the program.\r
+inputKey$ = INPUT$(1)\r
 \r
+SYSTEM\r