Article ID: 58105
Article Last Modified on 8/16/2005
APPLIES TO
- Microsoft Visual Basic for MS-DOS
- Microsoft QuickBasic 4.0
- Microsoft QuickBASIC 4.0b
- Microsoft QuickBasic 4.5 for MS-DOS
- Microsoft BASIC Compiler 6.0
- Microsoft BASIC Compiler 6.0b
- Microsoft BASIC Professional Development System 7.0
This article was previously published under Q58105
SUMMARY
The Visual Basic for MS-DOS PAINT statement can be used to paint a region of the screen in a particular color or pattern. PAINTing with a pattern is called "tiling."
The syntax for the PAINT statement is as follows:
PAINT [STEP] (x,y) [,[paint] [,[bordercolor] [,[background]]]
The variable labeled "paint" is used to control the color of the painted region. If it is a numeric value, then the number must be a valid color attribute. The corresponding color is used to paint the area. If the "paint" variable is left blank, then the foreground color attribute is used.
However, if you use a string in this part of the PAINT statement, then this string is used to do "tiling". This article describes how to do tiling in different screen modes.
For an in-depth explanation of tiling, please see the following manuals:
- "Microsoft Visual Basic for MS-DOS Programmer's Guide".
- "Microsoft QuickBasic 4.5: Programming in Basic," Pages 181-191
- "Microsoft QuickBasic 4.0: Programming in Basic: Selected Topics," Pages 226-239
- "Microsoft Basic 7.0: Programmer's Guide," Pages 179-189
- "Microsoft Basic Compiler 6.0: Programming in Basic: Selected Topics," Pages 226-239
- "Microsoft QuickBasic Compiler" manual for Versions 2.00, 2.01, and 3.00, Pages 380-382
MORE INFORMATION
Each tile for a pattern is composed of a rectangular grid of pixels. This tile grid can have up to 64 rows in all screen modes. However, the number of pixels in each row depends on the screen mode. This is because, depending on the number of color attributes per screen, each pixel can be represented by a varying number of bits.
The formula for the number of bits per pixel is as follows:
Bits-per-pixel = Log (base 2) of the number-of-attributes
The number-of-attributes is the number of color attributes in that screen mode.
The following table gives the bits-per-pixel and length-of-tile-row for each screen mode:
Screen Mode Bits-per-Pixel Length-of-Tile-Row ----------- -------------- ------------------ 1 1 8 pixels 2 2 4 pixels 3 1 8 pixels 4 1 8 pixels 7 4 2 pixels 8 4 2 pixels 9 2 4 pixels 10 2 4 pixels 11 1 8 pixels 12 4 2 pixels 13 8 1 pixel
The easiest way to define a tile row is with the CHR$() function. This function defines one byte (8 bits) in the tiling string. It is also easiest to use two hexadecimal digits per byte since they are easily converted to 4 bits per digit. For example, the following line:
TILE$ = CHR$(&HF0)
sets up a tiling string with the value 11110000. It is used in a PAINT statement, such as the following:
PAINT (100,100), TILE$
SCREENS 2, 3, 4, and 11
In screen modes with only two attributes (modes 2, 3, 4, and 11), the tiling string is very simple since each bit equals one pixel. A one (1) means that the pixel is on and a zero (0) means that the pixel is off.
SCREENS 1, 9, and 10
In screen modes with four attributes (modes 1, 9, and 10), the tiling is only a little more complicated since a pixel is represented by two bits. For example, if the two bits were 01, then the pixel would be drawn in color 1. If they were 11, then the pixel would be color 3. One byte would equal 4 pixels. The byte 00011011 would draw 4 pixels in color 0, 1, 2, and 3 consecutively. The tiling string for 00011011 would be the following:
TILE$ = CHR$(&H1B) ' 0001 = &H1, 1101 = &HB
SCREENS 7, 8, and 12
Tiling in EGA and VGA screen modes with more than 4 colors is a lot more complicated. In these modes, it takes more than one row (byte) to define a tiling row. This is because each pixel is represented three-dimensionally in a stack of "bit planes", rather than sequentially in a single plane.
Listed below is an example of how to define a multicolored pattern consisting of rows of alternating yellow and magenta in a screen mode with 16 color attributes (modes 7, 8, and 12). The following table shows how the colors are defined for each pixel and how to arrange them into CHR$() statements:
Column 1 2 3 4 5 6 7 8 ------------------- Row 1 1 1 0 0 0 0 1 1 = CHR$(&HC3) Row 2 0 0 1 1 1 1 0 0 = CHR$(&H3C) Row 3 1 1 1 1 1 1 1 1 = CHR$(&HFF) Row 4 0 0 1 1 1 1 0 0 = CHR$(&H3C) TILE$ = CHR$(&HC3)+CHR$(&H3C)+CHR$(&HFF)+CHR$(&H3C)
The preceding line defines 8 pixels of the colors magenta, magenta, yellow, yellow, yellow, yellow, magenta, and magenta. This combination results in alternating stripes of magenta and yellow. You can get the color by reading each column from BOTTOM to TOP. For example, the first pixel is defined in column 1 by the color number 0101. This is color 5, which defaults to magenta. The sixth pixel is defined by the number 1110, or color 14, which is yellow in the default palette.
To paint a circle with this pattern, you would do the following:
Example
To try this example in VBDOS.EXE:
- From the File menu, choose New Project.
- Copy the code example to the Code window.
- Press F5 to run the program.
SCREEN 12 TILE$ = CHR$(&HC3)+CHR$(&H3C)+CHR$(&HFF)+CHR$(&H3C) CIRCLE (100,100),50 ' A circle of radius 50. PAINT (100,100),TILE$ END
SCREEN 13
Screen mode 13, which has 256 attributes, works differently than the other EGA and VGA modes. You have a lot less flexibility with screen 13 than you do with even the two-color screens. The most that you can do with screen 13 tiling is to create horizontal lines of different colors. This is very simple since one byte is equal to one pixel color. Therefore, one CHR$() statement defines one line or row.
To paint a circle with alternating lines of color 5 (magenta) and color 14 (yellow), you would do the following:
Example
To try this example in VBDOS.EXE:
- From the File menu, choose New Project.
- Copy the code example to the Code window.
- Press F5 to run the program.
SCREEN 13 TILE$ = CHR$(&H5) + CHR$(&HE) ' Colors 5 and 14. CIRCLE (100,100),50 PAINT (100,100),TILE$ END
Additional query words: VBmsdos QuickBas BasicCom 1.00 1.01 1.02 2.00 2.01 3.00 4.00 4.00b 4.50 6.00 6.00b 7.00
Keywords: KB58105