polygon¶
- class janim.items.geometry.polygon.Polygon(*args, **kwargs)¶
Bases:
GeometryShapePolygon
- Parameters:
verts – A sequence of vertices connected in order to form a polygon
close_path – Whether to close the path by connecting the last vertex to the first; default is
True(closed)
- reshape(verts: VectArray | None = None, *, close_path: bool | None = None) Self¶
Similar to passing parameters to
__init__, reset the shape of the geometry itemSome values can be omitted to reuse previous ones; for detailed usage, refer to the Reshape Geometry tutorial
- get_vertices() list[ndarray]¶
- round_corners(radius: float | None = None) Self¶
- class janim.items.geometry.polygon.Polyline(*args, **kwargs)¶
Bases:
PolygonPolyline
- Parameters:
verts – A sequence of polyline vertices connected in order
close_path – Whether to close the path; default is not closed
- class janim.items.geometry.polygon.RegularPolygon(*args, **kwargs)¶
Bases:
MarkedItem,PolygonRegular polygon
- Parameters:
n – Number of sides
radius – Circumradius
start_angle – Starting angle; when
None, it is set automatically based on the number of sides
Can get the center of the polygon via
.mark.get()- reshape(n: int | None = None, *, radius: float | None = None, start_angle: float | None = None) Self¶
Similar to passing parameters to
__init__, reset the shape of the geometry itemSome values can be omitted to reuse previous ones; for detailed usage, refer to the Reshape Geometry tutorial
- class janim.items.geometry.polygon.Triangle(*args, **kwargs)¶
Bases:
RegularPolygonEquilateral triangle
- Parameters:
**kwargs – Other parameters, see also
RegularPolygon
- class janim.items.geometry.polygon.Rect(*args, **kwargs)¶
Bases:
PolygonRectangle
Supports two construction forms:
Rect(width, height)orRect(corner1, corner2)- Param:
You can pass width and height
(width, height), or a pair of diagonal corners(corner1, corner2)- Parameters:
kwargs – Other parameters passed to the parent class
- reshape(width: float | None = None, height: float | None = None, /) Self¶
- reshape(corner1: Vect | None = None, corner2: Vect | None = None, /) Self
Similar to passing parameters to
__init__, reset the shape of the geometry itemSome values can be omitted to reuse previous ones; for detailed usage, refer to the Reshape Geometry tutorial
- preset_highlight_stroke = {'color': '#FFFF00', 'fill_alpha': 0, 'stroke_alpha': 1}¶
Highlight stroke preset (yellow stroke), e.g.:
Rect(p1, p2, **Rect.preset_highlight_stroke)
- preset_highlight_fill = {'color': '#FFFF00', 'fill_alpha': 0.5, 'stroke_alpha': 0}¶
Highlight fill preset (semi-transparent yellow fill), e.g.:
SurroundingRect(item, depth=1, **Rect.preset_highlight_fill)
- preset_shadow = {'color': '#000000', 'fill_alpha': 0.5, 'stroke_alpha': 0}¶
Shadow preset (semi-transparent black fill), e.g.:
SurroundingRect(item, depth=1, **Rect.preset_shadow)
- class janim.items.geometry.polygon.Square(*args, **kwargs)¶
Bases:
RectSquare
- Parameters:
side_length – Side length of the square
- reshape(side_length: float) Self¶
Similar to passing parameters to
__init__, reset the shape of the geometry itemSome values can be omitted to reuse previous ones; for detailed usage, refer to the Reshape Geometry tutorial
- class janim.items.geometry.polygon.RoundedRect(*args, **kwargs)¶
Bases:
RectRounded rectangle
- Parameters:
前两个参数 – You can pass width and height
(width, height), or a pair of diagonal corners(corner1, corner2)corner_radius – Corner radius
kwargs – Other parameters passed to the parent class
- reshape(width: float | None = None, height: float | None = None, /, corner_radius: float | None = None) Self¶
- reshape(corner1: Vect | None = None, corner2: Vect | None = None, /, corner_radius: float | None = None) Self
Similar to passing parameters to
__init__, reset the shape of the geometry itemSome values can be omitted to reuse previous ones; for detailed usage, refer to the Reshape Geometry tutorial
- class janim.items.geometry.polygon.Star(*args, **kwargs)¶
Bases:
MarkedItem,PolygonStar
- Parameters:
n – Number of vertices, default is 5
outer_radius – Outer radius
inner_radius – Inner radius; when
None, it is computed fromdensitydensity – Density. Larger values produce a smaller inner radius. Valid range is
[1, n/2]; it can be understood as “how many vertices to skip between each connected segment” when drawing in one stroke. By default, one vertex is skipped each time to form a starstart_angle – Starting angle
- property start_angle: float¶
- reshape(n: int | None = None, *, outer_radius: float | None = None, inner_radius: float | None = None, density: float | None = None, start_angle: float | None = None) Self¶
Similar to passing parameters to
__init__, reset the shape of the geometry itemSome values can be omitted to reuse previous ones; for detailed usage, refer to the Reshape Geometry tutorial
- static inner_radius_of_density(density: float, outer_radius: float = 1, n: int = 5) None¶
Compute the
inner_radiuscorresponding toouter_radiusunder the specifieddensity