+' Program author:\r
' Svjatoslav Agejenko\r
-' year: 2001\r
-' alien text\r
+' email: svjatoslav@svjatoslav.eu\r
+' homepage: https://svjatoslav.eu\r
+'\r
+' Program attempts to render imaginary alien text.\r
+' Text is composed by subdividing square into 4 triangles.\r
+'\r
+' 2001, Initial version.\r
+' 2024.08, Improved code readability.\r
\r
DEFINT A-Z\r
-DECLARE SUB prch (x, y, n, s)\r
-DIM SHARED co(1 TO 4)\r
-co(1) = 7\r
-co(2) = 7\r
-co(3) = 0\r
-co(4) = 0\r
\r
+' Declare the subroutine which will draw a character at a given position with a given size and color\r
+DECLARE SUB DrawCharacter (characterX, characterY, characterColor, CharacterSize)\r
\r
+' Define shared array for colors\r
+DIM SHARED characterColors(1 TO 4) AS INTEGER\r
+\r
+' Initialize the color palette\r
+characterColors(1) = 7 ' LightGray\r
+characterColors(2) = 7 ' LightGray\r
+characterColors(3) = 0 ' Black\r
+characterColors(4) = 0 ' Black\r
+\r
+' Set the screen mode and seed the random number generator\r
SCREEN 12\r
RANDOMIZE TIMER\r
\r
+' Clear the screen with black color\r
PAINT (1, 1), 0\r
\r
-siz = 4\r
+' Define the size of each character\r
+CONST CharacterSize = 4\r
\r
+' Initialize counters for drawing characters\r
+DIM tmp AS INTEGER\r
tmp = 0\r
-FOR y = 1 TO 480 - siz - 2 STEP siz + (siz \ 2)\r
-tmp1 = 0\r
-FOR x = 1 TO 640 - siz - 2 STEP siz + (siz \ 2)\r
-prch x, y, RND * 16, siz\r
-tmp1 = tmp1 + 1\r
-IF tmp1 > 20 THEN tmp1 = 0: x = x + (siz)\r
-NEXT x\r
-tmp = tmp + 1\r
-IF tmp > 5 THEN tmp = 0: y = y + (siz)\r
-NEXT y\r
-\r
-SUB prch (x, y, n, s)\r
-sp = s \ 2\r
-\r
-c = co(RND * 3 + 1)\r
-LINE (x, y)-(x + s, y), c\r
-LINE (x, y)-(x + sp, y + sp), c\r
-LINE (x + s, y)-(x + sp, y + sp), c\r
-PAINT (x + 2, y + 1), c\r
-\r
-c = co(RND * 3 + 1)\r
-LINE (x, y)-(x, y + s), c\r
-LINE (x, y)-(x + sp, y + sp), c\r
-LINE (x, y + s)-(x + sp, y + sp), c\r
-PAINT (x + 1, y + 2), c\r
-\r
-c = co(RND * 3 + 1)\r
-LINE (x + s, y)-(x + s, y + s), c\r
-LINE (x + s, y)-(x + sp, y + sp), c\r
-LINE (x + s, y + s)-(x + sp, y + sp), c\r
-PAINT (x + s - 1, y + 2), c\r
-\r
-c = co(RND * 3 + 1)\r
-LINE (x, y + s)-(x + s, y + s), c\r
-LINE (x, y + s)-(x + sp, y + sp), c\r
-LINE (x + s, y + s)-(x + sp, y + sp), c\r
-PAINT (x + 2, y + s - 1), c\r
\r
+' Outer loop for vertical positioning of characters\r
+FOR characterY = 1 TO 480 - CharacterSize - 2 STEP CharacterSize + (CharacterSize \ 2)\r
+ DIM tmp1 AS INTEGER\r
+ tmp1 = 0\r
+\r
+ ' Inner loop for horizontal positioning of characters\r
+ FOR characterX = 1 TO 640 - CharacterSize - 2 STEP CharacterSize + (CharacterSize \ 2)\r
+ ' Draw a character with random color and specified size at the current position\r
+ CALL DrawCharacter(characterX, characterY, INT(RND * 16), CharacterSize)\r
+\r
+ ' Increment the inner loop counter\r
+ tmp1 = tmp1 + 1\r
+\r
+ ' Add spaces to emulate visual character clusters\r
+ IF tmp1 > 20 THEN\r
+ tmp1 = 0\r
+ characterX = characterX + (CharacterSize)\r
+ END IF\r
+ NEXT characterX\r
+\r
+ ' Increment the outer loop counter\r
+ tmp = tmp + 1\r
+\r
+ ' Add space to group caracters visually into clusters\r
+ IF tmp > 5 THEN\r
+ tmp = 0\r
+ characterY = characterY + (CharacterSize)\r
+ END IF\r
+NEXT characterY\r
+\r
+' Subroutine to draw a character at a given position with a given size and color\r
+SUB DrawCharacter (characterX AS INTEGER, characterY AS INTEGER, characterColor AS INTEGER, CharacterSize AS INTEGER)\r
+ ' Calculate half the size of the character for drawing diagonals\r
+ DIM halfSize AS INTEGER\r
+ halfSize = CharacterSize \ 2\r
+\r
+ ' Randomly select a color from the palette\r
+ DIM randomColor AS INTEGER\r
+ randomColor = characterColors(INT(RND * 3) + 1)\r
+\r
+ ' Draw the top horizontal line and diagonals of the character\r
+ LINE (characterX, characterY)-(characterX + CharacterSize, characterY), randomColor\r
+ LINE (characterX, characterY)-(characterX + halfSize, characterY + halfSize), randomColor\r
+ LINE (characterX + CharacterSize, characterY)-(characterX + halfSize, characterY + halfSize), randomColor\r
+ ' Fill the top right corner of the character\r
+ PAINT (characterX + 2, characterY + 1), randomColor\r
+\r
+ ' Draw the left vertical line and diagonals of the character\r
+ randomColor = characterColors(INT(RND * 3) + 1)\r
+ LINE (characterX, characterY)-(characterX, characterY + CharacterSize), randomColor\r
+ LINE (characterX, characterY)-(characterX + halfSize, characterY + halfSize), randomColor\r
+ LINE (characterX, characterY + CharacterSize)-(characterX + halfSize, characterY + halfSize), randomColor\r
+ ' Fill the middle left of the character\r
+ PAINT (characterX + 1, characterY + 2), randomColor\r
+\r
+ ' Draw the right vertical line and diagonals of the character\r
+ randomColor = characterColors(INT(RND * 3) + 1)\r
+ LINE (characterX + CharacterSize, characterY)-(characterX + CharacterSize, characterY + CharacterSize), randomColor\r
+ LINE (characterX + CharacterSize, characterY)-(characterX + halfSize, characterY + halfSize), randomColor\r
+ LINE (characterX + CharacterSize, characterY + CharacterSize)-(characterX + halfSize, characterY + halfSize), randomColor\r
+ ' Fill the middle right of the character\r
+ PAINT (characterX + CharacterSize - 1, characterY + 2), randomColor\r
+\r
+ ' Draw the bottom horizontal line and diagonals of the character\r
+ randomColor = characterColors(INT(RND * 3) + 1)\r
+ LINE (characterX, characterY + CharacterSize)-(characterX + CharacterSize, characterY + CharacterSize), randomColor\r
+ LINE (characterX, characterY + CharacterSize)-(characterX + halfSize, characterY + halfSize), randomColor\r
+ LINE (characterX + CharacterSize, characterY + CharacterSize)-(characterX + halfSize, characterY + halfSize), randomColor\r
+ ' Fill the bottom left corner of the character\r
+ PAINT (characterX + 2, characterY + CharacterSize - 1), randomColor\r
END SUB\r
\r
-' Determine avaiable video modes\r
-' made by Svjatoslav Agejenko\r
-' in 2001\r
-' homepage: svjatoslav.eu\r
-' email: svjatoslav@svjatoslav.eu\r
- \r
-' program to determine avaiable video modes\r
-' it assumes that 1 is always avaiable\r
-\r
-DIM SHARED mo(1 TO 100)\r
-ON ERROR GOTO 1\r
-b = 1\r
-a = 0\r
-2\r
-SCREEN a\r
-'PRINT "mode", a\r
-'a$ = INPUT$(1)\r
-mo(b) = a\r
-b = b + 1\r
-a = a + 1\r
-GOTO 2\r
-\r
-\r
-1\r
-a = a + 1\r
-IF a > 1000 THEN\r
+' Determine available video modes\r
+' Improved and commented version of the original program by Svjatoslav Agejenko (2001)\r
+' Homepage: svjatoslav.eu\r
+' Email: svjatoslav@svjatoslav.eu\r
+\r
+' This program determines the available video modes on a computer.\r
+' It is based on the assumption that video mode 1 is always available.\r
+\r
+DIM SHARED AvailableModes(1 TO 100) AS INTEGER\r
+ON ERROR GOTO ErrorHandler\r
+\r
+' Initialize the video mode counter and the current mode number.\r
+currentModeIndex = 1\r
+currentModeNumber = 0\r
+\r
+' Start the loop to test each video mode.\r
+DO\r
+ ' Attempt to set the screen to the current video mode.\r
+ SCREEN currentModeNumber\r
+\r
+ ' Increment the mode number for the next iteration.\r
+ currentModeNumber = currentModeNumber + 1\r
+\r
+ ' Store the successful video mode in the array.\r
+ AvailableModes(currentModeIndex) = currentModeNumber - 1\r
+\r
+ ' Move to the next index in the array.\r
+ currentModeIndex = currentModeIndex + 1\r
+\r
+LOOP\r
+\r
+' Error handling routine when an error occurs (e.g., invalid video mode).\r
+ErrorHandler:\r
+' Increment the mode number to continue testing after an error.\r
+currentModeNumber = currentModeNumber + 1\r
+\r
+' Check if we have reached the maximum number of modes to test.\r
+IF currentModeNumber > 1000 THEN\r
+ ' Reset the screen to text mode (usually mode 1).\r
SCREEN 1\r
- PRINT "Avaiable video modes on this computer:"\r
- FOR a = 1 TO b - 1\r
- PRINT mo(a)\r
- NEXT a\r
+\r
+ ' Display the list of available video modes.\r
+ PRINT "Available video modes on this computer:"\r
+ FOR modeIndex = 1 TO currentModeIndex - 1\r
+ PRINT AvailableModes(modeIndex)\r
+ NEXT modeIndex\r
+\r
+ ' End the program after displaying the results.\r
END\r
END IF\r
-RESUME\r
\r
+' Resume execution after an error to continue testing modes.\r
+RESUME
\ No newline at end of file