LabeledPolygram¶
限定名称: manim.mobject.geometry.labeled.LabeledPolygram
- class LabeledPolygram(*vertex_groups, label, precision=0.01, label_config=None, box_config=None, frame_config=None, **kwargs)[源码]¶
基类:
Polygram
构建一个多边形,其不可达极点处包含一个标签框。
- 参数:
vertex_groups (Point3DLike_Array) – 传递给
Polygram
构造函数的顶点。precision (float) – PolyLabel 算法使用的精度。
label_config (dict[str, Any] | None) – 包含标签配置的字典。仅当
label
的类型为str
时应用此配置。box_config (dict[str, Any] | None) – 一个包含背景框配置的字典。
frame_config (dict[str, Any] | None) –
包含帧配置的字典。
注意
PolyLabel 算法要求每个顶点组形成一个闭合环。如果输入是开放的,
LabeledPolygram
将尝试闭合它。这可能导致多边形自相交,从而产生意想不到的结果。提示
请确保精度与您的输入比例相对应!例如,如果您的多边形边界框从 0 延伸到 10,000,则 1.0 或 10.0 的精度就足够了。
kwargs (Any)
示例
示例: LabeledPolygramExample ¶
from manim import * class LabeledPolygramExample(Scene): def construct(self): # Define Rings ring1 = [ [-3.8, -2.4, 0], [-2.4, -2.5, 0], [-1.3, -1.6, 0], [-0.2, -1.7, 0], [1.7, -2.5, 0], [2.9, -2.6, 0], [3.5, -1.5, 0], [4.9, -1.4, 0], [4.5, 0.2, 0], [4.7, 1.6, 0], [3.5, 2.4, 0], [1.1, 2.5, 0], [-0.1, 0.9, 0], [-1.2, 0.5, 0], [-1.6, 0.7, 0], [-1.4, 1.9, 0], [-2.6, 2.6, 0], [-4.4, 1.2, 0], [-4.9, -0.8, 0], [-3.8, -2.4, 0] ] ring2 = [ [0.2, -1.2, 0], [0.9, -1.2, 0], [1.4, -2.0, 0], [2.1, -1.6, 0], [2.2, -0.5, 0], [1.4, 0.0, 0], [0.4, -0.2, 0], [0.2, -1.2, 0] ] ring3 = [[-2.7, 1.4, 0], [-2.3, 1.7, 0], [-2.8, 1.9, 0], [-2.7, 1.4, 0]] # Create Polygons (for reference) p1 = Polygon(*ring1, fill_opacity=0.75) p2 = Polygon(*ring2, fill_color=BLACK, fill_opacity=1) p3 = Polygon(*ring3, fill_color=BLACK, fill_opacity=1) # Create Labeled Polygram polygram = LabeledPolygram( *[ring1, ring2, ring3], label=Text('Pole', font='sans-serif'), precision=0.01, ) # Display Circle (for reference) circle = Circle(radius=polygram.radius, color=WHITE).move_to(polygram.pole) self.add(p1, p2, p3) self.add(polygram) self.add(circle)
class LabeledPolygramExample(Scene): def construct(self): # Define Rings ring1 = [ [-3.8, -2.4, 0], [-2.4, -2.5, 0], [-1.3, -1.6, 0], [-0.2, -1.7, 0], [1.7, -2.5, 0], [2.9, -2.6, 0], [3.5, -1.5, 0], [4.9, -1.4, 0], [4.5, 0.2, 0], [4.7, 1.6, 0], [3.5, 2.4, 0], [1.1, 2.5, 0], [-0.1, 0.9, 0], [-1.2, 0.5, 0], [-1.6, 0.7, 0], [-1.4, 1.9, 0], [-2.6, 2.6, 0], [-4.4, 1.2, 0], [-4.9, -0.8, 0], [-3.8, -2.4, 0] ] ring2 = [ [0.2, -1.2, 0], [0.9, -1.2, 0], [1.4, -2.0, 0], [2.1, -1.6, 0], [2.2, -0.5, 0], [1.4, 0.0, 0], [0.4, -0.2, 0], [0.2, -1.2, 0] ] ring3 = [[-2.7, 1.4, 0], [-2.3, 1.7, 0], [-2.8, 1.9, 0], [-2.7, 1.4, 0]] # Create Polygons (for reference) p1 = Polygon(*ring1, fill_opacity=0.75) p2 = Polygon(*ring2, fill_color=BLACK, fill_opacity=1) p3 = Polygon(*ring3, fill_color=BLACK, fill_opacity=1) # Create Labeled Polygram polygram = LabeledPolygram( *[ring1, ring2, ring3], label=Text('Pole', font='sans-serif'), precision=0.01, ) # Display Circle (for reference) circle = Circle(radius=polygram.radius, color=WHITE).move_to(polygram.pole) self.add(p1, p2, p3) self.add(polygram) self.add(circle)
示例: LabeledCountryExample ¶
from manim import * import requests import json class LabeledCountryExample(Scene): def construct(self): # Fetch JSON data and process arcs data = requests.get('https://cdn.jsdelivr.net.cn/npm/us-atlas@3/nation-10m.json').json() arcs, transform = data['arcs'], data['transform'] sarcs = [np.cumsum(arc, axis=0) * transform['scale'] + transform['translate'] for arc in arcs] ssarcs = sorted(sarcs, key=len, reverse=True)[:1] # Compute Bounding Box points = np.concatenate(ssarcs) mins, maxs = np.min(points, axis=0), np.max(points, axis=0) # Build Axes ax = Axes( x_range=[mins[0], maxs[0], maxs[0] - mins[0]], x_length=10, y_range=[mins[1], maxs[1], maxs[1] - mins[1]], y_length=7, tips=False ) # Adjust Coordinates array = [[ax.c2p(*point) for point in sarc] for sarc in ssarcs] # Add Polygram polygram = LabeledPolygram( *array, label=Text('USA', font='sans-serif'), precision=0.01, fill_color=BLUE, stroke_width=0, fill_opacity=0.75 ) # Display Circle (for reference) circle = Circle(radius=polygram.radius, color=WHITE).move_to(polygram.pole) self.add(ax) self.add(polygram) self.add(circle)
import requests import json class LabeledCountryExample(Scene): def construct(self): # Fetch JSON data and process arcs data = requests.get('https://cdn.jsdelivr.net.cn/npm/us-atlas@3/nation-10m.json').json() arcs, transform = data['arcs'], data['transform'] sarcs = [np.cumsum(arc, axis=0) * transform['scale'] + transform['translate'] for arc in arcs] ssarcs = sorted(sarcs, key=len, reverse=True)[:1] # Compute Bounding Box points = np.concatenate(ssarcs) mins, maxs = np.min(points, axis=0), np.max(points, axis=0) # Build Axes ax = Axes( x_range=[mins[0], maxs[0], maxs[0] - mins[0]], x_length=10, y_range=[mins[1], maxs[1], maxs[1] - mins[1]], y_length=7, tips=False ) # Adjust Coordinates array = [[ax.c2p(*point) for point in sarc] for sarc in ssarcs] # Add Polygram polygram = LabeledPolygram( *array, label=Text('USA', font='sans-serif'), precision=0.01, fill_color=BLUE, stroke_width=0, fill_opacity=0.75 ) # Display Circle (for reference) circle = Circle(radius=polygram.radius, color=WHITE).move_to(polygram.pole) self.add(ax) self.add(polygram) self.add(circle)
方法
属性
animate (动画)
用于动画化
self
的任何方法的应用。animation_overrides (动画覆盖)
颜色
depth (深度)
mobject 的深度。
fill_color (填充颜色)
如果存在多种颜色(用于渐变),则返回第一种颜色
height (高度)
mobject 的高度。
n_points_per_curve (每条曲线的点数)
sheen_factor (光泽因子)
stroke_color (描边颜色)
width (宽度)
mobject 的宽度。
- _original__init__(*vertex_groups, label, precision=0.01, label_config=None, box_config=None, frame_config=None, **kwargs)¶
初始化自身。有关准确签名,请参阅 help(type(self))。
- 参数:
vertex_groups (Point3DLike_Array)
precision (float)
label_config (dict[str, Any] | None)
box_config (dict[str, Any] | None)
frame_config (dict[str, Any] | None)
kwargs (Any)
- 返回类型:
无