The box
function draws a rectangle with rounded corners within the Sdf2d
drawing context. The rectangle is defined by its position, dimensions, and a uniform corner radius applied to all corners.
Sdf2d
instance. The function modifies the internal state of self
to include the box shape.float
): The x-coordinate of the lower-left corner of the box.float
): The y-coordinate of the lower-left corner of the box.float
): The width of the box.float
): The height of the box.float
): The radius of the rounded corners.self
to represent the box with rounded corners.In this example:
Sdf2d
context using the current position (self.pos
) and size (self.rect_size
) of the viewport.box
function to draw a rectangle starting at position (10.0, 10.0)
with a width and height of 100.0
units and a corner radius of 5.0
. This creates a square with uniformly rounded corners.sdf.fill(#f00)
.sdf.result
, which contains the final rendered color.(x, y)
. The w
and h
parameters define the width and height, extending the box to the right and upwards.r
parameter sets the radius for all four corners equally. Adjusting this value changes the rounding of the corners, with 0.0
resulting in sharp corners.box
, use a fill function like fill
or fill_keep
to render it.translate
, rotate
, or scale
can be applied to the Sdf2d
context to modify the position and orientation of the box.