Q(uick)BASIC Statement: PAINT
Quick View
PAINT
A graphics statement that fills an area with the color or pattern specified
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- PAINT [STEP] (x!,y!)[,[{color% | tile$}] [,[bordercolor%] [,background$]]]
Description/Parameter(s)
STEP | Specifies that coordinates are relative to the current graphics cursor position. |
(x!,y!) | The screen coordinates where painting begins. |
color% | A color attribute that sets the fill color. |
tile$ | A fill pattern that is 8 bits wide and up to 64 bytes long, defined as follows: |
tile$ = CHR$(arg1) + CHR$(arg2) + … + CHR$(argn%) |
|
The arguments to CHR$ are numbers between 0 and 255. Each CHR$(argn%) defines a 1-byte, 8-pixel slice of the pattern based on the binary form of the number. | |
bordercolor% | A color attribute that specifies the color of the filled area's border. PAINT stops filling an area when it encounters a border of the specified color. |
background$ | A 1-byte, 8-pixel background tile slice. Specifying a background tile slice allows you to paint over an area that has already been painted. |
The available color attributes depend on your graphics adapter and the screen mode set by the most recent SCREEN statement. |
Example
'This example requires a color graphics adapter.
SCREEN 1
CIRCLE (106, 100), 75, 1
LINE (138, 35)-(288, 165), 1, B
PAINT (160, 100), 2, 1
Syntax
- PAINT [STEP] (x,y)[,[paint] [,[bordercolor] [,background]]]
Description/Parameter(s)
Argument | Description |
STEP | Defines coordinates to be relative to the most recently plotted point. For example, if the last point plotted were (10,10), then the coordinates referred to by STEP (4,5) would be (4+10,5+10) or (14,15). |
(x,y) | The coordinates where painting begins. The point must be inside or outside a figure, not on the border itself. If this point is inside, the figure's interior is painted; if the point is on the outside, the background is painted. |
paint | A numeric or string expression. If paint is a numeric expression, then the number must be a valid color attribute. The corresponding color is used to paint the area. If you do not specify paint, the foreground color attribute is used. For information about valid colors, numbers, and attributes see the following: |
If the paint argument is a string expression, then PAINT does "tiling," a process that paints a pattern rather than a solid color. Tiling is similar to "line styling," which creates dashed lines rather than solid lines. | |
bordercolor | A numeric expression identifying the color attribute to use to paint the border of the figure. When the border color is encountered, painting of the current line stops. If the bordercolor is not specified, the paint argument is used. |
background | A string value giving the "background tile slice" to skip when checking for termination of the boundary. Painting is terminated when adjacent points display the paint color. Specifying a background tile slice allows you to paint over an already painted area. When you omit background the default is CHR$ (0). |
Painting is complete when a line is painted without changing the color of any pixel, in other words, when the entire line is equal to the paint color. The PAINT command permits coordinates outside the screen or viewport.
"Tiling" is the design of a PAINT pattern that is eight bits wide and up to 64 bytes long. In the tile string, each byte masks eight bits along the x axis when putting down points. The syntax for constructing this tile mask is
- PAINT (x,y), CHR$(arg1)+CHR$(arg2)+...+CHR$(argn)
The arguments to CHR$ are numbers between 0 and 255, represented in binary form across the x axis of the tile. There can be up to 64 of these CHR$ elements; each generates an image not of the assigned character, but of the bit arrangement of the code for that character. For example, the decimal number 85 is binary 01010101; the graphic image line on a black-and-white screen generated by CHR$(85) is an eight-pixel line, with even-numbered points white and odd-numbered points black. That is, each bit equal to 1 turns the associated pixel on and each bit equal to 0 turns the associated bit off in a black- and-white system. The ASCII character CHR$(85), which is U, is not displayed in this case.
When supplied, background defines the "background tile slice" to skip when checking for boundary termination. You cannot specify more than two consecutive bytes that match the tile string in the tile background slice. Specifying more than two consecutive bytes produces an error message that reads "Illegal function call."
Tiling can also be done to produce various patterns of different colors.
Example
This example uses PAINT to create a magenta fish with a cyan tail.
CONST PI = 3.1415926536
CLS ' Clear screen
SCREEN 1
CIRCLE (190, 100), 100, 1, , , .3 'Outline fish body in cyan.
CIRCLE (265, 92), 5, 1, , , .7 'Outline fish eye in cyan.
PAINT (190, 100), 2, 1 'Fill in fish body with magenta.
LINE (40, 120)-STEP (0, -40), 2 'Outline
LINE -STEP (60, 20), 2 ' tail in
LINE -STEP (-60, 20), 2 ' magenta.
PAINT (50, 100), 1, 2 'Paint tail cyan.
CIRCLE (250,100),30,0,PI*3/4,PI* 5/4,1.5 'Draw gills in black.
FOR Y = 90 TO 110 STEP 4
LINE (40, Y)-(52, Y), 0 'Draw comb in tail.
NEXT
See also:
Syntax
- PAINT [STEP] (x!,y!)[,[paint] [,[bordercolor&] [,background$]]]
Description/Parameter(s)
STEP | Enables use of relative coordinates. |
(x!,y!) | The screen coordinates where painting begins. |
paint | A numeric expression that specifies the color to paint with, or a string expression that indicates the pattern ("tiling") to paint with. |
bordercolor& | A numeric expression that specifies which color to use for the boundary of the figure. Default color is same as paint. |
background$ | A string expression that specifies the tile pattern to skip during boundary checking. |
- The coordinates (x!,y!) must be inside or outside of a figure, not on the border itself. If this point is inside, the figure's interior is painted; if the point is on the outside, the background is painted.
- If the paint argument is a numeric expression, the number must be a valid color attribute. If you do not specify paint, the foreground color attribute is used. For information about valid colors, numbers, and attributes see the following:If the paint argument is a string expression, the PAINT statement "tiles," a process that paints a pattern rather than a solid color. Tiling is similar to "line styling," which creates dashed lines rather than solid lines.
- The argument bordercolor& is a numeric expression identifying the color attribute to use to paint the border of the figure. When the border color is encountered, painting of the current line stops. If the bordercolor is not specified, the paint argument is used.
- The argument background$ is a string value giving the "background tile slice" to skip when checking for termination of the boundary. Painting is terminated when adjacent points display the paint color. Specifying a background tile slice allows you to paint over an already painted area. When you omit background$ the default is CHR$(0).
Usage Notes
- Painting is complete when a line is painted without changing the
- color of any pixel; in other words, when the entire line is equal to the paint color. The PAINT statement permits coordinates outside the screen or viewport.
- Tiling also can be done to produce various patterns of different colors. "Tiling" is the design of a PAINT pattern represented in string form. The tile string is eight bits wide and up to 64 bytes long. Each byte masks eight bits along the x axis when plotting points. The syntax for constructing the tile mask is:A$ = CHR$(arg1)+CHR$(arg2)+…+CHR$(argn)The arguments to CHR$ are numbers between 0 and 255, represented in binary form across the x axis of the tile. There can be up to 64 of these CHR$ elements; each generates an image not of the assigned character, but of the bit arrangement of the code for that character. For example, the decimal number 85 is binary 01010101; the graphic image line on a black-and-white screen generated by CHR$(85) is an eight-pixel line, with even-numbered points white and odd-numbered points black. That is, each bit equal to 1 turns the associated pixel on and each bit equal to 0 turns the associated bit off in a black- and-white system. The ASCII character CHR$(85), which is U, is not displayed in this case.
PAINT (x, Y), a$ - When supplied, background defines the "background tile slice" to skip when checking for boundary termination. You cannot specify more than two consecutive bytes that match the tile string in the background tile slice. If you specify more than two consecutive bytes, BASIC generates the error message "Illegal function call."
Example
This example uses PAINT to create a magenta fish with a cyan tail.
CONST PI = 3.1415926536#
CLS 'Clear screen.
SCREEN 1
CIRCLE (190, 100), 100, 1, , , .3 'Outline fish body in cyan.
CIRCLE (265, 92), 5, 1, , , .7 'Outline fish eye in cyan.
PAINT (190, 100), 2, 1 'Fill in fish body with magenta.
LINE (40, 120)-STEP(0, -40), 2 'Outline tail in magenta.
LINE -STEP(60, 20), 2
LINE -STEP(-60, 20), 2
PAINT (50, 100), 1, 2 'Paint tail cyan.
CIRCLE (250, 100), 30, 0, PI * 3 / 4, PI * 5 / 4, 1.5'Draw gills in black.
FOR Y = 90 TO 110 STEP 4
LINE (40, Y)-(52, Y), 0 'Draw comb in tail.
NEXT
See also: