Skip to main content

Class: Mobject2D

Defined in: mobjects/point/Mobject2D.ts:74

Mobject2D - 2D point distribution in a rectangular plane

Points are distributed within a rectangular region. Supports grid distribution (evenly spaced rows and columns) or random distribution within the bounds.

Example

// Create a 10x10 grid of points
const grid = new Mobject2D({
center: [0, 0, 0],
width: 4,
height: 4,
numPointsX: 10,
numPointsY: 10,
distribution: 'grid',
});

// Create random points in a region
const randomCloud = new Mobject2D({
center: [0, 0, 0],
width: 3,
height: 2,
numPointsX: 100, // total points for random
distribution: 'random',
color: '#ff00ff',
});

// Use density instead of explicit counts
const densePlane = new Mobject2D({
width: 2,
height: 2,
density: 5, // 5 points per unit (grid) or 5 per unit area (random)
distribution: 'grid',
});

Extends

Constructors

Constructor

new Mobject2D(options): Mobject2D

Defined in: mobjects/point/Mobject2D.ts:83

Parameters

options

Mobject2DOptions = {}

Returns

Mobject2D

Overrides

PMobject.constructor

Properties

__savedMobjectState

__savedMobjectState: unknown = null

Defined in: core/Mobject.ts:95

JSON-serializable saved state (used by restoreState()).

Inherited from

PMobject.__savedMobjectState


_center2D

protected _center2D: Vector3Tuple

Defined in: mobjects/point/Mobject2D.ts:75


_color

protected _color: string = '#ffffff'

Defined in: core/Mobject.ts:70

Inherited from

PMobject._color


_density?

protected optional _density: number

Defined in: mobjects/point/Mobject2D.ts:80


_dirty

_dirty: boolean = true

Defined in: core/Mobject.ts:88

Inherited from

PMobject._dirty


_disableChildZLayering

protected _disableChildZLayering: boolean = false

Defined in: core/Mobject.ts:85

When true, children skip the 2D z-layering offset in _syncToThree.

Inherited from

PMobject._disableChildZLayering


_distribution

protected _distribution: Distribution2D

Defined in: mobjects/point/Mobject2D.ts:81


_geometry

protected _geometry: BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap> = null

Defined in: mobjects/point/PMobject.ts:65

THREE.js geometry for points

Inherited from

PMobject._geometry


_height

protected _height: number

Defined in: mobjects/point/Mobject2D.ts:77


_material

protected _material: PointsMaterial = null

Defined in: mobjects/point/PMobject.ts:68

THREE.js material for points

Inherited from

PMobject._material


_numPointsX

protected _numPointsX: number

Defined in: mobjects/point/Mobject2D.ts:78


_numPointsY

protected _numPointsY: number

Defined in: mobjects/point/Mobject2D.ts:79


_opacity

protected _opacity: number = 1

Defined in: core/Mobject.ts:81

Inherited from

PMobject._opacity


_points

protected _points: PointData[] = []

Defined in: mobjects/point/PMobject.ts:59

Internal point data storage

Inherited from

PMobject._points


_pointSize

protected _pointSize: number = 10

Defined in: mobjects/point/PMobject.ts:62

Point size in pixels

Inherited from

PMobject._pointSize


_style

protected _style: MobjectStyle

Defined in: core/Mobject.ts:86

Inherited from

PMobject._style


_threeObject

_threeObject: Object3D<Object3DEventMap> = null

Defined in: core/Mobject.ts:87

Inherited from

PMobject._threeObject


_width

protected _width: number

Defined in: mobjects/point/Mobject2D.ts:76


children

children: Mobject[] = []

Defined in: core/Mobject.ts:65

Inherited from

PMobject.children


createdAtBeginning

createdAtBeginning: boolean = false

Defined in: core/Mobject.ts:69

Inherited from

PMobject.createdAtBeginning


fillOpacity

fillOpacity: number = 0

Defined in: core/Mobject.ts:83

Inherited from

PMobject.fillOpacity


id

readonly id: string

Defined in: core/Mobject.ts:63

Inherited from

