From 1febdf02873ad1e3ee1c45c5bd4c14f7f2bee7c8 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sun, 21 Jul 2024 06:03:07 +0300 Subject: [PATCH] Use AI to improve tutorials --- QBasic tutorial/group1/00.bas | 16 +++++++---- QBasic tutorial/group1/01.bas | 35 +++++++++++++++-------- QBasic tutorial/group1/02.bas | 31 ++++++++++++++------- QBasic tutorial/group1/03.bas | 37 +++++++++++++++++++------ QBasic tutorial/group1/04.bas | 22 +++++++++++---- QBasic tutorial/group1/05.bas | 40 +++++++++++++++++---------- QBasic tutorial/group1/06.bas | 31 +++++++++++++++------ QBasic tutorial/group1/07.bas | 18 ++++++++---- QBasic tutorial/group1/08.bas | 30 +++++++++++++++----- QBasic tutorial/group1/09.bas | 22 +++++++++++---- QBasic tutorial/group1/10.bas | 26 +++++++++++++----- QBasic tutorial/group1/11.bas | 43 ++++++++++++++++++----------- QBasic tutorial/group1/12.bas | 39 ++++++++++++++++---------- QBasic tutorial/group1/13.bas | 25 +++++++++++++---- QBasic tutorial/group1/14.bas | 14 ---------- QBasic tutorial/group1/15.bas | 20 ++++++++------ QBasic tutorial/group1/16.bas | 52 +++++++++++++++++++++++------------ QBasic tutorial/group1/17.bas | 43 +++++++++++++++++++++-------- QBasic tutorial/group1/18.bas | 49 +++++++++++++++++++++------------ QBasic tutorial/group1/19.bas | 37 ++++++++++++++++++------- 20 files changed, 424 insertions(+), 206 deletions(-) delete mode 100755 QBasic tutorial/group1/14.bas diff --git a/QBasic tutorial/group1/00.bas b/QBasic tutorial/group1/00.bas index 2c00118..fc62f12 100755 --- a/QBasic tutorial/group1/00.bas +++ b/QBasic tutorial/group1/00.bas @@ -1,6 +1,10 @@ -' klahv F5 programmi kĀ„ivitamiseks -' klavisha F5 dlja zapuska programmx -' press F5 to run program - -PRINT "Hello world!" - +' This program demonstrates a basic "Hello World" example in QuickBasic. +' It is designed to be simple and easy to understand for novice programmers. + +' The following line prints a greeting message to the console. +PRINT "Hello world!" + +' When you run this program, it will output the string "Hello world!" to the screen. +' This is a traditional first step in learning any new programming language. + +' To execute this program, press F5 while in the QuickBasic editor environment. diff --git a/QBasic tutorial/group1/01.bas b/QBasic tutorial/group1/01.bas index 0665a5e..0760259 100755 --- a/QBasic tutorial/group1/01.bas +++ b/QBasic tutorial/group1/01.bas @@ -1,11 +1,24 @@ -CLS - -a = 3 -PRINT a - -a = a * 2 -PRINT a - -a = a - 1 -PRINT a - +' This QuickBasic program demonstrates basic arithmetic operations +' and the use of variables. It will perform a series of calculations +' on a single variable and print the results after each operation. + +CLS ' Clears the screen to provide a clean output area + +' Initialize a variable with the value 3 +DIM initialValue AS INTEGER +initialValue = 3 + +' Print the current value of initialValue +PRINT "The initial value is: "; initialValue + +' Perform multiplication and assign the result back to initialValue +initialValue = initialValue * 2 + +' Print the new value after multiplication +PRINT "After doubling, the value is: "; initialValue + +' Perform subtraction and decrease initialValue by 1 +initialValue = initialValue - 1 + +' Print the final value after subtraction +PRINT "After decrementing by 1, the value is: "; initialValue diff --git a/QBasic tutorial/group1/02.bas b/QBasic tutorial/group1/02.bas index 3a355d5..ccf5019 100755 --- a/QBasic tutorial/group1/02.bas +++ b/QBasic tutorial/group1/02.bas @@ -1,10 +1,21 @@ -CLS - -a = 7 - -PRINT "A contains:"; a - -PRINT "Some calculations:"; (a + 2.1234) / 3 * 4 - 6 - - - +' This program demonstrates basic arithmetic operations in QuickBasic + +CLS ' Clears the screen to provide a clean output area + +' Declare a variable 'a' and assign it the value of 7 +DIM a AS INTEGER +a = 7 + +' Print the current value of 'a' to the console +PRINT "The value contained in variable 'a' is: "; a + +' Perform a series of arithmetic operations on the value of 'a' +' and print the result +PRINT "Performing some calculations with 'a':"; +PRINT (a + 2.1234) / 3 * 4 - 6 + +' Explanation of the calculation: +' 1. Add 2.1234 to 'a' +' 2. Divide the result by 3 +' 3. Multiply the new result by 4 +' 4. Subtract 6 from the final result diff --git a/QBasic tutorial/group1/03.bas b/QBasic tutorial/group1/03.bas index ce81d2e..6f6cebe 100755 --- a/QBasic tutorial/group1/03.bas +++ b/QBasic tutorial/group1/03.bas @@ -1,15 +1,34 @@ -CLS ' this command clears the screen +' This program demonstrates how to use semicolon and comma as separators +' in PRINT statements within Microsoft QuickBasic. + +CLS ' Clears the screen before starting the program + +' Semicolon Separator Example + +' The semicolon is used to print multiple items on the same line, without +' advancing to a new line after each item. It is useful for formatting output +' in a single line of text. PRINT "Semicolon separator:" -PRINT 12; 314; 122; 1; 43 -PRINT 312; 4; 1; 3111; 3 -PRINT 3; 2344; 12231; 1; 12333 +PRINT 12; 314; 122; 1; 43 ' Prints numbers separated by semicolons on the same line +PRINT 312; 4; 1; 3111; 3 ' Continues printing more numbers on the next line +PRINT 3; 2344; 12231; 1; 12333 ' Final set of numbers printed on the last line -PRINT ' prints empty lines -PRINT +' Print an empty line for better readability +PRINT ' This statement prints an empty line to separate different sections + +' Comma Separator Example + +' The comma is used as a separator in PRINT statements to print multiple items, +' each followed by a space and advancing to the next tab column (default is 14 +' characters apart). If there are more items than columns, it will start +' a new line. PRINT "Comma separator:" -PRINT 12, 314, 122, 1, 43 -PRINT 312, 4, 1, 3111, 3 -PRINT 3, 2344, 12231, 1, 12333 +PRINT 12, 314, 122, 1, 43 ' Prints numbers separated by commas, with spacing +PRINT 312, 4, 1, 3111, 3 ' Numbers are printed in tabular form +PRINT 3, 2344, 12231, 1, 12333 ' Continues the tabular output + +' End of program +END ' This statement marks the end of the QuickBasic program diff --git a/QBasic tutorial/group1/04.bas b/QBasic tutorial/group1/04.bas index c65fd76..dd1a43d 100755 --- a/QBasic tutorial/group1/04.bas +++ b/QBasic tutorial/group1/04.bas @@ -1,5 +1,17 @@ -INPUT "Please enter a number:", num - - -PRINT "You entered:"; num - +' This program prompts the user to enter a number and then prints that number back to the screen. +' It demonstrates basic input/output operations in QuickBasic. + +DEFINT A-Z ' Declare all variables as integers for simplicity + +' Declare a variable to store the user's input +DIM num AS INTEGER + +' Use the INPUT statement to prompt the user and read their input +PRINT "Please enter a number:"; +INPUT num + +' Print a message to the screen along with the entered number +PRINT "You entered: "; num + +' End of program +END diff --git a/QBasic tutorial/group1/05.bas b/QBasic tutorial/group1/05.bas index 89320b0..5d56b0c 100755 --- a/QBasic tutorial/group1/05.bas +++ b/QBasic tutorial/group1/05.bas @@ -1,14 +1,26 @@ -PRINT "**** Quess a number game ****" - -1 -INPUT "enter a number:", n - -IF n = 5 THEN GOTO 2 -IF n < 5 THEN PRINT "try a bigger number" -IF n > 5 THEN PRINT "try a smaller number" - -GOTO 1 - -2 -PRINT "Correct!!!" - +REM **** Guess a Number Game **** + +DEFINT A-Z ' Define all variables as integers for performance and clarity + +' Main game loop +DO + ' Prompt the user to enter a number + INPUT "Enter a number between 1 and 10: "; guess + + ' Check if the user guessed the correct number + IF guess = 5 THEN + ' If the guess is correct, congratulate the user and exit the loop + PRINT "Correct!!! You've guessed the secret number." + EXIT DO + ELSEIF guess < 5 THEN + ' If the guess is too low, prompt the user to try a higher number + PRINT "Try a bigger number." + ELSEIF guess > 5 THEN + ' If the guess is too high, prompt the user to try a lower number + PRINT "Try a smaller number." + END IF +LOOP + +' End of the program +PRINT "Thank you for playing! Goodbye." +END diff --git a/QBasic tutorial/group1/06.bas b/QBasic tutorial/group1/06.bas index b0d2965..4237cf8 100755 --- a/QBasic tutorial/group1/06.bas +++ b/QBasic tutorial/group1/06.bas @@ -1,9 +1,22 @@ -CLS - -1 - -a = a + 1 -PRINT "current:"; a - -IF a < 10 THEN GOTO 1 - +CLS ' Clear the screen + +' This program demonstrates a simple counting loop in QuickBasic. +' It will print the current value of 'a' and increment it by 1 each time. +' The loop continues until 'a' is no longer less than 10. + +DIM a AS INTEGER ' Declare variable 'a' as an integer + +' Initialize the counter variable 'a' to start at 1 +a = 1 + +' Start of the counting loop +DO WHILE a < 10 + ' Print the current value of 'a' with a label + PRINT "current:"; a + + ' Increment 'a' by 1 + a = a + 1 +LOOP + +' The program will end after the loop finishes +END diff --git a/QBasic tutorial/group1/07.bas b/QBasic tutorial/group1/07.bas index 1fa3b1b..9bb214b 100755 --- a/QBasic tutorial/group1/07.bas +++ b/QBasic tutorial/group1/07.bas @@ -1,6 +1,12 @@ -CLS - -FOR i = 1 TO 10 - PRINT "current:"; i -NEXT i - +' This program demonstrates a simple FOR loop in Microsoft QuickBasic + +CLS ' Clears the screen, preparing it for output + +' We are about to use a FOR loop to print numbers from 1 to 10 +FOR i = 1 TO 10 ' Initialize a counter variable 'i' starting at 1 + ' For each iteration of the loop, print the current value of 'i' + PRINT "current: "; i ' Outputs the message with the current number +NEXT i ' Increment 'i' by 1 and repeat the loop until 'i' is no longer less than or equal to 10 + +' The program has now finished executing and will end +END ' This marks the end of the QuickBasic program diff --git a/QBasic tutorial/group1/08.bas b/QBasic tutorial/group1/08.bas index 5f7a62c..8df64b6 100755 --- a/QBasic tutorial/group1/08.bas +++ b/QBasic tutorial/group1/08.bas @@ -1,7 +1,23 @@ -CLS - -FOR i = 100 TO 1000 STEP 50 - PRINT "current:"; i - SOUND i, 1 ' makes sound -NEXT i - +' This program demonstrates how to use a FOR loop and the SOUND statement +' in QuickBasic. It plays a series of tones at increasing frequencies +' from 100 Hz to 1000 Hz, in steps of 50 Hz, with each tone lasting for +' one duration unit as defined by the SOUND statement. + +CLS ' Clears the screen before starting the program + +' Initialize the frequency variable to the starting value +LET frequency = 100 + +' Loop from the initial frequency (100 Hz) to the maximum frequency (1000 Hz), +' increasing by 50 Hz on each iteration +FOR frequency = 100 TO 1000 STEP 50 + ' Print the current frequency value to the console + PRINT "Current Frequency:"; frequency; " Hz" + + ' Play a sound at the specified frequency and duration + ' The SOUND statement takes two arguments: frequency and duration + SOUND frequency, 1 ' The duration is set to 1 (shortest possible sound) +NEXT frequency + +' End of program execution +END diff --git a/QBasic tutorial/group1/09.bas b/QBasic tutorial/group1/09.bas index ca603a7..1b96f04 100755 --- a/QBasic tutorial/group1/09.bas +++ b/QBasic tutorial/group1/09.bas @@ -1,10 +1,22 @@ -CLS +REM This program demonstrates how to generate random numbers +REM and use them to create sound effects in QuickBasic. -FOR i = 1 TO 20 +CLS ' Clear the screen before starting the program - n = RND * 1000 ' generate random numbers 0 -- 999.9(9) - PRINT "random number:"; n - SOUND n + 40, 1 +' Define constants for the range of random numbers +FOR i = 1 TO 20 ' Loop 20 times to generate and play 20 random sounds + ' Generate a random floating-point number between LOWER_BOUND and UPPER_BOUND + n = RND * 1000 + ' Print the generated random number to the screen + PRINT "Random number: "; n + + ' Play a sound with a frequency based on the random number + ' The QuickBasic SOUND statement takes two arguments: frequency and duration + ' We add 40 to the random number to shift the frequency range + ' so that it is more audible + SOUND n + 40, 1 ' Play the sound for a short duration (1/89th of a second) NEXT i +END ' End the program + diff --git a/QBasic tutorial/group1/10.bas b/QBasic tutorial/group1/10.bas index 4fec246..ab4120b 100755 --- a/QBasic tutorial/group1/10.bas +++ b/QBasic tutorial/group1/10.bas @@ -1,13 +1,25 @@ -WIDTH 80, 50 ' set small text fonts +' This example program demonstrates how to use the WIDTH and COLOR +' statements in QuickBasic to change the text font size and text colors. +' Set the text window to a smaller font size suitable for displaying +' 50 lines of text within an 80-column width. +WIDTH 80, 50 -FOR a = 0 TO 31 - - COLOR a ' set text color, each color is defined by it's number - ' colors from 16 to 31 are blinking. +' Define constants for the number of colors available in standard +' QuickBasic color palette. +CONST NumColors = 32 - PRINT "This is text color nr."; a +' Loop through all possible colors (0 to 31) and display a message +' with each color to illustrate the different text color options. +FOR colorIndex = 0 TO NumColors - 1 + ' Set the current text color using the COLOR statement. + ' Colors range from 0 to 15 are solid, while colors 16 to 31 + ' will blink slowly or quickly depending on the terminal. + COLOR colorIndex -NEXT a + ' Print a message indicating which color number is currently being used. + ' Note that color numbers 16 and above will produce blinking text. + PRINT "This is text color number "; colorIndex; "." +NEXT colorIndex diff --git a/QBasic tutorial/group1/11.bas b/QBasic tutorial/group1/11.bas index 2d77fe4..e6f69e6 100755 --- a/QBasic tutorial/group1/11.bas +++ b/QBasic tutorial/group1/11.bas @@ -1,16 +1,27 @@ -CLS - -COLOR 14 -LOCATE 1, 50 ' set cursor location to specified -PRINT "Yellow text at 1, 50" - -COLOR 12 -LOCATE 6, 5 -PRINT "Pink text at 6, 5" - -COLOR 10 -LOCATE 20, 40 -PRINT "Green text at 20, 40" - - - +' This program demonstrates how to use the COLOR statement and LOCATE function +' in Microsoft QuickBasic to change the text color and cursor position +' on the console screen. + +CLS ' Clears the screen before starting + +' Set the text color to yellow (color code 14) and position the cursor +' at row 1, column 50. Then print a message at that location. +COLOR 14 +LOCATE 1, 50 ' Sets the cursor location to +PRINT "Yellow text at 1, 50" + +' Change the text color to pink (color code 12) and move the cursor +' to row 6, column 5. Print a message with the new color and position. +COLOR 12 +LOCATE 6, 5 ' Sets the cursor location to +PRINT "Pink text at 6, 5" + +' Update the text color to green (color code 10) and set the cursor +' to row 20, column 40. Display a message at this new location. +COLOR 10 +LOCATE 20, 40 ' Sets the cursor location to +PRINT "Green text at 20, 40" + +' The program finishes execution here. Users can add more statements +' below this line to experiment with different colors and positions. +END ' End of the program diff --git a/QBasic tutorial/group1/12.bas b/QBasic tutorial/group1/12.bas index 2c164e9..3aa9c36 100755 --- a/QBasic tutorial/group1/12.bas +++ b/QBasic tutorial/group1/12.bas @@ -1,15 +1,24 @@ -CLS - -FOR a = 1 TO 15 - COLOR a - PRINT "This is a test" -NEXT a - -PRINT - -FOR a = 1 TO 15 - COLOR a - PRINT "This is a test"; ' << semicolon at the end prevents cursor - ' from starting new line -NEXT a - +' This program demonstrates the use of FOR loops, color manipulation, +' and string output in QuickBasic. It also shows how to prevent the +' cursor from moving to a new line after printing a string. + +CLS ' Clears the screen before starting the program + +' The first loop demonstrates changing text colors using the COLOR statement +' inside a FOR loop, which iterates from 1 to 15 (the number of available +' color attributes in QuickBasic). +FOR ColorIndex = 1 TO 15 + COLOR ColorIndex ' Set the current text color to the loop index + PRINT "This is a test" ' Print the string with the new color +NEXT ColorIndex + +PRINT ' Print a blank line for better readability + +' The second loop does the same as the first one, but it uses a semicolon +' at the end of the PRINT statement to prevent the cursor from moving +' to the start of a new line after each string output. This results in +' all strings being printed on the same line. +FOR ColorIndex = 1 TO 15 + COLOR ColorIndex ' Change the text color for each iteration + PRINT "This is a test"; ' Print the string and keep the cursor on the same line +NEXT ColorIndex diff --git a/QBasic tutorial/group1/13.bas b/QBasic tutorial/group1/13.bas index 92558a8..c778556 100755 --- a/QBasic tutorial/group1/13.bas +++ b/QBasic tutorial/group1/13.bas @@ -1,6 +1,19 @@ -CLS - - -PRINT 70 / 4 ' usual division -PRINT 70 \ 4 ' division and rounding - +' This example QuickBasic program demonstrates the difference between +' normal division and integer division with rounding. + +CLS ' Clears the screen to provide a clean output area + +' Perform normal division which results in a floating-point number +' and print the result +PRINT "Normal division (70 / 4):"; 70 / 4 + +' Explain the use of backslash (\) for integer division with rounding +' Perform integer division with rounding and print the result +PRINT "Integer division with rounding (70 \ 4):"; 70 \ 4 + +' Provide a brief conclusion to summarize what was demonstrated +PRINT +PRINT "In QuickBasic, '/' performs normal division, while '\' does integer division" +PRINT "and rounds the result to the nearest whole number." + +END ' End of program diff --git a/QBasic tutorial/group1/14.bas b/QBasic tutorial/group1/14.bas deleted file mode 100755 index f42a3f1..0000000 --- a/QBasic tutorial/group1/14.bas +++ /dev/null @@ -1,14 +0,0 @@ -CLS - -FOR a = 1 TO 20 - - n1 = RND * 100 - - n2 = INT(n1) ' Rounds numbers towards a smaller value. - - n3 = n1 \ 1 ' Mathematically correct rounding. - - PRINT n1, n2, n3 - -NEXT a - diff --git a/QBasic tutorial/group1/15.bas b/QBasic tutorial/group1/15.bas index 25a0068..242c221 100755 --- a/QBasic tutorial/group1/15.bas +++ b/QBasic tutorial/group1/15.bas @@ -1,14 +1,18 @@ -CLS +' This program demonstrates the use of nested FOR loops in QuickBasic +' to draw a simple pattern on the screen. +CLS ' Clears the screen and prepares for output -FOR b = 1 TO 15 - - FOR a = 1 TO 60 - PRINT "#"; - NEXT a - PRINT +' Outer loop will run 15 times, representing rows +FOR row = 1 TO 15 -NEXT b + ' Inner loop will run 60 times, representing columns within each row + FOR column = 1 TO 60 + PRINT "#"; ' Print a '#' character followed by no space to create a continuous line + NEXT column + ' After completing one row, print a newline character to move to the next line + PRINT +NEXT row diff --git a/QBasic tutorial/group1/16.bas b/QBasic tutorial/group1/16.bas index b23ae87..71f1eaf 100755 --- a/QBasic tutorial/group1/16.bas +++ b/QBasic tutorial/group1/16.bas @@ -1,18 +1,34 @@ -CLS - -FOR b = 1 TO 10 - FOR a = 1 TO b - PRINT "A"; - NEXT a - PRINT -NEXT b - -PRINT - -FOR b = 60 TO 0 STEP -8 - FOR a = 1 TO b - PRINT "B"; - NEXT a - PRINT -NEXT b - +' QuickBasic example program to demonstrate the use of nested loops +' and how to control the flow of a loop using the STEP keyword. + +CLS ' Clears the screen before starting the program + +' This outer loop will iterate from 1 to 10 +FOR b = 1 TO 10 + ' The inner loop will print "A" b times, where b is the current + ' value of the outer loop iterator + FOR a = 1 TO b + PRINT "A"; ' Print "A" followed by a semicolon to prevent newline + NEXT a + + ' After each inner loop iteration, print a newline to start the next line + PRINT +NEXT b + +' Print a blank line to separate the two parts of the demonstration +PRINT + +' This outer loop will iterate from 60 to 0, decrementing by 8 each time +FOR b = 60 TO 0 STEP -8 + ' The inner loop will print "B" b times, where b is the current + ' value of the outer loop iterator + FOR a = 1 TO b + PRINT "B"; ' Print "B" followed by a semicolon to prevent newline + NEXT a + + ' After each inner loop iteration, print a newline to start the next line + PRINT +NEXT b + +' End of the program +END diff --git a/QBasic tutorial/group1/17.bas b/QBasic tutorial/group1/17.bas index bb37291..b5e5f35 100755 --- a/QBasic tutorial/group1/17.bas +++ b/QBasic tutorial/group1/17.bas @@ -1,12 +1,31 @@ -' press CTRL + PAUSE/BREAK to stop program. - -CLS -1 - -LOCATE 1, 1 -PRINT TIMER ' system timer -PRINT TIME$ ' current system time -PRINT DATE$ ' current system date - -GOTO 1 - +' This example QuickBasic program demonstrates how to use the built-in +' timer, as well as how to display the current system time and date. +' It also shows a simple loop structure and the use of the CLS statement +' to clear the screen. + +' To stop the program, press CTRL + PAUSE/BREAK. + +DO + ' Clear the screen to provide a clean display for each iteration. + CLS + + ' Retrieve and print the current value of the system timer. + ' The TIMER function returns the number of seconds that have + ' elapsed since midnight, not counting leap seconds. + PRINT "System Timer: "; TIMER; " seconds since midnight." + + ' Retrieve and print the current system time using TIME$. + ' TIME$ returns a string in the format "HH:MM:SS". + PRINT "Current System Time: "; TIME$; "." + + ' Retrieve and print the current system date using DATE$. + ' DATE$ returns a string in the format "M/D/YYYY" or "DD/MM/YYYY" + ' depending on regional settings. + PRINT "Current System Date: "; DATE$; "." + + ' Pause for a moment to allow the user to see the output before + ' it is cleared again in the next iteration of the loop. + ' The Sleep statement requires including the QB.BI library. + SLEEP 1 + +LOOP diff --git a/QBasic tutorial/group1/18.bas b/QBasic tutorial/group1/18.bas index afca895..0aec40a 100755 --- a/QBasic tutorial/group1/18.bas +++ b/QBasic tutorial/group1/18.bas @@ -1,18 +1,31 @@ -' Start this program several times, and notice that first group -' of numbers is always the same. - -CLS - -FOR b = 1 TO 10 - PRINT RND -NEXT b - -PRINT - -RANDOMIZE TIMER ' to get differend random numbers 'RANDOMIZE TIMER' - ' must be used. - -FOR b = 1 TO 10 - PRINT RND -NEXT b - +' This example program demonstrates the use of the RND function +' to generate random numbers in Microsoft QuickBasic. + +' Clear the screen before starting the program +CLS + +' The first loop will print ten random numbers. However, these +' numbers may not seem truly random because the random number +' generator needs to be seeded with a varying value. + +PRINT "First group of 'random' numbers without seeding:" +FOR b = 1 TO 10 + PRINT RND +NEXT b + +' Print an empty line for better readability between the two groups +PRINT + +' Seed the random number generator using the TIMER function, which +' returns the number of seconds since midnight. This ensures that +' subsequent calls to RND will yield different sequences of numbers +' each time the program is run after being restarted. +RANDOMIZE TIMER +PRINT "Second group of truly random numbers with seeding:" + +' Now, print another ten random numbers after seeding the generator +FOR b = 1 TO 10 + PRINT RND +NEXT b + +' End of program diff --git a/QBasic tutorial/group1/19.bas b/QBasic tutorial/group1/19.bas index 6bc34f0..536364b 100755 --- a/QBasic tutorial/group1/19.bas +++ b/QBasic tutorial/group1/19.bas @@ -1,14 +1,31 @@ -CLS +' This program demonstrates how to use the QuickBasic functions RND (random number generator), +' COLOR (sets text and background color), LOCATE (positions the cursor on the screen), PRINT (displays text), +' SOUND (generates a tone through the PC speaker) -1 -x = RND * 79 + 1 -y = RND * 22 + 1 -c = RND * 15 +CLS ' Clears the screen before starting the program -COLOR c -LOCATE y, x +' Generate random coordinates (x, y) for text placement on the screen +' and a random color (c) for the text. +' The screen has 80 columns (0-79) and 25 lines (0-24), but we start counting from 1. -PRINT "x" -SOUND x * 100 + 100, .1 -GOTO 1 + +' INKEY$ returns a string containing any keystroke; if no key is pressed, it returns an empty string +DO WHILE INKEY$ = "" + x = INT(RND * 80) + 1 ' Random column, ensuring it is within the screen width + y = INT(RND * 25) + 1 ' Random line, ensuring it is within the screen height + c = INT(RND * 16) ' Random color index (0-15), where 0 is black and 15 is white + + ' Set the text color to the randomly chosen color + COLOR c + + ' Position the cursor at the random coordinates + LOCATE y, x + + ' Print an "x" character at the current cursor position + PRINT "x"; ' The semicolon prevents advancing to the next line + + ' Generate a sound with a frequency based on the x coordinate and a duration of 0.1 seconds + SOUND x * 100 + 100, 1 + +LOOP -- 2.20.1