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

HDR intensity

In 2D, every drawing operation that paints colour accepts intensity from 0 to 6 (default 1), including background, shapes, lines/paths, text and images. draw::clear() has no intensity. Intensity scales linear-light brightness; it does not change opacity. A value of 1 is reference-white brightness, and values above 1 can produce highlights on an HDR display.

prop angle = 0.0
on_frame { angle = $TIME_SEC }
render {
  draw::background(color: $COLOR_BLACK)
  draw::rect(x: 100, y: 100, width: 120, height: 80,
    color: $COLOR_TURQUOISE, intensity: 4, rotation_rad: angle)
  draw::text(content: "HDR", x: 100, y: 240, size: 28, intensity: 3)
}

Rotation, transform stacks, fills/strokes, linear/radial gradients, image opacity, blend modes, filters, bloom and scramble preserve HDR in the WebGPU renderer. Intensity multiplies the paint for the whole operation, including gradient stops or image pixels. Alpha remains independent. Effects and blends operate in linear light, so translucent overlaps can differ from the legacy SDR rendering.

The player attempts HDR when a 2D drawing call explicitly supplies intensity and WebGPU is available. Dynamic values and calls inside functions or conditions also opt in; even explicit intensity: 1 selects the HDR renderer. Scripts with no drawing intensity stay on the native SDR path, avoiding HDR recording and replay costs. Effect parameters alone do not opt a script into HDR. Actual highlight brightness depends on browser, display and system settings. If WebGPU cannot run, the existing SDR renderer displays the base colours and ignores intensity. PNG captures/thumbnails continue to use that SDR renderer. This does not add HDR to 3D drawing or HDR image export.

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
gradientGradient—Linear 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
gradientGradient—Linear 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
gradientGradient—Linear 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
gradientGradient—Linear 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
gradientGradient—Linear 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
gradientGradient—Linear 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
gradientGradient—Linear 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.