From: Svjatoslav Agejenko Date: Wed, 25 Jun 2025 22:05:00 +0000 (+0300) Subject: Better code readability. Add screenshots. X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=96cf0d4b54d556feb63ccfc5c328b47f2e14e965;p=qbasicapps.git Better code readability. Add screenshots. --- diff --git a/2D GFX/Textures/circular waves.bas b/2D GFX/Textures/circular waves.bas new file mode 100755 index 0000000..d2242d0 --- /dev/null +++ b/2D GFX/Textures/circular waves.bas @@ -0,0 +1,29 @@ +' Draw circular wave pattern. +' Made by Svjatoslav Agejenko in 2003.12 +' H-Page: svjatoslav.eu +' E-Mail: svjatoslav@svjatoslav.eu + +SCREEN 13 + +' Initialize the screen mode to 320x200 with 16 colors + +' Outer loop for the vertical axis (y-coordinate) +FOR ycoordinate = 1 TO 199 + ' Inner loop for the horizontal axis (x-coordinate) + FOR xcoordinate = 1 TO 319 + ' Calculate the sine value based on the squared distances from the origin + colorvalue = SIN((xcoordinate ^ 2 + ycoordinate ^ 2) / 10) * 10 + + ' Clamp the color value to the range [0, 15] + IF colorvalue < 0 THEN colorvalue = 0 + IF colorvalue > 15 THEN colorvalue = 15 + + ' Set the pixel color at (xcoordinate, ycoordinate) with an offset to use the full 16-color palette + PSET (xcoordinate, ycoordinate), colorvalue + 16 + NEXT xcoordinate +NEXT ycoordinate + +' Wait for user key press +WHILE INKEY$ = "": WEND +CLS +END diff --git a/2D GFX/Textures/circular waves.png b/2D GFX/Textures/circular waves.png new file mode 100644 index 0000000..fbb5233 Binary files /dev/null and b/2D GFX/Textures/circular waves.png differ diff --git a/2D GFX/Textures/diamond square clouds.bas b/2D GFX/Textures/diamond square clouds.bas new file mode 100755 index 0000000..927409b --- /dev/null +++ b/2D GFX/Textures/diamond square clouds.bas @@ -0,0 +1,94 @@ +DECLARE SUB DrawPixels (x1 AS INTEGER, y1 AS INTEGER, s AS INTEGER) +' Program to render cloud surface using diamond square algorithm. +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 2003.12, Initial version +' 2024.08, Improved program readability using AI + +DECLARE SUB DrawBox (x1 AS INTEGER, y1 AS INTEGER, s AS INTEGER) +DECLARE SUB SetPalette () +DECLARE SUB InitializeProgram () +DEFINT A-Z +InitializeProgram + +DIM SHARED maxLightness AS INTEGER +maxLightness = 127 + +DIM scale AS INTEGER +scale = 2 ^ 8 + +1 : +scale = scale \ 2 +x1 = (319 \ scale) - 1 +y1 = (199 \ scale) - 1 + +FOR y = 0 TO y1 + FOR x = 0 TO x1 + DrawPixels x * scale, y * scale, scale + NEXT x +NEXT y + +IF scale > 2 THEN GOTO 1 +WAITa$ = INPUT$(1) + +SUB DrawPixels (x1 AS INTEGER, y1 AS INTEGER, s AS INTEGER) + ' Get the lightness values for the corners of the box + c1 = POINT(x1, y1) + c2 = POINT(x1 + s, y1) + c3 = POINT(x1, y1 + s) + c4 = POINT(x1 + s, y1 + s) + + ' Calculate the midpoint lightness values + sp = s \ 2 + k = s * 2 + kp = k / 2 + + cc2 = ((c1 + c2) / 2) + (RND * k) - kp + IF cc2 > maxLightness THEN cc2 = maxLightness + IF cc2 < 0 THEN cc2 = 0 + + cc3 = ((c1 + c3) / 2) + (RND * k) - kp + IF cc3 > maxLightness THEN cc3 = maxLightness + IF cc3 < 0 THEN cc3 = 0 + + cc4 = ((c2 + c4) / 2) + (RND * k) - kp + IF cc4 > maxLightness THEN cc4 = maxLightness + IF cc4 < 0 THEN cc4 = 0 + + cc5 = ((c3 + c4) / 2) + (RND * k) - kp + IF cc5 > maxLightness THEN cc5 = maxLightness + IF cc5 < 0 THEN cc5 = 0 + + ' Calculate the central lightness value + cc1 = ((cc2 + cc3 + cc4 + cc5) / 4) + (RND * k) - kp + IF cc1 > maxLightness THEN cc1 = maxLightness + IF cc1 < 0 THEN cc1 = 0 + + ' Set the calculated lightness values for the box + PSET (x1 + sp, y1 + sp), cc1 + PSET (x1 + sp, y1), cc2 + PSET (x1, y1 + sp), cc3 + PSET (x1 + s, y1 + sp), cc4 + PSET (x1 + sp, y1 + s), cc5 +END SUB + +SUB InitializeProgram + ' Set the screen mode and initialize the color palette + SCREEN 13 + SetPalette + RANDOMIZE TIMER +END SUB + +SUB SetPalette + ' Set the color palette for lightness levels + FOR a = 0 TO 255 + OUT &H3C8, a + OUT &H3C9, a / 4 + OUT &H3C9, a / 3 + OUT &H3C9, a / 2.3 + NEXT a +END SUB + diff --git a/2D GFX/Textures/diamond square clouds.png b/2D GFX/Textures/diamond square clouds.png new file mode 100644 index 0000000..b596db6 Binary files /dev/null and b/2D GFX/Textures/diamond square clouds.png differ diff --git a/2D GFX/Textures/map1.bas b/2D GFX/Textures/map1.bas deleted file mode 100755 index 56ffcce..0000000 --- a/2D GFX/Textures/map1.bas +++ /dev/null @@ -1,45 +0,0 @@ -' Yellow flame -' By Svjatoslav Agejenko. -' Email: svjatoslav@svjatoslav.eu -' Homepage: http://www.svjatoslav.eu -' -' Changelog: -' 2003.12, Initial version -' 2024.08, Improved program readability using AI - - -DEFINT A-Z ' Define all variables as integers -SCREEN 13 ' Set graphics mode to 320x200 with 256 colors -RANDOMIZE TIMER ' Seed the random number generator - -' Initialize palette registers with sine wave colors -FOR paletteIndex = 0 TO 255 - OUT &H3C8, paletteIndex - OUT &H3C9, INT(SIN(paletteIndex / 21) * 30 + 30) - OUT &H3C9, INT(SIN(paletteIndex / 34) * 30 + 30) - OUT &H3C9, INT(SIN(paletteIndex / 10) * 30 + 30) -NEXT paletteIndex - -' Generate the surface pattern -FOR y = 1 TO 199 - FOR x = 1 TO 319 - prevPixel = POINT(x, y - 1) - leftPixel = POINT(x - 1, y) - diagPixel = POINT(x - 1, y - 1) - left2Pixel = POINT(x - 2, y) - - ' Calculate the average of surrounding pixels and add some randomness - newColor = (prevPixel + leftPixel + diagPixel + left2Pixel) \ 4 + (RND * 5 - 2) - - ' Clamp the color value within the valid range - IF newColor < 0 THEN newColor = 0 - IF newColor > 63 THEN newColor = 63 - - ' Set the pixel with the calculated color - PSET (x, y), newColor - NEXT x -NEXT y - -' Wait for user input to exit -userInput$ = INPUT$(1) - diff --git a/2D GFX/Textures/map2.bas b/2D GFX/Textures/map2.bas deleted file mode 100755 index 7fde5c0..0000000 --- a/2D GFX/Textures/map2.bas +++ /dev/null @@ -1,35 +0,0 @@ -' Old paper surface -' made by Svjatoslav Agejenko -' in 2003.12 -' H-Page: svjatoslav.eu -' E-Mail: svjatoslav@svjatoslav.eu - -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 - -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 -NEXT y -a$ = INPUT$(1) - -SYSTEM - diff --git a/2D GFX/Textures/map3.bas b/2D GFX/Textures/map3.bas deleted file mode 100755 index 927409b..0000000 --- a/2D GFX/Textures/map3.bas +++ /dev/null @@ -1,94 +0,0 @@ -DECLARE SUB DrawPixels (x1 AS INTEGER, y1 AS INTEGER, s AS INTEGER) -' Program to render cloud surface using diamond square algorithm. -' By Svjatoslav Agejenko. -' Email: svjatoslav@svjatoslav.eu -' Homepage: http://www.svjatoslav.eu -' -' Changelog: -' 2003.12, Initial version -' 2024.08, Improved program readability using AI - -DECLARE SUB DrawBox (x1 AS INTEGER, y1 AS INTEGER, s AS INTEGER) -DECLARE SUB SetPalette () -DECLARE SUB InitializeProgram () -DEFINT A-Z -InitializeProgram - -DIM SHARED maxLightness AS INTEGER -maxLightness = 127 - -DIM scale AS INTEGER -scale = 2 ^ 8 - -1 : -scale = scale \ 2 -x1 = (319 \ scale) - 1 -y1 = (199 \ scale) - 1 - -FOR y = 0 TO y1 - FOR x = 0 TO x1 - DrawPixels x * scale, y * scale, scale - NEXT x -NEXT y - -IF scale > 2 THEN GOTO 1 -WAITa$ = INPUT$(1) - -SUB DrawPixels (x1 AS INTEGER, y1 AS INTEGER, s AS INTEGER) - ' Get the lightness values for the corners of the box - c1 = POINT(x1, y1) - c2 = POINT(x1 + s, y1) - c3 = POINT(x1, y1 + s) - c4 = POINT(x1 + s, y1 + s) - - ' Calculate the midpoint lightness values - sp = s \ 2 - k = s * 2 - kp = k / 2 - - cc2 = ((c1 + c2) / 2) + (RND * k) - kp - IF cc2 > maxLightness THEN cc2 = maxLightness - IF cc2 < 0 THEN cc2 = 0 - - cc3 = ((c1 + c3) / 2) + (RND * k) - kp - IF cc3 > maxLightness THEN cc3 = maxLightness - IF cc3 < 0 THEN cc3 = 0 - - cc4 = ((c2 + c4) / 2) + (RND * k) - kp - IF cc4 > maxLightness THEN cc4 = maxLightness - IF cc4 < 0 THEN cc4 = 0 - - cc5 = ((c3 + c4) / 2) + (RND * k) - kp - IF cc5 > maxLightness THEN cc5 = maxLightness - IF cc5 < 0 THEN cc5 = 0 - - ' Calculate the central lightness value - cc1 = ((cc2 + cc3 + cc4 + cc5) / 4) + (RND * k) - kp - IF cc1 > maxLightness THEN cc1 = maxLightness - IF cc1 < 0 THEN cc1 = 0 - - ' Set the calculated lightness values for the box - PSET (x1 + sp, y1 + sp), cc1 - PSET (x1 + sp, y1), cc2 - PSET (x1, y1 + sp), cc3 - PSET (x1 + s, y1 + sp), cc4 - PSET (x1 + sp, y1 + s), cc5 -END SUB - -SUB InitializeProgram - ' Set the screen mode and initialize the color palette - SCREEN 13 - SetPalette - RANDOMIZE TIMER -END SUB - -SUB SetPalette - ' Set the color palette for lightness levels - FOR a = 0 TO 255 - OUT &H3C8, a - OUT &H3C9, a / 4 - OUT &H3C9, a / 3 - OUT &H3C9, a / 2.3 - NEXT a -END SUB - diff --git a/2D GFX/Textures/old paper.bas b/2D GFX/Textures/old paper.bas new file mode 100755 index 0000000..7fde5c0 --- /dev/null +++ b/2D GFX/Textures/old paper.bas @@ -0,0 +1,35 @@ +' Old paper surface +' made by Svjatoslav Agejenko +' in 2003.12 +' H-Page: svjatoslav.eu +' E-Mail: svjatoslav@svjatoslav.eu + +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 + +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 +NEXT y +a$ = INPUT$(1) + +SYSTEM + diff --git a/2D GFX/Textures/old paper.png b/2D GFX/Textures/old paper.png new file mode 100644 index 0000000..d9c900b Binary files /dev/null and b/2D GFX/Textures/old paper.png differ diff --git a/2D GFX/Textures/oldpaper.bas b/2D GFX/Textures/oldpaper.bas deleted file mode 100755 index 8bdca0d..0000000 --- a/2D GFX/Textures/oldpaper.bas +++ /dev/null @@ -1,84 +0,0 @@ -' Program to render surface resembling old paper. -' By Svjatoslav Agejenko. -' Email: svjatoslav@svjatoslav.eu -' Homepage: http://www.svjatoslav.eu -' -' Changelog: -' 2003.12, Initial version -' 2024.08, Improved program readability using AI - -DECLARE SUB DrawPaper (x1 AS INTEGER, y1 AS INTEGER, x2 AS INTEGER, y2 AS INTEGER) - -DEFINT A-Z -SCREEN 12 -RANDOMIZE TIMER - -' Set color palette -FOR colorIndex = 0 TO 15 - OUT &H3C8, colorIndex - OUT &H3C9, colorIndex * 3 - OUT &H3C9, colorIndex * 3 - OUT &H3C9, colorIndex * 2 -NEXT colorIndex - -' Generate and draw paper surfaces continuously until a key is pressed -1 - x1 = RND * 600 + 20 - x2 = RND * 600 + 20 - y1 = RND * 400 + 40 - y2 = RND * 400 + 40 - - ' Ensure x1 is less than x2 and y1 is less than y2 - IF x1 > x2 THEN SWAP x1, x2 - IF y1 > y2 THEN SWAP y1, y2 - - ' Draw the paper with the calculated coordinates - CALL DrawPaper(x1, y1, x2, y2) - - ' Continue drawing until any key is pressed - IF INKEY$ <> "" THEN SYSTEM -GOTO 1 - -SUB DrawPaper (x1 AS INTEGER, y1 AS INTEGER, x2 AS INTEGER, y2 AS INTEGER) - DIM c AS INTEGER - DIM z AS SINGLE - DIM p AS INTEGER - DIM c1 AS INTEGER - DIM yl AS INTEGER - - ' Initialize variables - yl = y2 + 1 - z = 0 - - ' Draw the bottom and right borders of the paper - LINE (x1, y1)-(x2, y1), 0 - LINE (x2, y1)-(x2, y2), 0 - - ' Generate the texture of the paper - FOR y = y1 + 1 TO y2 - c = 0 - FOR x = x1 TO x2 - p = p + 1 - - ' Randomly reset the pattern counter - IF p > 23 THEN - z = RND * 1 - p = 0 - END IF - - ' Get the color of the previous row - c1 = POINT(x, y - 1) - - ' Calculate the average color with random variation - c = (c1 + c) / 2 + (RND * (2 + (5 / y))) - (3 / (yl - y)) - z - - ' Clamp the color value within the range [0, 15] - IF c < 0 THEN c = 0 - IF c > 15 THEN c = 15 - - ' Set the pixel color for the current position - PSET (x - 1, y), c - NEXT x - NEXT y -END SUB - diff --git a/2D GFX/Textures/test3.bas b/2D GFX/Textures/test3.bas deleted file mode 100755 index c23659c..0000000 --- a/2D GFX/Textures/test3.bas +++ /dev/null @@ -1,27 +0,0 @@ -' Strange surface -' Made by Svjatoslav Agejenko in 2003.12 -' H-Page: svjatoslav.eu -' E-Mail: svjatoslav@svjatoslav.eu - -SCREEN 13 - -' Initialize the screen mode to 320x200 with 16 colors - -' Outer loop for the vertical axis (y-coordinate) -FOR ycoordinate = 1 TO 199 - ' Inner loop for the horizontal axis (x-coordinate) - FOR xcoordinate = 1 TO 319 - ' Calculate the sine value based on the squared distances from the origin - colorvalue = SIN((xcoordinate ^ 2 + ycoordinate ^ 2) / 10) * 10 - - ' Clamp the color value to the range [0, 15] - IF colorvalue < 0 THEN colorvalue = 0 - IF colorvalue > 15 THEN colorvalue = 15 - - ' Set the pixel color at (xcoordinate, ycoordinate) with an offset to use the full 16-color palette - PSET (xcoordinate, ycoordinate), colorvalue + 16 - NEXT xcoordinate -NEXT ycoordinate - -' Wait for a key press before exiting -WAIT 30, 1 \ No newline at end of file diff --git a/2D GFX/Textures/yellow flame.bas b/2D GFX/Textures/yellow flame.bas new file mode 100755 index 0000000..56ffcce --- /dev/null +++ b/2D GFX/Textures/yellow flame.bas @@ -0,0 +1,45 @@ +' Yellow flame +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 2003.12, Initial version +' 2024.08, Improved program readability using AI + + +DEFINT A-Z ' Define all variables as integers +SCREEN 13 ' Set graphics mode to 320x200 with 256 colors +RANDOMIZE TIMER ' Seed the random number generator + +' Initialize palette registers with sine wave colors +FOR paletteIndex = 0 TO 255 + OUT &H3C8, paletteIndex + OUT &H3C9, INT(SIN(paletteIndex / 21) * 30 + 30) + OUT &H3C9, INT(SIN(paletteIndex / 34) * 30 + 30) + OUT &H3C9, INT(SIN(paletteIndex / 10) * 30 + 30) +NEXT paletteIndex + +' Generate the surface pattern +FOR y = 1 TO 199 + FOR x = 1 TO 319 + prevPixel = POINT(x, y - 1) + leftPixel = POINT(x - 1, y) + diagPixel = POINT(x - 1, y - 1) + left2Pixel = POINT(x - 2, y) + + ' Calculate the average of surrounding pixels and add some randomness + newColor = (prevPixel + leftPixel + diagPixel + left2Pixel) \ 4 + (RND * 5 - 2) + + ' Clamp the color value within the valid range + IF newColor < 0 THEN newColor = 0 + IF newColor > 63 THEN newColor = 63 + + ' Set the pixel with the calculated color + PSET (x, y), newColor + NEXT x +NEXT y + +' Wait for user input to exit +userInput$ = INPUT$(1) + diff --git a/2D GFX/Textures/yellow flame.png b/2D GFX/Textures/yellow flame.png new file mode 100644 index 0000000..762a97b Binary files /dev/null and b/2D GFX/Textures/yellow flame.png differ