Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Visamp Docs

Drawing Primitives

All drawing happens inside render blocks using draw:: functions.

For polylines, Béziers, arcs, images, rounded rectangles, polygon outlines and 2D transforms, see Creative Drawing Tools.

draw::clear

Clears the entire canvas. Call this at the start of your render block to start fresh each frame. In 2D, omit it to let previous frames persist (useful for trails and accumulation effects).

draw::clear()

No arguments. Clears the full canvas dimensions.

draw::background

Fills the entire canvas with a color.

draw::background(color: $COLOR_BLACK)
ParameterTypeDefaultDescription
colorColor$COLOR_BLACKBackground color
gradientGradientLinear gradient, overrides color

draw::circle

Draws a filled circle.

draw::circle(x: 400.0, y: 300.0, radius: 50.0, color: $COLOR_RED)
ParameterTypeDefaultDescription
xFloat0.0Center X position
yFloat0.0Center Y position
radiusFloat50.0Circle radius
colorColor$COLOR_WHITEFill color
gradientGradientLinear gradient, overrides color
strokeBooleanfalseDraw outline instead of fill
stroke_widthFloat1.0Outline thickness
stroke_colorColor$COLOR_BLACKOutline color

draw::rect

Draws a rectangle.

draw::rect(x: 100.0, y: 200.0, width: 150.0, height: 80.0, color: $COLOR_BLUE, rotation_rad: 0.5)
ParameterTypeDefaultDescription
xFloat0.0Top-left X position
yFloat0.0Top-left Y position
widthFloat100.0Rectangle width
heightFloat100.0Rectangle height
corner_radiusFloat0.0Nonnegative radius, clamped to half the smaller dimension
colorColor$COLOR_WHITEFill color
gradientGradientLinear gradient, overrides color
strokeBooleanfalseDraw outline instead of fill
stroke_widthFloat1.0Outline thickness
stroke_colorColor$COLOR_BLACKOutline color
rotation_rad / rotation_degFloat0.0Rotation around center, in the named unit

draw::polygon

Draws a filled polygon from a list of points.

draw::polygon(
  points: [
    [400.0, 100.0],
    [200.0, 400.0],
    [600.0, 400.0],
  ],
  color: $COLOR_GREEN,
  rotation_rad: 0.0
)
ParameterTypeDefaultDescription
pointsArray[]Array of [x, y] coordinate pairs
colorColor$COLOR_WHITEFill color
gradientGradientLinear gradient, overrides color
rotation_rad / rotation_degFloat0.0Rotation around centroid, in the named unit
strokeBooleanfalseDraw outline instead of fill
stroke_widthFloat1.0Outline thickness
stroke_colorColor$COLOR_BLACKOutline color

draw::line

Draws a line between two points.

draw::line(x1: 100.0, y1: 100.0, x2: 700.0, y2: 500.0, color: $COLOR_WHITE, stroke_width: 2.0)
ParameterTypeDefaultDescription
x1Float0.0Start X
y1Float0.0Start Y
x2Float100.0End X
y2Float100.0End Y
colorColor$COLOR_WHITELine color
gradientGradientLinear gradient, overrides color
stroke_widthFloat1.0Line thickness

draw::ellipse

Draws an ellipse.

draw::ellipse(x: 400.0, y: 300.0, radius_x: 80.0, radius_y: 40.0, color: $COLOR_PURPLE, rotation_rad: 0.3)
ParameterTypeDefaultDescription
xFloat0.0Center X position
yFloat0.0Center Y position
radius_xFloat50.0X radius
radius_yFloat30.0Y radius
colorColor$COLOR_WHITEFill color
gradientGradientLinear gradient, overrides color
strokeBooleanfalseDraw outline instead of fill
stroke_widthFloat1.0Outline thickness
stroke_colorColor$COLOR_BLACKOutline color
rotation_rad / rotation_degFloat0.0Rotation in the named unit

draw::text

Draws text on the canvas.

draw::text(content: "Hello!", x: 350.0, y: 300.0, size: 24.0, color: $COLOR_WHITE)
ParameterTypeDefaultDescription
contentString""Text to display
xFloat0.0X position (baseline left)
yFloat0.0Y position (baseline)
sizeFloat16.0Font size in pixels
colorColor$COLOR_WHITEText color
gradientGradientLinear gradient, overrides color
fontString"monospace"CSS font family

Coordinate System

  • Origin (0, 0) is at the top-left corner
  • X increases to the right
  • Y increases downward
  • Positive rotations are clockwise; choose radians or degrees with the argument name

Rotation arguments are mutually exclusive: supply rotation_rad in radians or rotation_deg in degrees. Both default to no rotation when omitted.