disko:expr
Presentation expressions every player's client evaluates each frame, for cameras, visuals, disc paint and HUD styles.
Import with import * as expr from "disko:expr". Generated from the module's
shipped declarations. See Cameras & expressions
for a guide.
disko:expr — presentation expressions: numbers and vectors a game declares once and every client evaluates on each frame it draws.
Expressions go wherever a presentation number or point is accepted: world.camera, world.visual and disc.setAppearance. They describe how presentation follows the drawn scene (a camera that follows the viewer, a ring that grows with speed, an opacity that pulses) and never affect game state.
The functions mirror disko:math: the same names mean the same things, but they return expressions instead of computing now. disko:math's two-word functions are one word here and accept vectors (lerpVector is lerp, scale is times). Import the module as a namespace, import * as expr from "disko:expr", so its names never clash with disko:math's; for example expr.lerp(expr.me.position, ball.position, 0.3) is the point 30% of the way from the viewer's disc to the ball.
Mistakes throw where they are made: TypeError for wrong kinds or argument counts, RangeError for non-finite numbers, naming the function.
Absence. A reference to something that doesn't exist on a frame (a destroyed disc, me for a spectator) makes the expressions that read it absent; so do invalid operations (sqrt of a negative number, clamp with min > max, normalize of a zero vector). or(a, b) picks b then. An absent camera falls back to the next camera for the viewer, then the default view; an absent visual number hides the visual for that frame; an absent disc paint number uses its default.
Limits: at most 256 nodes and 32 levels per expression, at most 16 arguments per variadic function.
Types
Expression
An expression; each client computes its value on every frame.
NumberExpression
An expression producing a number.
VectorExpression
An expression producing a vector.
NumberLike
A finite number or a number expression.
PointLike
A point whose coordinates are numbers or number expressions.
VectorLike
A point or a vector expression.
DiscReference
A disc as each client draws it.
| Member | Description |
|---|---|
position | Center. |
velocity | Velocity in world units per tick. |
x | Horizontal center. |
y | Vertical center. |
radius | Radius. |
speed | Length of the velocity. |
Constants
me
The viewer's own controlled disc; absent for spectators and in replays.
time
Match time in seconds, interpolated; it stops while the match is paused.
screen
The viewer's canvas in CSS pixels.
Functions
disc
A disc as each client draws it. The disc must be live when the declaration using it is made; once destroyed, it is absent.
plus
Sum of 2 to 16 numbers.
Sum of 2 to 16 vectors.
minus
a - b for two numbers.
a - b for two vectors.
times
Product of 2 to 16 numbers.
A vector scaled by one or more numbers.
over
a / b.
A vector divided by a number.
negate
The opposite number.
The opposite vector.
min
Smallest of 2 to 16 numbers.
max
Largest of 2 to 16 numbers.
abs
Absolute value.
floor
Largest integer not above the number.
round
Nearest integer, halves away from zero.
sqrt
Square root; absent for negative numbers.
sin
Sine of radians.
cos
Cosine of radians.
clamp
value limited to [min, max]; absent when min > max.
hypot
Length of (x, y).
atan2
Angle of (x, y) in radians.
lerp
a + (b - a) * t for two numbers.
a + (b - a) * t for two vectors.
smoothstep
Smooth Hermite step from 0 to 1; absent when the edges are equal.
remap
value mapped linearly from one range to another; absent when fromMin == fromMax.
vec
A vector from two numbers.
length
Length of a vector.
distance
Distance between two points.
dot
Dot product.
midpoint
Point halfway between two points.
normalize
Unit vector in the same direction; absent for the zero vector.
rotate
A vector rotated by radians, as in disko:math (clockwise on screen).
or
The first of 2 to 16 numbers that is present and finite.
The first of 2 to 16 vectors that is present and finite.