PAINT: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 24: | Line 24: | ||
''Example 1:'' Painting a [[CIRCLE]] immediately after it is drawn using [[STEP]](0, 0) to paint from the circle's center point. | ''Example 1:'' Painting a [[CIRCLE]] immediately after it is drawn using [[STEP]](0, 0) to paint from the circle's center point. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl | {{Cl|SCREEN}} 12 | ||
x = 200: y = 200 | x = 200: y = 200 | ||
{{Cl|CIRCLE}} (x, y), 100, 10 | {{Cl|CIRCLE}} (x, y), 100, 10 | ||
Line 38: | Line 38: | ||
{{Cl|FOR...NEXT|FOR}} i = 1 {{Cl|TO}} {{Cl|LEN}}(drw$) | {{Cl|FOR...NEXT|FOR}} i = 1 {{Cl|TO}} {{Cl|LEN}}(drw$) | ||
tmp$ = {{Cl|UCASE$}}({{Cl|MID$}}(drw$, i, 1)) | tmp$ = {{Cl|UCASE$}}({{Cl|MID$ (function)|MID$}}(drw$, i, 1)) | ||
check = 1 | check = 1 | ||
{{Cl|SELECT CASE}} tmp$ | {{Cl|SELECT CASE}} tmp$ | ||
Line 55: | Line 55: | ||
{{Cl|FOR...NEXT|FOR}} j = i + 1 {{Cl|TO}} i + 4 'set for up to 4 digits and spaces | {{Cl|FOR...NEXT|FOR}} j = i + 1 {{Cl|TO}} i + 4 'set for up to 4 digits and spaces | ||
{{Cl|IF...THEN|IF}} j > {{Cl|LEN}}(drw$) {{Cl|THEN}} {{Cl|EXIT}} {{Cl|FOR...NEXT|FOR}} | {{Cl|IF...THEN|IF}} j > {{Cl|LEN}}(drw$) {{Cl|THEN}} {{Cl|EXIT}} {{Cl|FOR...NEXT|FOR}} | ||
n$ = {{Cl|MID$}}(drw$, j, 1) | n$ = {{Cl|MID$ (function)|MID$}}(drw$, j, 1) | ||
num = {{Cl|ASC}}(n$) | num = {{Cl|ASC (function)|ASC}}(n$) | ||
{{Cl|IF...THEN|IF}} (num > 47 {{Cl|AND (boolean)|AND}} num < 58) {{Cl|OR (boolean)|OR}} num = 32 {{Cl|THEN}} | {{Cl|IF...THEN|IF}} (num > 47 {{Cl|AND (boolean)|AND}} num < 58) {{Cl|OR (boolean)|OR}} num = 32 {{Cl|THEN}} | ||
snum$ = snum$ + n$ | snum$ = snum$ + n$ | ||
Line 120: | Line 120: | ||
{{Cl|IF}} {{Cl|LEFT$}}(row$, 3) = "---" {{Cl|THEN}} {{Cl|EXIT}} {{Cl|DO}} | {{Cl|IF}} {{Cl|LEFT$}}(row$, 3) = "---" {{Cl|THEN}} {{Cl|EXIT}} {{Cl|DO}} | ||
{{Cl|FOR}} x = 0 {{Cl|TO}} 7 | {{Cl|FOR}} x = 0 {{Cl|TO}} 7 | ||
pixel = {{Cl|VAL}}("&h" + {{Cl|MID$}}(row$, x + 1, 1)) | pixel = {{Cl|VAL}}("&h" + {{Cl|MID$ (function)|MID$}}(row$, x + 1, 1)) | ||
{{Cl|FOR}} bit = 0 {{Cl|TO}} 3 | {{Cl|FOR}} bit = 0 {{Cl|TO}} 3 | ||
{{Cl|IF}} pixel {{Cl|AND}} 2 ^ bit {{Cl|THEN}} | {{Cl|IF}} pixel {{Cl|AND}} 2 ^ bit {{Cl|THEN}} |
Latest revision as of 00:42, 26 February 2023
The PAINT statement is used to fill a delimited area in a graphic screen mode with color.
Syntax
- PAINT [STEP] (column%, row%), fillColor[, borderColor%]
Parameters
- Can use the STEP keyword for relative coordinate placements. See example 1 below.
- fillColor is an INTEGER or LONG 32-bit value to paint the inside of an object. Colors are limited to the SCREEN mode used.
- Optional INTEGER or LONG 32-bit borderColor% is the color of the border of the shape to be filled when this is different from the fill color.
- fillColor can be a string made up of a sequence of CHR$ values, each representing a tiling pattern to fill the shape. See Example 3 below.
Description
- Graphic column% and row% INTEGER pixel coordinates should be inside of a fully closed "shape", whether it's a rectangle, circle or custom-drawn shape using DRAW.
- If the coordinates passed to the PAINT statement are on a pixel that matches the border colors, no filling will occur.
- If the shape's border isn't continuous, the "paint" will "leak".
- If the shape is not totally closed, every color except the border color may be painted over.
- DRAW shapes can be filled using the string "P fillColor, borderColor". Use a "B" blind move to offset from the shape's border.
Examples
Example 1: Painting a CIRCLE immediately after it is drawn using STEP(0, 0) to paint from the circle's center point.
SCREEN 12 x = 200: y = 200 CIRCLE (x, y), 100, 10 PAINT STEP(0, 0), 2, 10 |
- Results: A circle located at x and y with a bright green border filled in dark green. The last coordinate used was the circle's center point and PAINT used it also with the STEP relative coordinates being zero.
Example 2: Routine to check a DRAW string to make sure that the drawn shape is fully closed so that a PAINT does not "leak".
SCREEN 12 drw$ = "C15S20R9D4R6U3R3D3R7U5H3U2R9D3G2D6F1D3F5L10D1G1L4H2L7G2L3H2L3U8L2U5R1BF4" FOR i = 1 TO LEN(drw$) tmp$ = UCASE$(MID$(drw$, i, 1)) check = 1 SELECT CASE tmp$ CASE "U": ver = -1: hor = 0 CASE "D": ver = 1: hor = 0 CASE "E": ver = -1: hor = 1 CASE "F": ver = 1: hor = 1 CASE "G": ver = 1: hor = -1 CASE "H": ver = -1: hor = -1 CASE "L": ver = 0: hor = -1 CASE "R": ver = 0: hor = 1 CASE ELSE: check = 0 END SELECT IF check THEN snum$ = "" FOR j = i + 1 TO i + 4 'set for up to 4 digits and spaces IF j > LEN(drw$) THEN EXIT FOR n$ = MID$(drw$, j, 1) num = ASC(n$) IF (num > 47 AND num < 58) OR num = 32 THEN snum$ = snum$ + n$ ELSE: EXIT FOR END IF NEXT vertical = vertical + (ver * VAL(snum$)) horizont = horizont + (hor * VAL(snum$)) END IF PRINT tmp$, horizont, vertical 'SLEEP NEXT PSET (300, 300): DRAW drw$ |
- Explanation: If the DRAW string is fully closed, the end values should each be 0. In the example, the proper result should be 4, 4 as there is a BF4 offset for PAINT which cannot be on a border. The result is 4, 5 because the shape is not completely closed.
Example 3: Tiling using PAINT to create a red brick pattern inside a yellow border:
DIM Row$(1 TO 8) SCREEN 12 'make red-brick wall Row$(1) = CHR$(&H0) + CHR$(&H0) + CHR$(&HFE) + CHR$(&HFE) Row$(2) = Row$(1) Row$(3) = Row$(1) Row$(4) = CHR$(&H0) + CHR$(&H0) + CHR$(&H0) + CHR$(&H0) Row$(5) = CHR$(&H0) + CHR$(&H0) + CHR$(&HEF) + CHR$(&HEF) Row$(6) = Row$(5) Row$(7) = Row$(5) Row$(8) = Row$(4) Tile$ = Row$(1) + Row$(2) + Row$(3) + Row$(4) + Row$(5) + Row$(6) + Row$(7) + Row$(8) LINE (59, 124)-(581, 336), 14, B 'yellow box border to paint inside PAINT (320, 240), Tile$, 14 'paints brick tiles within yellow border |
Example 4: Generating a tiling pattern for PAINT from DATA statements:
ptndata: DATA "c4444444" DATA "c4444444" DATA "cccccccc" DATA "444c4444" DATA "444c4444" DATA "444c4444" DATA "cccccccc" DATA "c4444444" DATA --- RESTORE ptndata: ptn$ = loadpattern$ SCREEN 7 DRAW "c15l15f10g10r30g10f10l50u80r100m160,100" PAINT (160, 90), ptn$, 15 FUNCTION loadpattern$ DIM quad(0 TO 3) AS INTEGER res$ = "" DO READ row$ IF LEFT$(row$, 3) = "---" THEN EXIT DO FOR x = 0 TO 7 pixel = VAL("&h" + MID$(row$, x + 1, 1)) FOR bit = 0 TO 3 IF pixel AND 2 ^ bit THEN quad(bit) = quad(bit) OR (2 ^ (7 - x)) END IF NEXT NEXT FOR i = 0 TO 3 res$ = res$ + CHR$(quad(i)) quad(i) = 0 NEXT LOOP loadpattern$ = res$ END FUNCTION |
- Code provided by collaborator https://github.com/NEONTEC75
See also