PMobject.id


parent

parent: Mobject = null

Defined in: core/Mobject.ts:64

Inherited from

PMobject.parent


position

position: Vector3

Defined in: core/Mobject.ts:66

Inherited from

PMobject.position


rotation

rotation: Euler

Defined in: core/Mobject.ts:67

Inherited from

PMobject.rotation


savedState

savedState: Mobject = null

Defined in: core/Mobject.ts:91

Saved mobject copy (used by Restore animation). Set by saveState().

Inherited from

PMobject.savedState


scaleVector

scaleVector: Vector3

Defined in: core/Mobject.ts:68

Inherited from

PMobject.scaleVector


strokeWidth

strokeWidth: number = 4

Defined in: core/Mobject.ts:82

Inherited from

PMobject.strokeWidth


targetCopy

targetCopy: Mobject = null

Defined in: core/Mobject.ts:93

Target copy used by generateTarget() / MoveToTarget animation.

Inherited from

PMobject.targetCopy

Accessors

animate

Get Signature

get animate(): any

Defined in: core/Mobject.ts:497

Returns an AnimateProxy that records method calls. Pass the proxy to scene.play() to animate from the current state to the state after all recorded calls are applied.

Example
scene.play(circle.animate.shift([2, 0, 0]));
scene.play(circle.animate.setColor('#ff0000').scale(2));
Returns

any

Inherited from

PMobject.animate


color

Get Signature

get color(): string

Defined in: core/Mobject.ts:71

Returns

string

Set Signature

set color(value): void

Defined in: core/Mobject.ts:74

Parameters
value

string

Returns

void

Inherited from

PMobject.color


fillColor

Get Signature

get fillColor(): string

Defined in: core/Mobject.ts:184

Returns

string

Set Signature

set fillColor(color): void

Defined in: core/Mobject.ts:188

Parameters
color

string

Returns

void

Inherited from

PMobject.fillColor


isDirty

Get Signature

get isDirty(): boolean

Defined in: core/Mobject.ts:551

Returns

boolean

Inherited from

PMobject.isDirty


numPoints

Get Signature

get numPoints(): number

Defined in: mobjects/point/PMobject.ts:150

Get the number of points

Returns

number

Inherited from

PMobject.numPoints


opacity

Get Signature

get opacity(): number

Defined in: core/Mobject.ts:114

Returns

number

Set Signature

set opacity(value): void

Defined in: core/Mobject.ts:118

Parameters
value

number

Returns

void

Inherited from

PMobject.opacity


strokeColor

Get Signature

get strokeColor(): string

Defined in: core/Mobject.ts:195

Returns

string

Set Signature

set strokeColor(color): void

Defined in: core/Mobject.ts:199

Parameters
color

string

Returns

void

Inherited from

PMobject.strokeColor


style

Get Signature

get style(): MobjectStyle

Defined in: core/Mobject.ts:122

Returns

MobjectStyle

Inherited from

PMobject.style


submobjects

Get Signature

get submobjects(): Mobject[]

Defined in: core/Mobject.ts:136

Returns

Mobject[]

Inherited from

PMobject.submobjects

Methods

_createCopy()

protected _createCopy(): Mobject2D

Defined in: mobjects/point/Mobject2D.ts:341

Create a copy of this Mobject2D

Returns

Mobject2D

Overrides

PMobject._createCopy


_createThreeObject()

protected _createThreeObject(): Object3D

Defined in: mobjects/point/PMobject.ts:242

Create the Three.js backing object

Returns

Object3D

Inherited from

PMobject._createThreeObject


_generatePoints()

protected _generatePoints(): void

Defined in: mobjects/point/Mobject2D.ts:147

Generate points in the rectangular region

Returns

void


_getActualPointCounts()

protected _getActualPointCounts(): object

Defined in: mobjects/point/Mobject2D.ts:124

Get actual point counts based on density or config

Returns

object

total

total: number

x

x: number

y

y: number


_getBoundingBox()

_getBoundingBox(): object

Defined in: core/Mobject.ts:449

Returns

object

depth

depth: number

height

height: number

