From: Svjatoslav Agejenko Date: Mon, 22 Jul 2024 10:18:56 +0000 (+0300) Subject: AI improved tutorials by adding comments and fixing code style X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=032e72e185512be8db9b34af1460d53e0dc71a87;p=qbasicapps.git AI improved tutorials by adding comments and fixing code style --- diff --git a/QBasic tutorial/Group 3/00.bas b/QBasic tutorial/Group 3/00.bas index 91414f8..c01682c 100755 --- a/QBasic tutorial/Group 3/00.bas +++ b/QBasic tutorial/Group 3/00.bas @@ -1,7 +1,21 @@ -SCREEN 13 ' set video mode 320 x 200 256 colors - -PRINT "Hello..." - -PSET (160, 100), 10 ' draws a point - ' x=160 y=100 color=10 - +' This program demonstrates how to set the video mode to 320x200 with 256 colors +' and how to draw a single point on the screen using QuickBasic. + +SCREEN 13 ' Set video mode to 320 x 200 with 256 colors + +' Greet the user with a simple message +PRINT "Hello..." + +' Define constants for the center of the screen for readability +CONST CenterX = 160 +CONST CenterY = 100 + +' Draw a point on the screen at the defined center coordinates +' with a specified color. +PSET (CenterX, CenterY), 10 ' Draws a point at (x=160, y=100) with color 10 + +' Wait for a key press before exiting the program +PRINT "Press any key to exit..." +WHILE INKEY$ = "" + ' Do nothing until a key is pressed +WEND diff --git a/QBasic tutorial/Group 3/01.bas b/QBasic tutorial/Group 3/01.bas index 938bc41..2575df0 100755 --- a/QBasic tutorial/Group 3/01.bas +++ b/QBasic tutorial/Group 3/01.bas @@ -1,9 +1,18 @@ -SCREEN 13 - -FOR y = 50 TO 150 - FOR x = 100 TO 200 - PSET (x, y), 10 - NEXT x - SOUND y, 1 -NEXT y - +' QuickBasic example program to demonstrate drawing pixels on the screen +' and generating simple sound with varying frequency. + +SCREEN 13 ' Set the graphics mode to 320x200 resolution with 256 colors + +' Loop to draw a vertical line of pixels from y-coordinate 50 to 150 +FOR y = 50 TO 150 + ' Loop to draw a horizontal line of pixels from x-coordinate 100 to 200 + FOR x = 100 TO 200 + PSET (x, y), 10 ' Set the pixel at (x, y) to color 10 + NEXT x + + ' Generate a sound with a frequency corresponding to the y-coordinate + ' The SOUND statement takes two arguments: frequency and duration + ' Here, the frequency is set to the current value of y, and the duration + ' is set to 1 tick (approximately 1/18th of a second) + SOUND y, 1 +NEXT y diff --git a/QBasic tutorial/Group 3/02.bas b/QBasic tutorial/Group 3/02.bas index 11df674..adf3b10 100755 --- a/QBasic tutorial/Group 3/02.bas +++ b/QBasic tutorial/Group 3/02.bas @@ -1,25 +1,27 @@ -DECLARE SUB box (x1!, y1!, x2!, y2!, c!) - -' Press F2 to see submodules -' Nazmi F2 xtob uvidet SUB moduli -' Vajuta F2 et n„ha SUB mooduleid - - -SCREEN 13 - -box 10, 10, 100, 100, 15 - -box 30, 80, 300, 120, 11 - -box 140, 20, 180, 180, 10 - -SUB box (x1, y1, x2, y2, c) - -FOR y = y1 TO y2 - FOR x = x1 TO x2 - PSET (x, y), c - NEXT x -NEXT y - -END SUB - +' This program demonstrates how to create a simple drawing application +' using Microsoft QuickBasic. It defines a subroutine called 'box' that +' draws a rectangle on the screen with specified coordinates and color. + +' Declare the 'box' subroutine so it can be used in the main program +DECLARE SUB box (x1 AS SINGLE, y1 AS SINGLE, x2 AS SINGLE, y2 AS SINGLE, c AS INTEGER) + +' Set the screen mode to 13h which is a 320x200 pixel graphics mode with 256 colors +SCREEN 13 + +' Draw three boxes on the screen using the 'box' subroutine +' Each box has different starting and ending coordinates as well as color +box 10, 10, 100, 100, 15 +box 30, 80, 300, 120, 11 +box 140, 20, 180, 180, 10 + +' Define the 'box' subroutine +SUB box (x1 AS SINGLE, y1 AS SINGLE, x2 AS SINGLE, y2 AS SINGLE, c AS INTEGER) + ' Use nested FOR loops to iterate over every pixel within the rectangle + DIM x AS SINGLE, y AS SINGLE + FOR y = y1 TO y2 + FOR x = x1 TO x2 + ' Set the color of the current pixel to the specified color 'c' + PSET (x, y), c + NEXT x + NEXT y +END SUB diff --git a/QBasic tutorial/Group 3/03.bas b/QBasic tutorial/Group 3/03.bas index 8ddb8b2..ee7b9c2 100755 --- a/QBasic tutorial/Group 3/03.bas +++ b/QBasic tutorial/Group 3/03.bas @@ -1,6 +1,15 @@ +' This program demonstrates how to use QuickBasic to draw a simple +' graphic on the screen. It initializes the graphics mode, draws a +' rectangle, and then draws a circle within that rectangle. + +' Set the graphics mode to 320x200 with 256 colors (mode 13) SCREEN 13 +' Draw a line LINE (10, 10)-(200, 100), 14 +' Draw a circle centered at (100, 100) with a radius of 80 pixels +' using color 10 (bright green). The circle is drawn within the +' previously defined rectangle. CIRCLE (100, 100), 80, 10 diff --git a/QBasic tutorial/Group 3/04.bas b/QBasic tutorial/Group 3/04.bas index a806541..8408375 100755 --- a/QBasic tutorial/Group 3/04.bas +++ b/QBasic tutorial/Group 3/04.bas @@ -1,8 +1,25 @@ +' This example program demonstrates how to draw different types of +' lines and boxes on the screen using Microsoft QuickBasic. + +' First, we set the screen mode to 13 which provides a graphics +' resolution of 320x200 with 256 colors available. SCREEN 13 -LINE (10, 10)-(50, 50), 14 ' line +' Now we will draw three different objects using the LINE statement: + +' Draw an filled box from coordinates (10, 10) to (50, 50). +LINE (10, 10)-(50, 50), 14, BF + +' Draw an unfilled box with coordinates (100, 10) to (150, 50). +LINE (100, 10)-(150, 50), 14, B -LINE (100, 10)-(150, 50), 14, B ' box +' Draw a line with coordinates (200, 10) to (250, 50). +LINE (200, 10)-(250, 50), 14 -LINE (200, 10)-(250, 50), 14, BF ' filled box +' To finish the program and allow users to see the drawn objects +' before the screen closes, we wait for a key press from the user. +PRINT "Press any key to exit..." +WHILE NOT INKEY$ <> "" + ' Loop until a key is pressed +WEND diff --git a/QBasic tutorial/Group 3/05.bas b/QBasic tutorial/Group 3/05.bas index 3e87408..296eb8d 100755 --- a/QBasic tutorial/Group 3/05.bas +++ b/QBasic tutorial/Group 3/05.bas @@ -1,6 +1,15 @@ -SCREEN 13 +' QuickBasic example program to demonstrate drawing lines with varying colors -FOR x = 0 TO 255 - LINE (x, 50)-(x, 100), x -NEXT x +SCREEN 13 ' Set the screen mode to 13h which provides 256 color graphics + +' Draw vertical lines across the screen with colors from 0 to 255 +FOR xPosition = 0 TO 255 + ' Draw a line from coordinates (xPosition, 50) to (xPosition, 100) using color xPosition + LINE (xPosition, 50)-(xPosition, 100), xPosition +NEXT xPosition + +' Keep the window open until the user presses a key +PRINT "Press any key to exit..." +WHILE INKEY$ = "" +WEND diff --git a/QBasic tutorial/Group 3/06.bas b/QBasic tutorial/Group 3/06.bas index 5bb13d3..e60ab45 100755 --- a/QBasic tutorial/Group 3/06.bas +++ b/QBasic tutorial/Group 3/06.bas @@ -1,12 +1,27 @@ -SCREEN 13 +' This program demonstrates basic graphics drawing in QuickBasic. +' It uses the SCREEN function to set the graphics mode, draws a circle +' and a line using CIRCLE and LINE commands respectively, waits for user +' input, and then uses the PAINT command to fill an area with a solid color. +' Set the screen to mode 13 which is 320x200 pixels with 256 colors. +SCREEN 13 +' Draw a circle centered at (160, 100) with a radius of 80 pixels +' and use color 15 for the outline of the circle. CIRCLE (160, 100), 80, 15 + +' Draw a line from (100, 10) to (200, 180) using color 15. LINE (100, 10)-(200, 180), 15 -PRINT "press any key..." +' Print a message to the screen prompting the user to press any key. +PRINT "Press any key to fill part of the circle..." +' Wait for the user to press a key and store the input in variable 'a$'. a$ = INPUT$(1) +' Fill the area inside the circle with color 15 starting from point (180, 100). +' Note that PAINT fills an area bounded by the specified color at the start point. PAINT (180, 100), 15 +END ' End the program (although END is not strictly necessary in QuickBasic) + diff --git a/QBasic tutorial/Group 3/07.bas b/QBasic tutorial/Group 3/07.bas index 3c7ba6c..216341e 100755 --- a/QBasic tutorial/Group 3/07.bas +++ b/QBasic tutorial/Group 3/07.bas @@ -1,23 +1,25 @@ -DECLARE SUB sihik (x!, y!) -SCREEN 13 - -' Press F2 to see submodules list -' Vajuta F2 at n„ha sub moodulite listi -' nazmi F2 xtobe uvidjet sub spisok sub modulei - - -sihik 100, 100 -sihik 200, 50 -sihik 180, 150 - -SUB sihik (x, y) - -CIRCLE (x, y), 10, 15 -CIRCLE (x, y), 20, 15 -CIRCLE (x, y), 30, 15 - -LINE (x, y - 50)-(x, y + 50), 15 -LINE (x - 50, y)-(x + 50, y), 15 - -END SUB - +' This program demonstrates how to use subroutines and drawing +' commands in QuickBasic. It draws a simple figure consisting of +' concentric circles and intersecting lines. + +DECLARE SUB DrawFigure (xCenter AS DOUBLE, yCenter AS DOUBLE) +SCREEN 13 ' Set the screen mode for high-resolution graphics + +' To see a list of subroutines, press F2 +' This is useful when navigating through larger programs + +' Draw figures at different locations on the screen +DrawFigure 100, 100 +DrawFigure 200, 50 +DrawFigure 180, 150 + +SUB DrawFigure (xCenter AS DOUBLE, yCenter AS DOUBLE) + ' Draw three concentric circles with a specified center point + CIRCLE (xCenter, yCenter), 10, 15 + CIRCLE (xCenter, yCenter), 20, 15 + CIRCLE (xCenter, yCenter), 30, 15 + + ' Draw two lines intersecting at the center point + LINE (xCenter, yCenter - 50)-(xCenter, yCenter + 50), 15 + LINE (xCenter - 50, yCenter)-(xCenter + 50, yCenter), 15 +END SUB diff --git a/QBasic tutorial/Group 3/08.bas b/QBasic tutorial/Group 3/08.bas index deff209..56ba16e 100755 --- a/QBasic tutorial/Group 3/08.bas +++ b/QBasic tutorial/Group 3/08.bas @@ -1,13 +1,33 @@ -SCREEN 13 - - -FOR x = 0 TO 319 - - y = SIN(x / 10) * 50 + 100 - PSET (x, y), 14 - - y = COS(x / 10) * 50 + 100 - PSET (x, y), 12 - -NEXT x - +' This program demonstrates how to draw sine and cosine waves on the screen +' using Microsoft QuickBasic. It is intended for beginners learning +' programming in QuickBasic. + +' First, we set the graphics mode to 13 which provides a 320x200 pixel +' resolution with 256 colors. +SCREEN 13 + +' We will draw two waves: one for sine and another for cosine. The amplitude +' of both waves is scaled by a factor of 50, and they are vertically +' centered on the screen by adding 100 to the y-coordinate. + +' The FOR loop iterates over the x-axis from 0 to 319 pixels, which covers +' the entire width of the screen in this graphics mode. +FOR x = 0 TO 319 + ' Calculate the y-coordinate for the sine wave. We divide x by 10 to + ' reduce the frequency of the wave so it fits nicely on the screen. + ' The SIN function returns a value between -1 and 1, which we scale + ' and shift to get the desired waveform. + ysine = SIN(x / 10) * 50 + 100 + + ' Use PSET (Pixel SET) to plot a point on the screen for the sine wave + PSET (x, ysine), 14 + + ' Similarly, calculate and plot the cosine wave with color 12 + ycosine = COS(x / 10) * 50 + 100 + PSET (x, ycosine), 12 + + ' The loop continues to the next x-coordinate until it reaches 319. +NEXT x + +' After the loop completes, both sine and cosine waves will be drawn on +' the screen, with each point of the wave plotted in its respective color. diff --git a/QBasic tutorial/Group 3/09.bas b/QBasic tutorial/Group 3/09.bas index eaea7f8..31d9cb1 100755 --- a/QBasic tutorial/Group 3/09.bas +++ b/QBasic tutorial/Group 3/09.bas @@ -1,13 +1,40 @@ -SCREEN 13 +' This program demonstrates how to draw a simple circle using QuickBasic. +' It utilizes trigonometric functions SIN and COS to calculate the position of points on a circle. -pi = 3.14 -mi = 7 ' amount of points on circular shape +SCREEN 13 ' Set the screen mode to 13, which is 320x200 with 256 colors -FOR a = 0 TO pi * 2 STEP pi * 2 / mi +' Define pi (π) as a constant for calculations +CONST pi = 3.141592653589789# - x = SIN(a) * 50 + 100 - y = COS(a) * 50 + 100 - PSET (x, y), 10 +' Define the number of points to be drawn on the circular shape +DIM mi AS INTEGER +mi = 12 + +' Calculate the angle increment for each iteration of the loop +' This will determine how many points we draw on the circle +DIM angleStep AS SINGLE +angleStep = pi * 2 / mi + +' Loop through angles from 0 to 2π (360 degrees) with the calculated step +FOR a = 0 TO pi * 2 STEP angleStep + + ' Calculate the x-coordinate of the current point on the circle + ' We multiply by 50 to scale the radius and add 100 for centering + DIM x AS SINGLE + x = SIN(a) * 50 + 100 + + ' Calculate the y-coordinate of the current point on the circle + ' Similarly, we scale and center the point + DIM y AS SINGLE + y = COS(a) * 50 + 100 + + ' Set the pixel at coordinates (x, y) with color 10 + PSET (x, y), 10 NEXT a +' Wait for a key press before ending the program +PRINT "Press any key to exit..." +WHILE INKEY$ = "" +WEND + diff --git a/QBasic tutorial/Group 3/10.bas b/QBasic tutorial/Group 3/10.bas index fc4f497..ad15b02 100755 --- a/QBasic tutorial/Group 3/10.bas +++ b/QBasic tutorial/Group 3/10.bas @@ -1,21 +1,53 @@ +' This program demonstrates basic QuickBasic graphics and sound capabilities. +' It is designed for novice programmers to learn about drawing lines, plotting points, +' handling user input, and generating simple sounds. + +' Set the graphics mode to 320x200 with 16 colors (mode 13). SCREEN 13 +' Draw a grid on the screen with horizontal and vertical lines every 10 pixels. +' This loop demonstrates the use of the LINE function to draw lines. FOR i = 0 TO 320 STEP 10 + ' Draw a horizontal line from the left edge to the right edge at y-coordinate i. LINE (0, i)-(319, i), 5 + ' Draw a vertical line from the top edge to the bottom edge at x-coordinate i. LINE (i, 0)-(i, 199), 5 NEXT i +' Draw a horizontal line across the middle of the screen (y=100) LINE (0, 100)-(319, 100), 10 -PRINT "press a key..." +' Prompt the user to press any key before continuing. +PRINT "Press any key to continue..." +' Wait for the user to press a key and store the input in variable a$. a$ = INPUT$(1) +' Initialize variables for the bouncing ball animation and sound. +DIM y AS SINGLE ' The vertical position of the ball, using single precision for smooth motion. +DIM ys AS SINGLE ' The vertical speed of the ball. +DIM t AS INTEGER ' A counter for the main animation loop. + +' Set the initial vertical position of the ball to the middle of the screen (y=100). y = 100 +' Set the initial vertical speed of the ball to a negative value for upward motion. ys = -1 + +' The main animation loop runs from t=0 to t=300, simulating the passage of time. FOR t = 0 TO 300 + ' Plot the current position of the ball with a specific color (14). PSET (t, y), 14 + + ' Update the vertical speed of the ball by adding gravity-like acceleration (ys = ys + .01). ys = ys + .01 + ' Update the vertical position of the ball based on the current speed (y = y + ys). y = y + ys + + ' Generate a sound with a frequency that varies inversely with the ball's vertical position. + ' As the ball falls, the pitch of the sound increases. SOUND 300 - y, .1 NEXT t +' The program ends here; to exit, press any key. +PRINT "Press any key to exit..." +a$ = INPUT$(1) + diff --git a/QBasic tutorial/Group 3/11.bas b/QBasic tutorial/Group 3/11.bas index c4e4c5a..6d1cfe9 100755 --- a/QBasic tutorial/Group 3/11.bas +++ b/QBasic tutorial/Group 3/11.bas @@ -1,10 +1,26 @@ -CLS - -a = -12.7 - -PRINT "normal: ", a -PRINT "rounded: ", INT(a) -PRINT "absolute: ", ABS(a) - -PRINT "reminder of 10 / 4 is: ", 10 MOD 4 - +' This program demonstrates basic mathematical operations in QuickBasic. +' It includes examples of rounding, taking the absolute value, +' and finding the remainder of a division operation. + +DIM a AS SINGLE ' Declare variable 'a' as type SINGLE for floating-point arithmetic + +' Assign a negative floating-point number to variable 'a' +a = -12.7 + +' Print the original value of 'a' +PRINT "Normal: "; a + +' Use the INT function to round down 'a' to the nearest whole number +' and print the result +PRINT "Rounded down (INT): "; INT(a) + +' Use the ABS function to get the absolute value of 'a', +' which is always non-negative, and print the result +PRINT "Absolute value: "; ABS(a) + +' Calculate the remainder of 10 divided by 4 using the MOD operator +' and store the result in an implicitly declared variable +' Then print the result +DIM reminder AS INTEGER +reminder = 10 MOD 4 +PRINT "Remainder of 10 / 4 is: "; reminder