2D shapes¶
This section presents the main shape classes available in
anim.plane, and how to control their geometry and style.
Available shapes¶
The following classes cover the standard 2D shapes.
API class |
Demo |
|---|---|
|
Anchor point (reference point)¶
Each shape inherits from anim.plane.item and is positioned using a
reference point (anchor point). This anchor is the point controlled by
anim.plane.item.position (or by
anim.plane.item.x and anim.plane.item.y).
The exact geometric meaning of the anchor depends on the shape:
anim.plane.circle: the anchor is the center.anim.plane.ellipse: the anchor is the center.anim.plane.line: the anchor is one endpoint by default, or the center ifcenter=True.anim.plane.rectangle: by default the anchor is the center; withcenter=[False, False]it becomes the bottom-left corner.anim.plane.polygonandanim.plane.path: points are defined relative to the anchor.anim.plane.arrow: the anchor follows the first point of the arrow trajectory.
C.item.rect = anim.plane.rectangle(dimension=[1.2, 0.6], center=[False, False])
C.item.rect.position = [0.0, 0.0] # bottom-left corner at origin
Rotation and center of rotation¶
Rotations are controlled by anim.plane.item.orientation (in
radians), or by calling anim.plane.item.rotate() for relative updates.
The pivot point is controlled by anim.plane.item.center_of_rotation:
for most shapes, default is
[0, 0]in local item coordinatesfor
anim.plane.circle, the natural center rotation is obtained withcenter_of_rotation=[0, 0]for polygons/paths,
[0, 0]means rotating around the anchor point
import numpy as np
C.item.rect = anim.plane.rectangle(dimension=[1.4, 0.5], position=[0.5, -0.2])
# Absolute orientation (30 degrees)
C.item.rect.orientation = np.pi / 6
# Relative rotation (+15 degrees)
C.item.rect.rotate(np.pi / 12)
# Change pivot to the rectangle corner in local coordinates
C.item.rect.center_of_rotation = [0.7, 0.25]
C.item.rect.orientation = np.pi / 3
Geometry control by shape¶
Each shape exposes specific geometry attributes:
anim.plane.line:Lx,Lyordimension=[Lx, Ly]define the segment vector.anim.plane.circle:radiusdefines size.anim.plane.ellipse:LxandLy(ordimension) define width and height.anim.plane.rectangle:LxandLy(ordimension), pluscenterfor anchor behavior.anim.plane.polygon:pointsdefines vertices relative to the anchor.anim.plane.path:pointsdefines a polyline relative to the anchor.anim.plane.arrow:pointsdefines the trajectory; dedicated options control head and text.
Style: fill and stroke¶
Shape style is controlled by four attributes settable directly on any shape instance, either at construction time or at runtime.
Attribute |
Description |
|---|---|
|
Fill color (string, hex, or |
|
Contour color. Set to |
|
Contour thickness in scene units (default |
|
Contour pattern: |
C.item.ell = anim.plane.ellipse(dimension=[1.2, 0.5], position=[0.0, 0.0])
# Fill only
C.item.ell.color = '#4aa3ff'
# Fill + contour
C.item.ell.color = '#4aa3ff'
C.item.ell.stroke = 'white'
C.item.ell.thickness = 0.01
# Contour only (no fill)
C.item.ell.color = None
C.item.ell.stroke = 'white'
C.item.ell.thickness = 0.01
C.item.ell.linestyle = '--'
For anim.plane.line and anim.plane.path, there is no
fill — only stroke, thickness, and linestyle apply.