width

width: number

Deprecated

Use getBoundingBox() instead.

Inherited from

PMobject._getBoundingBox


_getEdgeInDirection()

_getEdgeInDirection(direction): Vector3Tuple

Defined in: core/Mobject.ts:442

Parameters

direction

Vector3Tuple

Returns

Vector3Tuple

Inherited from

PMobject._getEdgeInDirection


_markDirty()

_markDirty(): void

Defined in: core/Mobject.ts:541

Returns

void

Inherited from

PMobject._markDirty


_markDirtyUpward()

_markDirtyUpward(): void

Defined in: core/Mobject.ts:545

Returns

void

Inherited from

PMobject._markDirtyUpward


_syncMaterialToThree()

protected _syncMaterialToThree(): void

Defined in: mobjects/point/PMobject.ts:297

Sync material properties to Three.js

Returns

void

Inherited from

PMobject._syncMaterialToThree


_syncToThree()

_syncToThree(): void

Defined in: core/Mobject.ts:519

Returns

void

Inherited from

PMobject._syncToThree


_updateGeometry()

protected _updateGeometry(): void

Defined in: mobjects/point/PMobject.ts:253

Update or create the geometry from points

Returns

void

Inherited from

PMobject._updateGeometry


_updateMaterial()

protected _updateMaterial(): void

Defined in: mobjects/point/PMobject.ts:278

Update or create the material

Returns

void

Inherited from

PMobject._updateMaterial


add()

add(...mobjects): this

Defined in: core/Mobject.ts:329

Parameters

mobjects

...Mobject[]

Returns

this

Inherited from

PMobject.add


addPoint()

addPoint(point): this

Defined in: mobjects/point/PMobject.ts:90

Add a single point to the mobject

Parameters

point

PointData

Point data with position and optional color/opacity

Returns

this

this for chaining

Inherited from

PMobject.addPoint


addPoints()

addPoints(points): this

Defined in: mobjects/point/PMobject.ts:105

Add multiple points to the mobject

Parameters

points

PointData[]

Array of point data

Returns

this

this for chaining

Inherited from

PMobject.addPoints


addUpdater()

addUpdater(updater, callOnAdd): this

Defined in: core/Mobject.ts:589

Parameters

updater

UpdaterFunction

callOnAdd

boolean = false

Returns

this

Inherited from

PMobject.addUpdater


alignTo()

alignTo(target, direction): this

Defined in: core/Mobject.ts:427

Parameters

target

Mobject | Vector3Tuple

direction

Vector3Tuple

Returns

this

Inherited from

PMobject.alignTo


applyFunction()

applyFunction(fn, options?): this

Defined in: core/Mobject.ts:619

Parameters

fn

(point) => number[]

options?
aboutEdge?

Vector3Tuple

aboutPoint?

Vector3Tuple

Returns

this

Inherited from

PMobject.applyFunction


applyMatrix()

applyMatrix(matrix, options?): this

Defined in: core/Mobject.ts:627

Parameters

matrix

number[][]

options?
aboutEdge?

Vector3Tuple

aboutPoint?

Vector3Tuple

Returns

this

Inherited from

PMobject.applyMatrix


applyToFamily()

applyToFamily(func): this

Defined in: core/Mobject.ts:577

Parameters

func

(mobject) => void

Returns

this

Inherited from

PMobject.applyToFamily


become()

become(other): this

Defined in: core/Mobject.ts:376

Parameters

other

Mobject

Returns

this

Inherited from

PMobject.become


center()

center(): this

Defined in: core/Mobject.ts:479

Returns

this

Inherited from

PMobject.center


clearPoints()

clearPoints(): this

Defined in: mobjects/point/PMobject.ts:129

Clear all points

Returns

this

this for chaining

Inherited from

PMobject.clearPoints


clearUpdaters()

clearUpdaters(): this

Defined in: core/Mobject.ts:601

Returns

this

Inherited from

PMobject.clearUpdaters


copy()

copy(): Mobject

Defined in: core/Mobject.ts:358

Returns

Mobject

Inherited from

PMobject.copy


