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)
| Parameter | Type | Default | Description |
|---|---|---|---|
color | Color | $COLOR_BLACK | Background color |
gradient | Gradient | — | Linear gradient, overrides color |
draw::circle
Draws a filled circle.
draw::circle(x: 400.0, y: 300.0, radius: 50.0, color: $COLOR_RED)
| Parameter | Type | Default | Description |
|---|---|---|---|
x | Float | 0.0 | Center X position |
y | Float | 0.0 | Center Y position |
radius | Float | 50.0 | Circle radius |
color | Color | $COLOR_WHITE | Fill color |
gradient | Gradient | — | Linear gradient, overrides color |
stroke | Boolean | false | Draw outline instead of fill |
stroke_width | Float | 1.0 | Outline thickness |
stroke_color | Color | $COLOR_BLACK | Outline 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)
| Parameter | Type | Default | Description |
|---|---|---|---|
x | Float | 0.0 | Top-left X position |
y | Float | 0.0 | Top-left Y position |
width | Float | 100.0 | Rectangle width |
height | Float | 100.0 | Rectangle height |
corner_radius | Float | 0.0 | Nonnegative radius, clamped to half the smaller dimension |
color | Color | $COLOR_WHITE | Fill color |
gradient | Gradient | — | Linear gradient, overrides color |
stroke | Boolean | false | Draw outline instead of fill |
stroke_width | Float | 1.0 | Outline thickness |
stroke_color | Color | $COLOR_BLACK | Outline color |
rotation_rad / rotation_deg | Float | 0.0 | Rotation 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
)
| Parameter | Type | Default | Description |
|---|---|---|---|
points | Array | [] | Array of [x, y] coordinate pairs |
color | Color | $COLOR_WHITE | Fill color |
gradient | Gradient | — | Linear gradient, overrides color |
rotation_rad / rotation_deg | Float | 0.0 | Rotation around centroid, in the named unit |
stroke | Boolean | false | Draw outline instead of fill |
stroke_width | Float | 1.0 | Outline thickness |
stroke_color | Color | $COLOR_BLACK | Outline 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)
| Parameter | Type | Default | Description |
|---|---|---|---|
x1 | Float | 0.0 | Start X |
y1 | Float | 0.0 | Start Y |
x2 | Float | 100.0 | End X |
y2 | Float | 100.0 | End Y |
color | Color | $COLOR_WHITE | Line color |
gradient | Gradient | — | Linear gradient, overrides color |
stroke_width | Float | 1.0 | Line 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)
| Parameter | Type | Default | Description |
|---|---|---|---|
x | Float | 0.0 | Center X position |
y | Float | 0.0 | Center Y position |
radius_x | Float | 50.0 | X radius |
radius_y | Float | 30.0 | Y radius |
color | Color | $COLOR_WHITE | Fill color |
gradient | Gradient | — | Linear gradient, overrides color |
stroke | Boolean | false | Draw outline instead of fill |
stroke_width | Float | 1.0 | Outline thickness |
stroke_color | Color | $COLOR_BLACK | Outline color |
rotation_rad / rotation_deg | Float | 0.0 | Rotation 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)
| Parameter | Type | Default | Description |
|---|---|---|---|
content | String | "" | Text to display |
x | Float | 0.0 | X position (baseline left) |
y | Float | 0.0 | Y position (baseline) |
size | Float | 16.0 | Font size in pixels |
color | Color | $COLOR_WHITE | Text color |
gradient | Gradient | — | Linear gradient, overrides color |
font | String | "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.