AI improved tutorials by adding comments and fixing code style
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Mon, 22 Jul 2024 10:18:56 +0000 (13:18 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Mon, 22 Jul 2024 10:18:56 +0000 (13:18 +0300)
12 files changed:
QBasic tutorial/Group 3/00.bas
QBasic tutorial/Group 3/01.bas
QBasic tutorial/Group 3/02.bas
QBasic tutorial/Group 3/03.bas
QBasic tutorial/Group 3/04.bas
QBasic tutorial/Group 3/05.bas
QBasic tutorial/Group 3/06.bas
QBasic tutorial/Group 3/07.bas
QBasic tutorial/Group 3/08.bas
QBasic tutorial/Group 3/09.bas
QBasic tutorial/Group 3/10.bas
QBasic tutorial/Group 3/11.bas

index 91414f8..c01682c 100755 (executable)
@@ -1,7 +1,21 @@
-SCREEN 13    ' set video mode 320 x 200   256 colors\r
-\r
-PRINT "Hello..."\r
-\r
-PSET (160, 100), 10    ' draws a point\r
-                       ' x=160  y=100 color=10\r
-\r
+' 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
index 938bc41..2575df0 100755 (executable)
@@ -1,9 +1,18 @@
-SCREEN 13\r
-\r
-FOR y = 50 TO 150\r
-  FOR x = 100 TO 200\r
-    PSET (x, y), 10\r
-  NEXT x\r
-  SOUND y, 1\r
-NEXT y\r
-\r
+' 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
index 11df674..adf3b10 100755 (executable)
@@ -1,25 +1,27 @@
-DECLARE SUB box (x1!, y1!, x2!, y2!, c!)\r
-\r
-' Press F2 to see submodules\r
-' Nazmi F2 xtob uvidet SUB moduli\r
-' Vajuta F2 et n\84ha SUB mooduleid\r
-\r
-\r
-SCREEN 13\r
-\r
-box 10, 10, 100, 100, 15\r
-\r
-box 30, 80, 300, 120, 11\r
-\r
-box 140, 20, 180, 180, 10\r
-\r
-SUB box (x1, y1, x2, y2, c)\r
-\r
-FOR y = y1 TO y2\r
-  FOR x = x1 TO x2\r
-    PSET (x, y), c\r
-  NEXT x\r
-NEXT y\r
-\r
-END SUB\r
-\r
+' 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
index 8ddb8b2..ee7b9c2 100755 (executable)
@@ -1,6 +1,15 @@
+' This program demonstrates how to use QuickBasic to draw a simple\r
+' graphic on the screen. It initializes the graphics mode, draws a\r
+' rectangle, and then draws a circle within that rectangle.\r
+\r
+' Set the graphics mode to 320x200 with 256 colors (mode 13)\r
 SCREEN 13\r
 \r
+' Draw a line\r
 LINE (10, 10)-(200, 100), 14\r
 \r
+' Draw a circle centered at (100, 100) with a radius of 80 pixels\r
+' using color 10 (bright green). The circle is drawn within the\r
+' previously defined rectangle.\r
 CIRCLE (100, 100), 80, 10\r
 \r
index a806541..8408375 100755 (executable)
@@ -1,8 +1,25 @@
+' This example program demonstrates how to draw different types of\r
+' lines and boxes on the screen using Microsoft QuickBasic.\r
+\r
+' First, we set the screen mode to 13 which provides a graphics\r
+' resolution of 320x200 with 256 colors available.\r
 SCREEN 13\r
 \r
-LINE (10, 10)-(50, 50), 14              ' line\r
+' Now we will draw three different objects using the LINE statement:\r
+\r
+' Draw an filled box from coordinates (10, 10) to (50, 50).\r
+LINE (10, 10)-(50, 50), 14, BF\r
+\r
+' Draw an unfilled box with coordinates (100, 10) to (150, 50).\r
+LINE (100, 10)-(150, 50), 14, B\r
 \r
-LINE (100, 10)-(150, 50), 14, B         ' box\r
+' Draw a line with coordinates (200, 10) to (250, 50).\r
+LINE (200, 10)-(250, 50), 14\r
 \r
-LINE (200, 10)-(250, 50), 14, BF        ' filled box\r
+' To finish the program and allow users to see the drawn objects\r
+' before the screen closes, we wait for a key press from the user.\r
+PRINT "Press any key to exit..."\r
+WHILE NOT INKEY$ <> ""\r
+    ' Loop until a key is pressed\r
+WEND\r
 \r
index 3e87408..296eb8d 100755 (executable)
@@ -1,6 +1,15 @@
-SCREEN 13\r
+' QuickBasic example program to demonstrate drawing lines with varying colors\r
 \r
-FOR x = 0 TO 255\r
-  LINE (x, 50)-(x, 100), x\r
-NEXT x\r
+SCREEN 13 ' Set the screen mode to 13h which provides 256 color graphics\r
+\r
+' Draw vertical lines across the screen with colors from 0 to 255\r
+FOR xPosition = 0 TO 255\r
+    ' Draw a line from coordinates (xPosition, 50) to (xPosition, 100) using color xPosition\r
+    LINE (xPosition, 50)-(xPosition, 100), xPosition\r
+NEXT xPosition\r
+\r
+' Keep the window open until the user presses a key\r
+PRINT "Press any key to exit..."\r
+WHILE INKEY$ = ""\r
+WEND\r
 \r
index 5bb13d3..e60ab45 100755 (executable)
@@ -1,12 +1,27 @@
-SCREEN 13\r
+' This program demonstrates basic graphics drawing in QuickBasic.\r
+' It uses the SCREEN function to set the graphics mode, draws a circle\r
+' and a line using CIRCLE and LINE commands respectively, waits for user\r
+' input, and then uses the PAINT command to fill an area with a solid color.\r
 \r
+' Set the screen to mode 13 which is 320x200 pixels with 256 colors.\r
+SCREEN 13\r
 \r
+' Draw a circle centered at (160, 100) with a radius of 80 pixels\r
+' and use color 15 for the outline of the circle.\r
 CIRCLE (160, 100), 80, 15\r
+\r
+' Draw a line from (100, 10) to (200, 180) using color 15.\r
 LINE (100, 10)-(200, 180), 15\r
 \r
-PRINT "press any key..."\r
+' Print a message to the screen prompting the user to press any key.\r
+PRINT "Press any key to fill part of the circle..."\r
 \r
+' Wait for the user to press a key and store the input in variable 'a$'.\r
 a$ = INPUT$(1)\r
 \r
+' Fill the area inside the circle with color 15 starting from point (180, 100).\r
+' Note that PAINT fills an area bounded by the specified color at the start point.\r
 PAINT (180, 100), 15\r
 \r
+END ' End the program (although END is not strictly necessary in QuickBasic)\r
+\r
index 3c7ba6c..216341e 100755 (executable)
@@ -1,23 +1,25 @@
-DECLARE SUB sihik (x!, y!)\r
-SCREEN 13\r
-\r
-' Press F2 to see submodules list\r
-' Vajuta F2 at n\84ha sub moodulite listi\r
-' nazmi F2 xtobe uvidjet sub spisok sub modulei\r
-\r
-\r
-sihik 100, 100\r
-sihik 200, 50\r
-sihik 180, 150\r
-\r
-SUB sihik (x, y)\r
-\r
-CIRCLE (x, y), 10, 15\r
-CIRCLE (x, y), 20, 15\r
-CIRCLE (x, y), 30, 15\r
-\r
-LINE (x, y - 50)-(x, y + 50), 15\r
-LINE (x - 50, y)-(x + 50, y), 15\r
-\r
-END SUB\r
-\r
+' 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
index deff209..56ba16e 100755 (executable)
@@ -1,13 +1,33 @@
-SCREEN 13\r
-\r
-\r
-FOR x = 0 TO 319\r
-\r
-  y = SIN(x / 10) * 50 + 100\r
-  PSET (x, y), 14\r
-\r
-  y = COS(x / 10) * 50 + 100\r
-  PSET (x, y), 12\r
-\r
-NEXT x\r
-\r
+' 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.
index eaea7f8..31d9cb1 100755 (executable)
@@ -1,13 +1,40 @@
-SCREEN 13\r
+' This program demonstrates how to draw a simple circle using QuickBasic.\r
+' It utilizes trigonometric functions SIN and COS to calculate the position of points on a circle.\r
 \r
-pi = 3.14\r
-mi = 7       ' amount of points on circular shape\r
+SCREEN 13 ' Set the screen mode to 13, which is 320x200 with 256 colors\r
 \r
-FOR a = 0 TO pi * 2 STEP pi * 2 / mi\r
+' Define pi (π) as a constant for calculations\r
+CONST pi = 3.141592653589789#\r
 \r
-  x = SIN(a) * 50 + 100\r
-  y = COS(a) * 50 + 100\r
-  PSET (x, y), 10\r
+' Define the number of points to be drawn on the circular shape\r
+DIM mi AS INTEGER\r
+mi = 12\r
+\r
+' Calculate the angle increment for each iteration of the loop\r
+' This will determine how many points we draw on the circle\r
+DIM angleStep AS SINGLE\r
+angleStep = pi * 2 / mi\r
+\r
+' Loop through angles from 0 to 2π (360 degrees) with the calculated step\r
+FOR a = 0 TO pi * 2 STEP angleStep\r
+\r
+    ' Calculate the x-coordinate of the current point on the circle\r
+    ' We multiply by 50 to scale the radius and add 100 for centering\r
+    DIM x AS SINGLE\r
+    x = SIN(a) * 50 + 100\r
+\r
+    ' Calculate the y-coordinate of the current point on the circle\r
+    ' Similarly, we scale and center the point\r
+    DIM y AS SINGLE\r
+    y = COS(a) * 50 + 100\r
+\r
+    ' Set the pixel at coordinates (x, y) with color 10\r
+    PSET (x, y), 10\r
 \r
 NEXT a\r
 \r
+' Wait for a key press before ending the program\r
+PRINT "Press any key to exit..."\r
+WHILE INKEY$ = ""\r
+WEND\r
+\r
index fc4f497..ad15b02 100755 (executable)
@@ -1,21 +1,53 @@
+' This program demonstrates basic QuickBasic graphics and sound capabilities.\r
+' It is designed for novice programmers to learn about drawing lines, plotting points,\r
+' handling user input, and generating simple sounds.\r
+\r
+' Set the graphics mode to 320x200 with 16 colors (mode 13).\r
 SCREEN 13\r
 \r
+' Draw a grid on the screen with horizontal and vertical lines every 10 pixels.\r
+' This loop demonstrates the use of the LINE function to draw lines.\r
 FOR i = 0 TO 320 STEP 10\r
+  ' Draw a horizontal line from the left edge to the right edge at y-coordinate i.\r
   LINE (0, i)-(319, i), 5\r
+  ' Draw a vertical line from the top edge to the bottom edge at x-coordinate i.\r
   LINE (i, 0)-(i, 199), 5\r
 NEXT i\r
 \r
+' Draw a horizontal line across the middle of the screen (y=100)\r
 LINE (0, 100)-(319, 100), 10\r
 \r
-PRINT "press a key..."\r
+' Prompt the user to press any key before continuing.\r
+PRINT "Press any key to continue..."\r
+' Wait for the user to press a key and store the input in variable a$.\r
 a$ = INPUT$(1)\r
 \r
+' Initialize variables for the bouncing ball animation and sound.\r
+DIM y AS SINGLE ' The vertical position of the ball, using single precision for smooth motion.\r
+DIM ys AS SINGLE ' The vertical speed of the ball.\r
+DIM t AS INTEGER ' A counter for the main animation loop.\r
+\r
+' Set the initial vertical position of the ball to the middle of the screen (y=100).\r
 y = 100\r
+' Set the initial vertical speed of the ball to a negative value for upward motion.\r
 ys = -1\r
+\r
+' The main animation loop runs from t=0 to t=300, simulating the passage of time.\r
 FOR t = 0 TO 300\r
+  ' Plot the current position of the ball with a specific color (14).\r
   PSET (t, y), 14\r
+\r
+  ' Update the vertical speed of the ball by adding gravity-like acceleration (ys = ys + .01).\r
   ys = ys + .01\r
+  ' Update the vertical position of the ball based on the current speed (y = y + ys).\r
   y = y + ys\r
+\r
+  ' Generate a sound with a frequency that varies inversely with the ball's vertical position.\r
+  ' As the ball falls, the pitch of the sound increases.\r
   SOUND 300 - y, .1\r
 NEXT t\r
 \r
+' The program ends here; to exit, press any key.\r
+PRINT "Press any key to exit..."\r
+a$ = INPUT$(1)\r
+\r
index c4e4c5a..6d1cfe9 100755 (executable)
@@ -1,10 +1,26 @@
-CLS\r
-\r
-a = -12.7\r
-\r
-PRINT "normal: ", a\r
-PRINT "rounded: ", INT(a)\r
-PRINT "absolute: ", ABS(a)\r
-\r
-PRINT "reminder of 10 / 4 is: ", 10 MOD 4\r
-\r
+' 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