dispose()

dispose(): void

Defined in: mobjects/point/PMobject.ts:322

Clean up Three.js resources

Returns

void

Inherited from

PMobject.dispose


flip()

flip(axis, options?): this

Defined in: core/Mobject.ts:257

Parameters

axis

Vector3Tuple = ...

options?
aboutEdge?

Vector3Tuple

aboutPoint?

Vector3Tuple

Returns

this

Inherited from

PMobject.flip


generateTarget()

generateTarget(): Mobject

Defined in: core/Mobject.ts:642

Returns

Mobject

Inherited from

PMobject.generateTarget


getArea()

getArea(): number

Defined in: mobjects/point/Mobject2D.ts:117

Get the area of the region

Returns

number


getBottom()

getBottom(): Vector3Tuple

Defined in: core/Mobject.ts:458

Returns

Vector3Tuple

Inherited from

PMobject.getBottom


getBoundingBox()

getBoundingBox(): object

Defined in: core/Mobject.ts:445

Returns

object

depth

depth: number

height

height: number

width

width: number

Inherited from

PMobject.getBoundingBox


getBounds()

getBounds(): object

Defined in: core/Mobject.ts:392

Returns

object

max

max: object

max.x

x: number

max.y

y: number

max.z

z: number

min

min: object

min.x

x: number

min.y

y: number

min.z

z: number

Inherited from

PMobject.getBounds


getCenter()

getCenter(): Vector3Tuple

Defined in: mobjects/point/Mobject2D.ts:285

Get the center of the region

Returns

Vector3Tuple

Overrides

PMobject.getCenter


getDisplayMeshes()

getDisplayMeshes(): Mesh<BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>, Material<MaterialEventMap> | Material<MaterialEventMap>[], Object3DEventMap>[]

Defined in: core/Mobject.ts:569

Returns

Mesh<BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>, Material<MaterialEventMap> | Material<MaterialEventMap>[], Object3DEventMap>[]

Inherited from

PMobject.getDisplayMeshes


getDisplayMeshLength()

getDisplayMeshLength(): number

Defined in: core/Mobject.ts:565

Number of visible display meshes this mobject contributes when rendered. Used for Transform eligibility checks without forcing Three.js object creation.

Returns

number

Inherited from

PMobject.getDisplayMeshLength


getDistribution()

getDistribution(): Distribution2D

Defined in: mobjects/point/Mobject2D.ts:278

Get the distribution pattern

Returns

Distribution2D


getEdge()

getEdge(direction): Vector3Tuple

Defined in: core/Mobject.ts:452

Parameters

direction

Vector3Tuple

Returns

Vector3Tuple

Inherited from

PMobject.getEdge


getFamily()

getFamily(): Mobject[]

Defined in: core/Mobject.ts:583

Returns

Mobject[]

Inherited from

PMobject.getFamily


getHeight()

getHeight(): number

Defined in: mobjects/point/Mobject2D.ts:200

Get the height of the region

Returns

number


getLeft()

getLeft(): Vector3Tuple

Defined in: core/Mobject.ts:461

Returns

Vector3Tuple

Inherited from

PMobject.getLeft


getPoints()

getPoints(): PointData[]

Defined in: mobjects/point/PMobject.ts:139

Get all points

Returns

PointData[]

Copy of the points array

Inherited from

PMobject.getPoints


getPointSize()

getPointSize(): number

Defined in: mobjects/point/PMobject.ts:168

Get the point size

Returns

number

Inherited from

PMobject.getPointSize


getRight()

getRight(): Vector3Tuple

Defined in: core/Mobject.ts:464

Returns

Vector3Tuple

Inherited from

PMobject.getRight


getThreeObject()

getThreeObject(): Object3D

Defined in: core/Mobject.ts:555

Returns

Object3D

Inherited from

PMobject.getThreeObject


getTop()

getTop(): Vector3Tuple

Defined in: core/Mobject.ts:455

Returns

Vector3Tuple

Inherited from

PMobject.getTop


getUpdaters()

getUpdaters(): UpdaterFunction[]

