Skip to content

Game

2D, 3D, and 4D vectors. Backed by glam.

MethodSignatureDescription
length() -> floatMagnitude
normalized() -> VecNUnit vector
dot(other: VecN) -> floatDot product
lerp(other: VecN, t: float) -> VecNLinear interpolation
cross(other: Vec3) -> Vec3Cross product (3D only)
let v2 = Vector2(x: 1.0, y: 0.0)
let v3 = Vector3(x: 0.0, y: 1.0, z: 0.0)
v2.length()
v2.normalized()
v2.dot(other)
v2.lerp(other, 0.5)
v3.cross(other)

3x3 and 4x4 matrices. Backed by glam.

MethodSignatureDescription
multiply(other: MatN) -> MatNMatrix multiply
inverse() -> MatNInverse matrix
transpose() -> MatNTranspose matrix
let m = Matrix4_IDENTITY
let rot = Matrix4_rotation(axis, angle)
let scale = Matrix4_scale(sx, sy, sz)
let trans = Matrix4_translation(tx, ty, tz)
m.multiply(other)
m.inverse()
m.transpose()

Rotation representation. Backed by glam.

MethodSignatureDescription
fromAxisAngle(axis: Vec3, angle: float) -> QuaternionFrom axis + angle
fromEuler(x: float, y: float, z: float) -> QuaternionFrom Euler angles
lookRotation(forward: Vec3, up: Vec3) -> QuaternionLook rotation
normalized() -> QuaternionUnit quaternion
slerp(other: Quaternion, t: float) -> QuaternionSpherical lerp
toMatrix() -> Matrix4Convert to matrix
let q = Quaternion_fromAxisAngle(axis, angle)
let q = Quaternion_fromEuler(x, y, z)
q.normalized()
q.slerp(other, t)
q.toMatrix()

RGBA color.

MethodSignatureDescription
fromHex(hex: string) -> ColorFrom hex string
fromHSV(h: float, s: float, v: float) -> ColorFrom HSV values
lerp(other: Color, t: float) -> ColorInterpolate colors
let red = Color(r: 1.0, g: 0.0, b: 0.0, a: 1.0)
let c = Color.fromHex("#FF5733")
let c = Color.fromHSV(h, s, v)
c.lerp(other, 0.5)

2D rectangle and 3D bounding box.

MethodSignatureDescription
contains(point: VecN) -> boolPoint inside check
intersects(other: Self) -> boolOverlap check
area() -> floatArea (2D) or volume (3D)
let r = Rectangle(x: 0.0, y: 0.0, width: 100.0, height: 50.0)
r.contains(point)
r.intersects(other)
r.area()

Module name: "tween". Animate a value over time.

MethodSignatureDescription
setEasing(name: string)Set easing function
setLoop(mode: string)Set loop mode
setDelay(seconds: float)Delay before start
update(delta: float)Advance by delta
value() -> floatCurrent interpolated value
isFinished() -> boolTrue when complete
reset()Reset to start
let t = Tween(from: 0.0, to: 100.0, duration: 2.0)
t.setEasing("easeInQuad") // linear, easeInQuad, easeOutQuad, easeInOutQuad,
// easeInCubic, easeOutCubic, easeInOutCubic, smoothstep
t.setLoop("pingpong") // "none", "loop", "pingpong"
t.setDelay(0.5)
t.update(delta)
let value = t.value()
t.isFinished()

Module name: "timer".

MethodSignatureDescription
start()Start the timer
update(delta: float)Advance by delta
stop()Stop the timer
reset()Reset to initial state
isFinished() -> boolTrue when elapsed >= duration
isRunning() -> boolTrue while running
elapsed() -> floatSeconds elapsed
remaining() -> floatSeconds remaining
setRepeating(repeat: bool)Auto-reset on finish
setCallback(fn: () -> void)Called on finish
let t = Timer(duration: 5.0)
t.start()
t.update(delta)
t.isFinished()
t.elapsed()
t.remaining()
t.setRepeating(true)
t.setCallback(myFunction)