The stroke
function applies a stroke to the current shape within the Sdf2d
drawing context, blending a specified color along the edge of the shape based on the stroke width. Unlike stroke_keep
, the stroke
function resets the internal shape and clipping state after performing the stroke operation, making it ready for a new shape definition.
Sdf2d
instance where the stroke operation is performed. The function modifies the result
and resets certain fields (shape
, old_shape
, clip
, has_clip
) of self
in place.vec4
): An RGBA color for the stroke.float
): The width of the stroke. The stroke width is scaled according to the current scale_factor
of the drawing context.In this example:
Sdf2d
context using the current position and size of the viewport.sdf.box
to draw a rectangle starting at position (10.0, 10.0)
with a width and height of 80.0
units and a corner radius of 5.0
.stroke
to apply a red stroke (#f00
) with a width of 2.5
units to the current shape (the rectangle). After this, the internal shape and clipping state are reset.(50.0, 50.0)
with a radius of 30.0
.#00f
) with a width of 1.5
units to the new shape.sdf.result
, which contains the final rendered color after all drawing operations.stroke_keep
, the stroke
function resets the internal shape (shape
, old_shape
) and clipping (clip
, has_clip
) state after execution. This means you can start defining a new shape immediately after without manual resets.stroke
resets the shape state, ensure that you apply it after defining the shape you wish to stroke.width
parameter is adjusted based on the scale_factor
of the Sdf2d
context, ensuring consistent stroke width regardless of transformations.#f00
for red, #00f
for blue) or as vec4
values.stroke
and defining new shapes between calls, you can apply multiple strokes to different shapes sequentially.