Defined in: core/Mobject.ts:608

Returns

UpdaterFunction[]

Inherited from

PMobject.getUpdaters


getWidth()

getWidth(): number

Defined in: mobjects/point/Mobject2D.ts:193

Get the width of the region

Returns

number


hasUpdaters()

hasUpdaters(): boolean

Defined in: core/Mobject.ts:605

Returns

boolean

Inherited from

PMobject.hasUpdaters


moveTo()

moveTo(point): this

Defined in: mobjects/point/Mobject2D.ts:293

Move the region to center at a new position

Parameters

point

Vector3Tuple

Target center position [x, y, z]

Returns

this

Overrides

PMobject.moveTo


moveToAligned()

moveToAligned(target, alignedEdge?): this

Defined in: core/Mobject.ts:437

Parameters

target

Mobject | Vector3Tuple

alignedEdge?

Vector3Tuple

Returns

this

Inherited from

PMobject.moveToAligned


nextTo()

nextTo(target, direction, buff): this

Defined in: core/Mobject.ts:410

Parameters

target

Mobject | Vector3Tuple

direction

Vector3Tuple = RIGHT

buff

number = 0.25

Returns

this

Inherited from

PMobject.nextTo


prepareForNonlinearTransform()

prepareForNonlinearTransform(numPieces): this

Defined in: core/Mobject.ts:635

Parameters

numPieces

number = 50

Returns

this

Inherited from

PMobject.prepareForNonlinearTransform


regenerate()

regenerate(): this

Defined in: mobjects/point/Mobject2D.ts:333

Regenerate the points (useful for random distribution refresh)

Returns

this

this for chaining


remove()

remove(...mobjects): this

Defined in: core/Mobject.ts:342

Parameters

mobjects

...Mobject[]

Returns

this

Inherited from

PMobject.remove


removePoint()

removePoint(index): this

Defined in: mobjects/point/PMobject.ts:117

Remove a point by index

Parameters

index

number

Index of point to remove

Returns

this

this for chaining

Inherited from

PMobject.removePoint


removeUpdater()

removeUpdater(updater): this

Defined in: core/Mobject.ts:595

Parameters

updater

UpdaterFunction

Returns

this

Inherited from

PMobject.removeUpdater


replace()

replace(target, stretch): this

Defined in: core/Mobject.ts:381

Parameters

target

Mobject

stretch

boolean = false

Returns

this

Inherited from

PMobject.replace


restoreState()

restoreState(): boolean

Defined in: core/Mobject.ts:652

Returns

boolean

Inherited from

PMobject.restoreState


rotate()

rotate(angle, axisOrOptions?): this

Defined in: core/Mobject.ts:237

Rotate the mobject by angle around an axis. Accepts aboutPoint or aboutEdge to specify the rotation center.

Parameters

angle

number

axisOrOptions?

Vector3Tuple | { aboutEdge?: Vector3Tuple; aboutPoint?: Vector3Tuple; axis?: Vector3Tuple; }

Returns

this

Inherited from

PMobject.rotate


rotateAboutOrigin()

rotateAboutOrigin(angle, axis): this

Defined in: core/Mobject.ts:253

Parameters

angle

number

axis

Vector3Tuple = ...

Returns

this

Inherited from

PMobject.rotateAboutOrigin


saveState()

saveState(): this

Defined in: core/Mobject.ts:647

Returns

this

Inherited from

PMobject.saveState


scale()

scale(factor, options?): this

Defined in: core/Mobject.ts:283

Parameters

factor

number | Vector3Tuple

options?
aboutEdge?

Vector3Tuple

aboutPoint?

Vector3Tuple

Returns

this

Inherited from

PMobject.scale


setColor()

setColor(color): this

Defined in: mobjects/point/PMobject.ts:177

Set the color of all points

Parameters

color

string

CSS color string

Returns

this

this for chaining

Inherited from

PMobject.setColor


setDensity()

setDensity(density): this

Defined in: mobjects/point/Mobject2D.ts:258

Set the density and regenerate (overrides point counts)

Parameters

density

number

Points per unit length (grid) or per unit area (random)

