The hexagon
function draws a regular hexagon within the Sdf2d
drawing context. The hexagon is defined by its center coordinates and radius.
Sdf2d
instance. The function modifies the internal state of self
to include the hexagon shape.float
): The x-coordinate of the center of the hexagon.float
): The y-coordinate of the center of the hexagon.float
): The radius of the hexagon. This is the distance from the center to any vertex of the hexagon.self
to represent the hexagon shape.In this example:
Sdf2d
drawing context using the current position (self.pos
) and the size of the rectangle (self.rect_size
), representing the viewport area for drawing.hexagon
function to draw a regular hexagon centered at (50.0, 50.0)
with a radius of 40.0
.sdf.fill(#f00)
.PI / 6.0
radians) around the center point (50.0, 50.0)
. This affects all subsequent drawing operations and transformations.sdf.result
, which contains the final rendered color after all drawing operations.(x, y)
.r
parameter defines the size of the hexagon. It represents the distance from the center to any vertex.translate
, rotate
, or scale
can be applied to the Sdf2d
context to manipulate the drawing.radians = degrees * (PI / 180)
. In the example, 30 degrees is converted to radians by PI / 6.0
.hexagon
before applying fills or other drawing operations. The fill
function renders the shape onto the context.#f00
color code is a shorthand hexadecimal notation for red (#ff0000
). You can use other color codes or vec4
values to specify different colors.Sdf2d
drawing context allows for vector graphics rendering using signed distance fields, enabling smooth and scalable shapes with anti-aliasing.