Fill
Description
The fill()
function sets the fill color for shapes. It can accept either a SIMD4 color value or individual RGB(A) components.
Syntax
// Using a SIMD4 color value
fill(color: SIMD4<Float>)
// Using RGB components
fill(r: Float, g: Float, b: Float, a: Float = 255)
// Using positional RGB components
fill(r, g, b, a)
// Using grayscale value
fill(gray: Float, a: Float = 255)
Parameters
color
A SIMD4 color value (optional)
r
Red component (0-255)
g
Green component (0-255)
b
Blue component (0-255)
a
Alpha component (0-255, defaults to 255)
gray
Grayscale value (0-255)
Example
// Set fill color using a SIMD4 color
fill(color(255, 0, 0))
// Set fill color using RGB components
fill(255, 0, 0) // Red
fill(r: 0, g: 255, b: 0) // Green
// Set semi-transparent fill
fill(255, 0, 0, 128) // Semi-transparent red
// Set grayscale fill
fill(128) // Medium gray
fill(255, 128) // Semi-transparent white
Notes
- The fill color affects all subsequent shape drawing operations
- Input values are in the range 0-255 but are automatically converted to 0-1
- The alpha component defaults to 255 (fully opaque) if not specified
- Using a single value creates a grayscale color