Returns

this

this for chaining


setDimensions()

setDimensions(width, height): this

Defined in: mobjects/point/Mobject2D.ts:232

Set both dimensions and regenerate

Parameters

width

number

New width

height

number

New height

Returns

this

this for chaining


setDistribution()

setDistribution(distribution): this

Defined in: mobjects/point/Mobject2D.ts:269

Set the distribution pattern and regenerate

Parameters

distribution

Distribution2D

'grid' or 'random'

Returns

this

this for chaining


setFill()

setFill(color?, opacity?): this

Defined in: core/Mobject.ts:178

Parameters

color?

string

opacity?

number

Returns

this

Inherited from

PMobject.setFill


setFillOpacity()

setFillOpacity(opacity): this

Defined in: core/Mobject.ts:168

Parameters

opacity

number

Returns

this

Inherited from

PMobject.setFillOpacity


setHeight()

setHeight(height): this

Defined in: mobjects/point/Mobject2D.ts:220

Set the height and regenerate

Parameters

height

number

New height

Returns

this

this for chaining


setPointCounts()

setPointCounts(xCount, yCount): this

Defined in: mobjects/point/Mobject2D.ts:245

Set point counts for grid distribution (clears density)

Parameters

xCount

number

Points along width

yCount

number

Points along height

Returns

this

this for chaining


setPointSize()

setPointSize(size): this

Defined in: mobjects/point/PMobject.ts:159

Set the point size

Parameters

size

number

Size in pixels

Returns

this

this for chaining

Inherited from

PMobject.setPointSize


setStrokeOpacity()

setStrokeOpacity(opacity): this

Defined in: mobjects/point/PMobject.ts:190

Set the opacity of all points

Parameters

opacity

number

Opacity value (0-1)

Returns

this

this for chaining

Inherited from

PMobject.setStrokeOpacity


setStrokeWidth()

setStrokeWidth(width): this

Defined in: core/Mobject.ts:158

Parameters

width

number

Returns

this

Inherited from

PMobject.setStrokeWidth


setStyle()

setStyle(style): this

Defined in: core/Mobject.ts:126

Parameters

style

Partial<MobjectStyle>

Returns

this

Inherited from

PMobject.setStyle


setWidth()

setWidth(width): this

Defined in: mobjects/point/Mobject2D.ts:209

Set the width and regenerate

Parameters

width

number

New width

Returns

this

this for chaining


setX()

setX(x): this

Defined in: core/Mobject.ts:467

Parameters

x

number

Returns

this

Inherited from

PMobject.setX


setY()

setY(y): this

Defined in: core/Mobject.ts:471

Parameters

y

number

Returns

this

Inherited from

PMobject.setY


setZ()

setZ(z): this

Defined in: core/Mobject.ts:475

Parameters

z

number

Returns

this

Inherited from

PMobject.setZ


shift()

shift(delta): this

Defined in: mobjects/point/Mobject2D.ts:309

Shift the region by a delta

Parameters

delta

Vector3Tuple

Translation vector [x, y, z]

Returns

this

this for chaining

Overrides

PMobject.shift


stretch()

stretch(factor, dim, options?): this

Defined in: core/Mobject.ts:310

Parameters

factor

number

dim

number

options?
aboutEdge?

Vector3Tuple

aboutPoint?

Vector3Tuple

Returns

this

Inherited from

PMobject.stretch


toCorner()

toCorner(direction, buff, frameDimensions?): this

Defined in: core/Mobject.ts:509

Parameters

direction

Vector3Tuple = ...

buff

number = 0.5

frameDimensions?

[number, number]

Returns

this

Inherited from

PMobject.toCorner


toEdge()

toEdge(direction, buff, frameDimensions?): this

Defined in: core/Mobject.ts:504

Parameters

direction

Vector3Tuple

buff

number = 0.5

frameDimensions?

[number, number]

Returns

this

Inherited from

PMobject.toEdge


update()

update(dt): void

Defined in: core/Mobject.ts:612

Parameters

dt

number

Returns

void

Inherited from

PMobject.update