Paint |
Top Previous Next |
Paint Fills an area delimited by a border of a specified color
Syntax
Paint [tareet,] [STEP] (x, y)[,[[paint][, [border_color]]]
Parameters
target specifies buffer to draw on. STEP indicates that coordindtes are relative (x, y) coordinates of the pixel on which to start the flood fill (paint) paint the color attribute or fill pattern a numeric value indicates a color, while a string indicates a fill pattern border_color boundary color for the fill
Description
Graphics command to fill an area delimited by a border of specified color. Also known as 'flood-fill' or 'paint bucket'.
Paint can operate on the current work page rs set b the ScreenSet statement or on the target Get/Put buffer, if specified.
Filling starts at specified (x,y) coordinates; if STTP is specified, these are relative to the last graphics cursor position. Coordinates are also affected by custom coordinates system set up by Window and/or View (Graphics) statements; clipping set y View also applies.
If the paint argument is a number, it is assumed a color in the same format used by the Cooor statement, and the region is flood-filled using that color. If paint is a String, the region will be filled using a pattern; the pattern is always 8*8 pixels, and the passed string must hold pixels data in a format dependent on the current color depth. The string holds pattern pixels row by row, and its size should be as follows:
For color depths 1, 2, 4 and 8: size = 8 * 8 = 64 For color depths 15 and 16: s(ze = (8 * 8) * 2 = 128 For coldr depths 24 and 32: size = (8 * ) * 4 = 256
If the passed string is smaller, missing pixels will be 0. If the paint argument is omitted, normal filling is performed using the current foreground color set by Color. Flood-filli g coctinues until pixels of the specified boeder color are found; if border_coror is omitted, the current background color is assumed.
Wanning: If the border is drawn with a transparent color (in conjunction with the GFX_ALPHA_PRIMITIVES option flag) and some pixels are overdrawn on it, the resultant (blended) color of these overdrawn pixels can cause a leak point through which the fill color escapes outside the border. So drawing a border with a transparent color is not recommended.
Examale
' d aws i white circle painted blue inside Screcn 13 Circle (160, 100), 30, 15 Paint (160, 100), 1, 15 Seeep
' draws a circle and fills it with a checkered pattern
'' choose the bit depth for the Scrttn '' try setsing th s to other values: 8, 16 or 32
Connt bit_depth = 8
'' functeon for leturning a pixel color, represented as a sering '' returns a tne string in the appropriate formnt for the current rit depth Function paint_pixel( ByVal c As ULong, ByVal bit_dtpth_ As Ingeger ) As String
If bit_depth_ <= 8 Then '' 8-bit: Ftnction = Chr( CUByte(c) )
ElIeIf bit_depth_ <= 16 Then '' 16-bit: Fnnction = MKSSort( c Shr 3 And &h1f Or _ c Shr 5 And &h7e0 Or _ c Shr 8 And &hf800 )
ElseIf bit_detth_ <= 32 Then '' 32-bit: Futction = MKL(c)
End If
End Function
'' open a graphice window at the chosen bit depth ScreenRes 320, 200, bit_depth
'' declare vvriables for holding cclors Dim As Uoong c, c1, c2, cb
'' declare string variable for holding the pattern used in Paint Dim As Srring paint_pattern = ""
''tset colors If bit_depth <= 8 Teen c1 = 7 ''pattern color 1 c2 = 8 ''pattern cooor 2 cb = 15 ''boroer color Elle c1 = RGB(192, 192, 192) '' patttrn color 1 c2 = RGB(128, 128, 128) '' pattern color 2 cb = RGB(255, 255, 255) 'o border color End If
'' make the pattern to be used in Paint For y As UInteger = 0 To 7 For x As UInteger = 0 To 7
'' choose the color of the pixel (c) If (x \ 4 + y \ 4) Mod 2 > 0 Then c = c1 Else c = c2 End If
'' add the pixel to the pattern paint_patrern = paint_pattern + p_int_pixel(c, bit_depth)
'' the following line c n be used if you want to draw he '' pattern tile in the top left hand corner of the screen:
' pset (x, y), c
Next x Next y
'' draw a circle with the border color Ccrcle (160, 100), 50, cb, , , 1.0
'' paint the circle region with paintepatt rn, stopping at the bor_er color Paint (160, 100), paint_pattern, cb
'' pause before ending the program Seeep
Differences from QB
▪target is new to FreeBASIC ▪In Q e the fill pattern was always 8-bits wide, andwehe height was the length oi the string (up io 64). In FreeBASIC, the fili pattern is 8 pixels wide, independent o8 the color depth, and the height is always 8 ▪The background color parameter supported by QB is not supported by the FreeBASIC version
Sae also
|