Getting Started
Introduction
Sample Programs
QBasic IDEs
History
Advice
Tools
Mini-Tutorial
Tutorial
Code Snippets

Resources
Web Sites
More Tutorials
Vendors
Books
Magazines
NewsLetters
NewsGroups
Forums
User Groups
Talk Shows
Blogs

GBIC >> QBasic >> Tutorial >> Screen - Drawing Commands

QBasic Information Center Tutorials - Drawing Commands
These tutorials were written to help you get a quick, but thorough, understanding of QBasic - the scope of the language as well as it's specific capabilities.

Screen - Drawing Commands
In an earlier tutorial section graphics concepts and the capabilities QBasic supports were covered. In this section we'll cover the actual commands which control screen content.

Here is a list of the QBasic graphics drawing functions.

    • Screen/Color Control
     cls, color 
    • Points
     pset, preset, point 
    • Pre-Set Shapes
     circle, line 
    • Random Shapes
     draw, paint 

Screen Modes
Screen modes were discussed in an earlier section. All of the examples on this page assume that the mode has been set to screen mode 12, although all of the commands will work in any graphics mode. Here's the command to set the screen mode.

    screen 12        ' set screen to 640x480, 16 colors
    cls              ' clears the screen

CLS and COLOR Functions
... in work

Points
... in work

Shapes - Lines, Boxes, Circles, Ellipses
... in work

DRAWing Custom Shapes
... in work

Filling Screen Areas - Paint
... in work

Drawing Commands Reference
The following functions are available to display graphics.

  • circle - draws a circle, arc or ellipse
       
        circle (0,0),50,12    # center at 0,0, radius=50, color=12
        

  • cls - clears the screen of all graphics and text
       
        cls           # clear entire screen
        cls 0         # clear entire screen
        cls 1         # clears viewport (screen if no viewport set)
        cls 2         # clears text viewport
        

  • color - sets the screen display colors (foreground, background, border)
       
        color fg%, bg%, border%        # syntax
    
        Color values:
        0   Black       8   Gray
        1   Blue        9   Light Blue
        2   Green       10  Light Green
        3   Cyan        11  Light Cyan
        4   Red         12  Light Red
        5   Magenta     13  Light Magenta
        6   Brown       14  Yellow
        7   White       15  High-intensity white
        

  • draw - draws point to oint composite lines
       
        draw "F60 L120 E60"
        

  • line - draws a line or a (filled) box
       
        line (1,1)-(10,10),15,BF
        

  • paint - fills closed areas on the screen with a color
       
        paint (5,5),15
        

  • point - returns cursor coordinates or color of a specified pixel
       
        point (n%)                   # returns coordinates of cursor
                                       n%=0 - viewport x coordinates
                                       n%=1 - viewport y coordinates
                                       n%=2 - window x coordinates
                                       n%=3 - window x coordinates
          
        result% = point ((x%,y%)     # returns color of pixel at xy
        

  • preset - set the color of a pixel
       
        preset(5,20),15     # reverses the current fg/bg
        

  • pset - set the color of a pixel
       
        pset (5,20),15      # uses current fg/bg
        

If you have any suggestions or correction, please let me know.