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