Vital.sandbox
Engine

engine.draw_polygon

Client

Draws a filled polygon from a series of 2D points on the canvas


Syntax

local status = engine.draw_polygon(
    points, 
    color = {1, 1, 1, 1}, 
    stroke = 0, 
    stroke_color = {1, 1, 1, 1}, 
    rotation = 0, 
    pivot = {0, 0}
)

Must be called within the vital.sandbox:draw event. Invoking this function outside of that event will have no effect.

  • Inside the event — executes as expected, rendering the filled polygon to the canvas each frame
  • Outside the event — the call will be silently ignored and nothing will be drawn
  • Recommended usage — register a handler via network:fetch("vital.sandbox:draw", true):on(...) and place all canvas draw calls inside it

Parameters

TypeNameDescription
vector2[]pointsArray of 2D points defining the polygon vertices
colorcolorFill color of the polygon
floatstrokeOutline thickness in pixels — set to 0 to disable
colorstroke_colorColor of the outline
floatrotationRotation angle in radians
vector2pivotPivot point for rotation, relative to the polygon's origin

Returns

TypeNameDescription
boolstatustrue on successful execution, or false on failure

Examples

Draw polygons with various styles
network:fetch("vital.sandbox:draw", true):on(function()
    --Draw a simple triangle
    engine.draw_polygon({{100, 0}, {200, 200}, {0, 200}})

    --Draw a filled blue triangle with a red outline
    engine.draw_polygon({{100, 0}, {200, 200}, {0, 200}}, {0, 0, 1, 1}, 3, {1, 0, 0, 1})

    --Draw a rotated polygon around a custom pivot
    engine.draw_polygon({{0, 0}, {100, 0}, {100, 100}, {0, 100}}, {1, 1, 0, 1}, 0, {1, 1, 1, 1}, math.pi/4, {50, 50})
end)

On this page