Prism
GuideCookbookExamplesErrorsPlayground

Guide

01Lessons & Slides02Exercises03Scene & State04Objects05Three dimensions06Controls07Timeline08Loops & Logic09Expressions & Math

Guide · 04 of 09

Objects

Objects are the visual elements of a scene. Properties go in a trailing { key: value } block — omit it entirely if the object needs no configuration. All objects accept: color, style (solid/dashed/dotted), show:<expr>, width:<number>. Note: curve, line, rect, circle, polygon, vector, arc, image require plane scenes; only point and label work on numberline scenes.

curve#

Plots f(x) across the domain. Give it a (x, y) pair instead to trace a parametric curve over the parameter t — supply t: [start, end]. State variables can appear in either form. A vertical asymptote (tan(x), 1/x, ...) breaks the stroke automatically — no special syntax needed, just let the domain span the pole.

curve <id> = <expr> { [props] }  OR  curve <id> = (x(t), y(t)) { t: [start, end], [steps: <n>] }
proptypedescription
t[start, end]parameter range (parametric form only)
stepsnumbersample count for parametric curves
whereexprboolean in x — draw the curve only where it holds (piecewise)

Example

-6-4-2246-6-4-2246

area#

Shades the region under a curve. Fills between y = <upper expr> and y = 0 (or lower: for a second curve), clipped to x in [from, to] (defaults to the scene domain). from/to can bind to state, so a slider can sweep the shaded width.

area <id> = <upper expr> { [from: <n>], [to: <n>], [lower: <expr>], [opacity: <n>] }
proptypedescription
fromexprleft x bound (default xMin)
toexprright x bound (default xMax)
lowerexprlower boundary curve (default y = 0)
opacitynumberfill opacity (default 0.15)

Example

-6-4-2246-6-4-2246

point#

A point at scene coordinates (x, y). Both coords can be expressions. drag makes it draggable — axis is x, y, or xy; bind is the state key updated by the drag. snap rounds the dragged value to the nearest step (grid = nearest 1). drag: along(<objId>) -> <bind> constrains the drag to a circle or two-point line object — bind receives an angle (radians) for a circle, or 0..1 for a line segment; the point's own position should already be an expression of that param. The bare open flag draws a hollow (unfilled) marker instead of a solid disc — the standard way to mark a removable discontinuity or an excluded one-sided limit endpoint.

point <id> = (x, y) { [drag: <axis> -> <bind>], [snap: <n>|(nx,ny)|grid], [r: <number>], [label: "text"], [open], [props] }
proptypedescription
dragaxis -> bindmake it draggable, writes state
snapnumber | (number, number) | gridround the dragged value(s) to a step
rnumberradius in pixels (default 6)
labelstringtext label next to the point
openflagdraw a hollow marker instead of a filled disc

Example

-6-4-2246-6-4-2246vertexhole

line#

A line segment uses -> arrow syntax. For an infinite line through a point, omit = and put through: and slope: in the props block instead.

line <id> = (x1,y1) -> (x2,y2) { [props] }  OR  line <id> { through: <obj_id>, slope: <expr>, [props] }

Example

-6-4-2246-6-4-2246

label#

Text positioned in scene coordinates. Use ${expr} in the text for live-updating values (rounded to 2 dp). Add tex flag to render as LaTeX via KaTeX. anchor: says which end of the text sits on (x, y) — the default start runs the text rightwards, middle centres it, which is what you want for a column of numbers of different widths.

label [id] at (x, y) = <text> { [size: <number>], [anchor: start|middle|end], [tex], [props] }

Example

-6-4-2246-6-4-2246slope = 0
x2+1x^2 + 1x2+1

rect#

(x, y) is the bottom-left corner in scene coords. Width and height are expressions. rotate: tilts the rectangle counter-clockwise by that many degrees about (x, y), so the anchor stays put and the body swings around it — that is what puts a block on a ramp. The angle can be live state, and the rotation happens in scene coords, so it stays correct with or without aspect: equal.

rect <id> = (x, y) { w: <expr>, h: <expr>, [rotate: <expr>], [opacity: <number>], [props] }

Example

-6-4-2246-6-4-2246
ramp angle25
060

circle#

Circle centered at (x, y) with radius r in scene units.

circle <id> = (x, y) { r: <expr>, [opacity: <number>], [props] }

Example

-6-4-2246-6-4-2246

polygon#

Closed polygon. Vertices are a list [...] of (x, y) tuples. rotate: turns the whole shape counter-clockwise by that many degrees about the first vertex.

polygon <id> = [(x1,y1), (x2,y2), ...] { [rotate: <expr>], [props] }

Example

-6-4-2246-6-4-2246
spin0
0360

vector#

An arrow from (x1,y1) to (x2,y2). All coords can be expressions.

vector <id> = (x1,y1) -> (x2,y2) { [props] }

Example

-6-4-2246-6-4-2246

arc#

An arc centered at (x, y), from from degrees to to degrees (counter-clockwise). Useful for angle markers.

arc <id> = (x, y) { r: <expr>, from: <degrees>, to: <degrees>, [props] }

Example

-6-4-2246-6-4-2246

image#

(x, y) is the bottom-left corner in scene coords; width/height are expressions. src must be an http(s) URL, a data:image/ URI, or a root-relative path — nothing else compiles. alt is required: it becomes the image's accessible description, so write what it shows, not just its filename.

image <id> = (x, y) { w: <expr>, h: <expr>, src: "", alt: "", [opacity: <number>] }
proptypedescription
srcstringhttp(s) URL, data:image/ URI, or /path
altstringrequired accessible description
opacitynumberfill opacity (default 1)

Example

-6-4-2246-6-4-2246
← PreviousScene & StateNext →Three dimensions

On this page

curveareapointlinelabelrectcirclepolygonvectorarcimage