🎨 QBasic Graphic Statements Explained
QBasic's graphic statements allow you to create shapes, colors, and sound in your programs, making learning coding more fun and creative!
🖥️ GRAPHIC MODE - SCREEN & RESOLUTION
- SCREEN statement: Sets the display mode (resolution and color levels) required for drawing graphics.
SCREEN mode_number -
Common Modes:
Mode Resolution Colors 0 Text only - 1 320x200 4 colors 2 640x200 2 colors 12 640x480 16 colors
Example:
SCREEN 1
🌈 COLOR STATEMENT
- COLOR sets the foreground and background colors for text or graphics.
COLOR foreground, background-
Some color codes:
Color Code Black 0 Blue 1 Green 2 Red 4 White 7 Yellow 14
Example:
(Red text on white background)
COLOR 4, 7 (Red text on white background)
⬛ PIXEL, PSET and PRESET
- To color or read an individual pixel:
- PSET (x, y), color plots a single pixel.
- PRESET (x, y), color erases or puts background color at position.
Example:
PSET (100, 150), 14 ('Draws yellow pixel at 100,150)
📏 LINE Statement
- LINE (x1, y1)-(x2, y2), color draws a line from (x1, y1) to (x2, y2).
- B option: draws a rectangle.
BF option: draws a filled box.
Draw a line:
LINE (50,60)-(180,160), 2
Draw a square box (side=50):
LINE (60,60)-(110,110), 3, B
⚪ CIRCLE Statement
- CIRCLE (x, y), radius, color draws a circle with given center and radius.
Example:
CIRCLE (120,100), 40, 4 ('Red Circle)
🪄 PAINT Statement
- Fills an area with color starting from (x, y).
PAINT (x, y), color, bordercolor
Example:
Paints area from (120,100) with color 6 inside a red border (color 4).
PAINT (120,100), 6, 4Paints area from (120,100) with color 6 inside a red border (color 4).
✏️ DRAW Statement (Turtle Graphics)
- Draws graphics using codes D, U, R, L, E, F, G, H (directions).
- D: Down, U: Up, R: Right, L: Left, E: Up-Right, F: Down-Right, G: Down-Left, H: Up-Left
- Syntax:
DRAW "code"(e.g.,DRAW "R50"moves right 50 units)
| Code | Direction |
|---|---|
| D | Down |
| U | Up |
| R | Right |
| L | Left |
| E | Up-Right |
| F | Down-Right |
| G | Down-Left |
| H | Up-Left |
Example:
DRAW "R80D80L80U80" (Draws a square)
🔊 SOUND & BEEP Statements
- BEEP: Simple short sound.
BEEP - SOUND: Plays tone at selected frequency for specified time.
SOUND frequency, duration
(frequency in Hz, duration in 1/18 sec)
Example:
BEEP (Beep Sound)SOUND 800, 10 (Tone at 800Hz for short time)
🚦 Unconditional and Exit Statements
- END: Stops the program instantly.
END - EXIT: Used to exit loop early.
EXIT FOR
EXIT DO
Example:
FOR I = 1 TO 10
IF I = 5 THEN EXIT FOR
PRINT I
NEXT I
(Prints 1 to 4, then exits loop)
🔀 GOSUB ... RETURN Statement
- Jumps to a subroutine, then goes back to next statement after GOSUB.
GOSUB label...RETURN
Example:
PRINT "Start"
GOSUB PrintMessage
PRINT "End"
END
PrintMessage:
PRINT "This is a subroutine"
RETURN
Answer the Question
Correct! Well done – You selected the right answer.
😊
🔔 Subscribe to My Channel


0 Comments