Stroke
Description
The stroke()
function sets the stroke (outline) color for shapes. It can accept either a SIMD4 color value or individual RGB(A) components.
Syntax
// Using a SIMD4 color value
stroke(color: SIMD4<Float>)
// Using RGB components
stroke(r: Float, g: Float, b: Float, a: Float = 255)
// Using positional RGB components
stroke(r, g, b, a)
// Using grayscale value
stroke(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 stroke color using a SIMD4 color
stroke(color(255, 0, 0))
// Set stroke color using RGB components
stroke(255, 0, 0) // Red
stroke(r: 0, g: 255, b: 0) // Green
// Set semi-transparent stroke
stroke(255, 0, 0, 128) // Semi-transparent red
// Set grayscale stroke
stroke(128) // Medium gray
stroke(255, 128) // Semi-transparent white
Notes
- The stroke 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
- The stroke width is set to 3 by default