Vivid is a modern web-based animation library for mathematical visualizations, similar to Manim but designed to run live in the browser. This comprehensive API documentation covers all classes, interfaces, and utilities.
interface Point2D {
x: number
y: number
}interface Point3D extends Point2D {
z: number
}interface Color {
r: number // Red component (0-1)
g: number // Green component (0-1)
b: number // Blue component (0-1)
a?: number // Alpha component (0-1, optional)
}interface Scale2D {
x: number // X-axis scale factor
y: number // Y-axis scale factor
}interface Transform2D {
translate: Point2D // Translation offset
scale: Point2D // Scale factors
rotate: number // Rotation angle in radians
}All renderable objects implement this interface:
interface VividObject {
id: string
transform: Transform2D
color: Color
visible: boolean
coordinateSystem?: VividObject
update(deltaTime: number): void
render(ctx: CanvasRenderingContext2D): void
getBounds(): { min: Point2D; max: Point2D }
// Coordinate system association
setCoordinateSystem?(axes: VividObject): this
getWorldTransform?(): Transform2D
}Creates circular shapes with customizable appearance.
class Circle implements VividObjectconstructor(options: CircleOptions = {})
interface CircleOptions {
radius?: number
color?: Color | string
fillOpacity?: number
strokeWidth?: number
strokeColor?: Color | string
}radius: number- Circle radiusvisible: boolean- Visibility flagtransform: Transform2D- Position, scale, rotation
move_to(point: Point2D): this- Move to absolute positionshift(delta: Point2D): this- Move by relative offsetscale(factor: number): this- Scale uniformlyrotate(angle: number): this- Rotate by angle (radians)setCoordinateSystem(axes: VividObject): this- Associate with coordinate systemgetBounds(): { min: Point2D; max: Point2D }- Get bounding box
Renders text with customizable fonts and alignment.
class Text implements VividObjectconstructor(text: string = '', options: TextOptions = {})
interface TextOptions {
text?: string
fontSize?: number
fontFamily?: string
color?: Color | string
align?: 'left' | 'center' | 'right'
baseline?: 'top' | 'middle' | 'bottom' | 'alphabetic'
}visible: boolean- Visibility flagtransform: Transform2D- Position, scale, rotation
setText(newText: string): this- Update text contentgetText(): string- Get current textsetFontSize(size: number): this- Change font sizemove_to(point: Point2D): this- Move to absolute positionshift(delta: Point2D): this- Move by relative offsetscale(factor: number): this- Scale uniformlyrotate(angle: number): this- Rotate by angle (radians)
MathSymbols- Collection of Unicode math symbols (α, β, π, ∞, etc.)
Advanced text rendering with LaTeX support via KaTeX.
class MathText implements VividObjectconstructor(mathExpression: string, options: MathTextOptions = {})
interface MathTextOptions {
fontSize?: number
color?: Color | string
backgroundColor?: Color | string
fontFamily?: string
padding?: number
renderMode?: 'katex' | 'unicode'
}visible: boolean- Visibility flagtransform: Transform2D- Position, scale, rotation
setExpression(expression: string): this- Update LaTeX expressionsetText(text: string): this- Alias for setExpressiongetExpression(): string- Get current expressionsetFontSize(size: number): this- Change font sizesetColor(color: Color | string): this- Change text colormove_to(point: Point2D): this- Move to absolute positionshift(delta: Point2D): this- Move by relative offsetscale(factor: number): this- Scale uniformlyrotate(angle: number): this- Rotate by angle (radians)
Creates line segments between two points.
class Line implements VividObjectconstructor(start: Point2D = { x: -1, y: 0 }, end: Point2D = { x: 1, y: 0 }, options: LineOptions = {})
interface LineOptions {
start?: Point2D
end?: Point2D
color?: Color | string
strokeWidth?: number
lineCap?: 'butt' | 'round' | 'square'
lineDash?: number[]
}visible: boolean- Visibility flagtransform: Transform2D- Position, scale, rotation
setStart(point: Point2D): this- Set start pointsetEnd(point: Point2D): this- Set end pointsetPoints(start: Point2D, end: Point2D): this- Set both pointsgetStart(): Point2D- Get start pointgetEnd(): Point2D- Get end pointgetLength(): number- Calculate line lengthmove_to(point: Point2D): this- Move to absolute positionshift(delta: Point2D): this- Move by relative offsetscale(factor: number): this- Scale uniformlyrotate(angle: number): this- Rotate by angle (radians)
Creates rectangular shapes with optional rounded corners.
class Rectangle implements VividObjectconstructor(options: RectangleOptions = {})
interface RectangleOptions {
width?: number
height?: number
color?: Color | string
fillOpacity?: number
strokeWidth?: number
strokeColor?: Color | string
cornerRadius?: number
}width: number- Rectangle widthheight: number- Rectangle heightvisible: boolean- Visibility flagtransform: Transform2D- Position, scale, rotation
setSize(width: number, height: number): this- Change dimensionssetCornerRadius(radius: number): this- Set corner roundingmove_to(point: Point2D): this- Move to absolute positionshift(delta: Point2D): this- Move by relative offsetscale(factor: number): this- Scale uniformlyrotate(angle: number): this- Rotate by angle (radians)
Plots mathematical functions (y = f(x)) or parametric curves.
class FunctionPlot implements VividObjectconstructor(funcOrParametric: FunctionType | ParametricFunction, options: FunctionPlotOptions = {})
type FunctionType = (x: number) => number
type ParametricFunction = (t: number) => { x: number; y: number }
interface FunctionPlotOptions {
func?: FunctionType
parametric?: ParametricFunction
tMin?: number
tMax?: number
xMin?: number
xMax?: number
samples?: number
color?: Color | string
strokeWidth?: number
lineDash?: number[]
smooth?: boolean
}visible: boolean- Visibility flagtransform: Transform2D- Position, scale, rotation
updateFunction(func: FunctionType, xMin?: number, xMax?: number): this- Update functionupdateParametric(parametric: ParametricFunction, tMin?: number, tMax?: number): this- Update parametric functionsetSamples(samples: number): this- Change resolutionsetColor(color: Color | string): this- Change line colormove_to(point: Point2D): this- Move to absolute positionshift(delta: Point2D): this- Move by relative offsetscale(factor: number): this- Scale uniformlyrotate(angle: number): this- Rotate by angle (radians)
MathFunctions = {
// Basic functions
linear: (m: number, b?: number) => (x: number) => number
quadratic: (a: number, b?: number, c?: number) => (x: number) => number
// Trigonometric
sin: (amplitude?: number, frequency?: number, phase?: number) => (x: number) => number
cos: (amplitude?: number, frequency?: number, phase?: number) => (x: number) => number
// Parametric curves
circle: (radius?: number, centerX?: number, centerY?: number) => (t: number) => {x: number, y: number}
ellipse: (a?: number, b?: number, centerX?: number, centerY?: number) => (t: number) => {x: number, y: number}
spiral: (a?: number, b?: number) => (t: number) => {x: number, y: number}
}Creates polygons and polylines from arrays of points.
class PolygonFromPoints implements VividObjectconstructor(points: Point2D[] = [], options: PolygonFromPointsOptions = {})
interface PolygonFromPointsOptions {
points?: Point2D[]
color?: Color | string
fillOpacity?: number
strokeWidth?: number
strokeColor?: Color | string
closed?: boolean
smooth?: boolean
showPoints?: boolean
pointSize?: number
pointColor?: Color | string
}points: Point2D[]- Array of polygon verticesvisible: boolean- Visibility flagtransform: Transform2D- Position, scale, rotation
setPoints(points: Point2D[]): this- Replace all pointsaddPoint(point: Point2D): this- Add point to endinsertPoint(index: number, point: Point2D): this- Insert point at indexremovePoint(index: number): this- Remove point at indexupdatePoint(index: number, point: Point2D): this- Update specific pointgetPoints(): Point2D[]- Get copy of all pointsgetPointCount(): number- Get number of pointssetClosed(closed: boolean): this- Set whether shape is closedsetSmooth(smooth: boolean): this- Enable/disable smooth curvesmove_to(point: Point2D): this- Move to absolute positionshift(delta: Point2D): this- Move by relative offsetscale(factor: number): this- Scale uniformlyrotate(angle: number): this- Rotate by angle (radians)
PolygonFromPoints.fromDataPoints(xValues: number[], yValues: number[]): PolygonFromPoints- Create from data arraysPolygonFromPoints.fromFunction(func: (x: number) => number, xMin: number, xMax: number, samples?: number): PolygonFromPoints- Create from functionPolygonFromPoints.regularPolygon(sides: number, radius?: number, center?: Point2D): PolygonFromPoints- Create regular polygonPolygonFromPoints.star(outerRadius?: number, innerRadius?: number, points?: number, center?: Point2D): PolygonFromPoints- Create star shape
Creates 2D coordinate axes with grid, labels, and scaling.
class Axes implements VividObjectconstructor(options: AxesOptions = {})
interface AxesOptions {
xMin?: number
xMax?: number
yMin?: number
yMax?: number
xStep?: number
yStep?: number
axisColor?: Color | string
tickColor?: Color | string
labelColor?: Color | string
gridColor?: Color | string
showGrid?: boolean
showTickMarks?: boolean
showLabels?: boolean
tickSize?: number
labelSize?: number
strokeWidth?: number
gridOpacity?: number
width?: number // Physical width in pixels
height?: number // Physical height in pixels
pixelsPerUnit?: number // Scale factor (default: 80)
maintainAspectRatio?: boolean // Whether to maintain aspect ratio (default: true)
}visible: boolean- Visibility flagtransform: Transform2D- Position, scale, rotation
setRange(xMin: number, xMax: number, yMin: number, yMax: number): this- Set axis rangessetXRange(min: number, max: number): this- Set X axis rangesetYRange(min: number, max: number): this- Set Y axis rangesetStep(xStep: number, yStep?: number): this- Set tick spacingsetDimensions(width: number, height: number): this- Set physical dimensionssetPixelsPerUnit(pixelsPerUnit: number): this- Set scale factorsetSize(pixelsPerUnit: number): this- Alias for setPixelsPerUnitcoordsToPoint(x: number, y: number): Point2D- Convert coordinates to canvas positionpointToCoords(point: Point2D): Point2D- Convert canvas position to coordinatesmove_to(point: Point2D): this- Move to absolute positionshift(delta: Point2D): this- Move by relative offsetscale(factor: number): this- Scale uniformlyrotate(angle: number): this- Rotate by angle (radians)
Displays matrices and tables with customizable styling.
class Matrix implements VividObjectconstructor(data: (string | number)[][], options: MatrixOptions = {})
interface MatrixOptions {
fontSize?: number
color?: Color | string
bracketStyle?: 'square' | 'round' | 'curly' | 'angle' | 'pipe' | 'none'
cellPadding?: number
rowSpacing?: number
colSpacing?: number
showGrid?: boolean
gridColor?: Color | string
}visible: boolean- Visibility flagtransform: Transform2D- Position, scale, rotation
setData(data: (string | number)[][]): this- Replace all datagetData(): (string | number)[][]- Get copy of datasetElement(row: number, col: number, value: string | number): this- Update single cellgetElement(row: number, col: number): string | number | undefined- Get single cellgetDimensions(): { rows: number; cols: number }- Get matrix dimensionsmoveTo(point: Point2D): this- Move to absolute positionshift(delta: Point2D): this- Move by relative offsetscale(factor: number): this- Scale uniformlyrotate(angle: number): this- Rotate by angle (radians)
class Table extends Matrix // Matrix with grid enabled and no bracketsCreates graph visualizations with nodes and edges.
class Graph implements VividObjectconstructor(options: GraphOptions = {})
interface GraphOptions {
nodeRadius?: number
nodeColor?: Color | string
edgeColor?: Color | string
edgeWidth?: number
labelSize?: number
labelColor?: Color | string
showLabels?: boolean
showWeights?: boolean
layout?: 'manual' | 'circle' | 'grid' | 'force'
spacing?: number
}
interface GraphNode {
id: string
label?: string
position?: Point2D
color?: Color | string
size?: number
data?: any
}
interface GraphEdge {
from: string
to: string
label?: string
weight?: number
color?: Color | string
width?: number
directed?: boolean
}visible: boolean- Visibility flagtransform: Transform2D- Position, scale, rotation
addNode(node: GraphNode): this- Add node to graphremoveNode(nodeId: string): this- Remove node and connected edgesaddEdge(edge: GraphEdge): this- Add edge between nodesremoveEdge(from: string, to: string): this- Remove specific edgegetNode(nodeId: string): GraphNode | undefined- Get node by IDgetEdges(): GraphEdge[]- Get all edgessetLayout(layout: string): this- Change layout algorithmmoveTo(point: Point2D): this- Move to absolute positionshift(delta: Point2D): this- Move by relative offsetscale(factor: number): this- Scale uniformlyrotate(angle: number): this- Rotate by angle (radians)
class Tree extends GraphbuildFromData(data: any, nodeId?: string, position?: Point2D, level?: number): this- Build tree from hierarchical data
Creates number lines with markers and labels.
class NumberLine implements VividObjectconstructor(options: NumberLineOptions = {})
interface NumberLineOptions {
xMin?: number
xMax?: number
step?: number
length?: number
color?: Color | string
tickColor?: Color | string
labelColor?: Color | string
showLabels?: boolean
showTicks?: boolean
tickSize?: number
labelSize?: number
strokeWidth?: number
includeArrow?: boolean
unitLength?: number
}visible: boolean- Visibility flagtransform: Transform2D- Position, scale, rotation
pointFromNumber(value: number): Point2D- Convert number to canvas positionnumberFromPoint(point: Point2D): number- Convert canvas position to numberaddNumber(value: number, color?: Color | string): NumberLineMarker- Add marker at valuesetRange(xMin: number, xMax: number): this- Set number rangegetRange(): { min: number; max: number }- Get current rangemoveTo(point: Point2D): this- Move to absolute positionshift(delta: Point2D): this- Move by relative offsetscale(factor: number): this- Scale uniformlyrotate(angle: number): this- Rotate by angle (radians)
Markers that can be placed on number lines.
class NumberLineMarker implements VividObjectconstructor(numberLine: NumberLine, value: number, options: NumberLineMarkerOptions = {})
interface NumberLineMarkerOptions {
color?: Color | string
size?: number
style?: 'dot' | 'arrow' | 'line'
label?: string
}visible: boolean- Visibility flagtransform: Transform2D- Position, scale, rotation
setValue(value: number): this- Change marker positiongetValue(): number- Get current valuemoveTo(point: Point2D): this- Move to absolute positionshift(delta: Point2D): this- Move by relative offsetscale(factor: number): this- Scale uniformlyrotate(angle: number): this- Rotate by angle (radians)
Creates highlighting boxes around other objects.
class HighlightBox implements VividObjectconstructor(target: VividObject, options: HighlightBoxOptions = {})
interface HighlightBoxOptions {
padding?: number
color?: Color | string
strokeWidth?: number
fillOpacity?: number
cornerRadius?: number
dashPattern?: number[]
}visible: boolean- Visibility flagtransform: Transform2D- Position, scale, rotation
setTarget(target: VividObject): this- Change highlighted objectsetPadding(padding: number): this- Adjust padding around targetsetColor(color: Color | string): this- Change highlight colormoveTo(point: Point2D): this- Move to absolute positionshift(delta: Point2D): this- Move by relative offsetscale(factor: number): this- Scale uniformlyrotate(angle: number): this- Rotate by angle (radians)
class UnderlineBox extends HighlightBox // Creates underline instead of boxInvisible object for tracking numeric values with smooth transitions.
class NumericValue implements VividObjectconstructor(startValue: number = 0)visible: boolean- Always false (invisible)transform: Transform2D- Position, scale, rotation
get(): number- Get current valueset(value: number): this- Set value directlytransitionTo(targetValue: number, duration?: number): Promise<void>- Smooth transitionreset(): this- Reset to starting valuesetStart(value: number): this- Update starting valueincrement(amount: number): this- Add to current valuemoveTo(point: Point2D): this- Move to absolute positionshift(delta: Point2D): this- Move by relative offsetscale(factor: number): this- Scale uniformlyrotate(angle: number): this- Rotate by angle (radians)
function generateId(): string // Generates unique object IDsconst ORIGIN = { x: 0, y: 0 }
const UP = { x: 0, y: 1 }
const DOWN = { x: 0, y: -1 }
const LEFT = { x: -1, y: 0 }
const RIGHT = { x: 1, y: 0 }
const PI = Math.PI
const TAU = Math.PI * 2
const DEGREES = Math.PI / 180const ease = {
linear: (t: number) => number
easeInOut: (t: number) => number
easeIn: (t: number) => number
easeOut: (t: number) => number
bounce: (t: number) => number
}function lerp(start: number, end: number, t: number): number
function lerpPoint(start: Point2D, end: Point2D, t: number): Point2DAll VividObject classes support non-uniform scaling through the Scale2D system:
- Independent X/Y scaling: Objects can be stretched horizontally or vertically
- Aspect ratio control: The
maintainAspectRatiooption in Axes controls whether scaling preserves proportions - Coordinate system integration: Objects automatically inherit scaling from their coordinate system
Objects can be associated with coordinate systems (typically Axes) using:
object.setCoordinateSystem(axes)This enables:
- Automatic coordinate transformations
- Consistent scaling across related objects
- Mathematical coordinate space mapping
Each object has its own transform that combines with its coordinate system:
- Object's local transform (
object.transform) - Coordinate system transform (if set)
- Final world transform (computed automatically)
// Create coordinate system
const axes = new Axes({
xMin: -5, xMax: 5,
yMin: -3, yMax: 3,
showGrid: true
})
// Create and position objects
const circle = new Circle({ radius: 1, color: '#ff6b6b' })
.setCoordinateSystem(axes)
.move_to({ x: 2, y: 1 })
const func = new FunctionPlot(x => Math.sin(x), {
xMin: -5, xMax: 5,
color: '#4ecdc4'
}).setCoordinateSystem(axes)// Using the animate property (framework integration required)
circle.animate.move_to({ x: -2, y: 1 })
circle.animate.scale(1.5)// Plot a function with custom styling
const parabola = new FunctionPlot(
x => x * x,
{
xMin: -3,
xMax: 3,
color: '#9b59b6',
strokeWidth: 3
}
).setCoordinateSystem(axes)
// Add LaTeX labels
const label = new MathText('f(x) = x^2', {
fontSize: 20,
color: '#9b59b6'
}).setCoordinateSystem(axes)
.move_to({ x: 1, y: 2 })This comprehensive API documentation covers all the classes, methods, and patterns available in the Vivid animation library.