Skip to content

Latest commit

 

History

History
413 lines (341 loc) · 16.1 KB

File metadata and controls

413 lines (341 loc) · 16.1 KB

FlowGeo 架构与API速查表

架构逻辑图

FlowGeo
├── 核心层 (core/)
│   ├── Scene - 场景管理器,管理所有幻灯片
│   ├── Slide - 幻灯片容器,包含几何对象和HUD
│   └── Config - 配置管理
│
├── 几何层 (geometry/)
│   ├── base.py - 基础类:Point, Vector, Geometry
│   ├── primitives.py - 基本几何:Line, Polygon
│   ├── axes.py - 坐标轴系统
│   ├── calc.py - 几何计算
│   └── solids/ - 立体几何
│       ├── cube.py - 立方体
│       ├── sphere.py - 球体
│       └── pyramid.py - 金字塔
│
├── 渲染层 (rendering/)
│   ├── Renderer - 渲染器抽象基类
│   ├── Style - 样式管理
│   └── backends/
│       └── plotly_backend.py - Plotly渲染后端
│
├── 导出层 (export/)
│   ├── Exporter - 导出器抽象基类
│   ├── HtmlExporter - HTML导出器
│   └── templates/ - HTML模板
│
├── UI层 (ui/)
│   ├── HUD - 平视显示器系统
│   └── animation.py - 动画系统
│
└── 主题层 (themes/)
    ├── cozy_light.py - 温柔亮色主题
    └── manim_dark.py - 深色主题

API速查表

导入方式

# 推荐方式:从顶层包导入
from flowgeo import Scene, Slide, Point, Vector, Line, Polygon, Cube, Sphere, Pyramid
from flowgeo import Renderer, Style, HtmlExporter
from flowgeo import cozy_light, manim_dark

# 或者按模块导入
from flowgeo.core.scene import Scene
from flowgeo.core.slide import Slide
from flowgeo.geometry.base import Point, Vector
from flowgeo.geometry.primitives import Line, Polygon
from flowgeo.geometry.solids.cube import Cube
from flowgeo.geometry.solids.sphere import Sphere
from flowgeo.geometry.solids.pyramid import Pyramid
from flowgeo.rendering import Renderer, Style
from flowgeo.export import HtmlExporter
from flowgeo.themes import cozy_light, manim_dark

# UI和动画系统
from flowgeo.ui.animation import TransitionAnimation

核心类

Scene

Scene(theme=None)                    # 创建场景
    # theme: 可选的主题名称(如'manim_dark'),用于覆盖默认配置。
    #        场景会自动加载和管理配置,推荐通过 flowgeo.yaml 文件进行自定义。

scene.config                         # 访问场景的配置对象 (flowgeo.Config)
scene.camera                         # 访问场景的相机对象 (flowgeo.SmartCamera)

scene.create_slide(title="", inherit=True)  # 创建幻灯片,返回Slide对象
    # title: 幻灯片标题
    # inherit: 是否继承上一页内容(True继承几何对象和相机配置,False创建空白)

scene.get_slide(index)               # 获取指定索引幻灯片,返回Slide或None
scene.get_current_slide()            # 获取当前幻灯片,返回Slide或None
scene.next_slide()                   # 切换到下一页,返回bool成功状态
scene.prev_slide()                   # 切换到上一页,返回bool成功状态
scene.goto_slide(index)              # 跳转到指定页,返回bool成功状态
scene.remove_slide(index)            # 删除指定幻灯片,返回bool成功状态

scene.export(exporter, filename)     # 使用指定导出器导出,返回文件路径
scene.export_html(filename="presentation.html")  # 导出HTML,返回文件路径
scene.to_html()                      # 生成HTML内容字符串,不保存文件
scene.preview_slide(index=None)      # 预览幻灯片渲染数据,返回字典

scene.set_theme(theme_dict)          # 设置主题,返回self支持链式调用
scene.set_metadata(key, value)       # 设置元数据,返回self
scene.get_metadata(key, default)     # 获取元数据
scene.get_slide_count()              # 获取幻灯片总数,返回int
scene.get_total_objects()            # 获取所有幻灯片几何对象总数,返回int

Slide

Slide(title="")                      # 创建幻灯片
    # title: 幻灯片标题

slide.add(obj)                       # 添加几何对象,返回self
    # obj: Point, Line, Polygon, Cube等几何对象
slide.remove(obj)                    # 移除几何对象,返回self
slide.clear_objects()                # 清空所有几何对象,返回self

slide.camera_config                  # 访问或设置幻灯片自己的相机配置字典(不再是SmartCamera对象)

slide.set_transition(transition_type='fade', duration=500, direction='none', easing='ease-in-out')  # 设置转场
    # transition_type: 'fade','slide','none'
    # duration: 动画时长(毫秒)
    # direction: 'left','right','up','down','none'
    # easing: 'ease-in-out','ease-in','ease-out','linear'

slide.set_transition_animation(transition)  # 使用TransitionAnimation对象设置转场
slide.set_slide_animation(animation)        # 使用SlideAnimation对象设置完整动画

动画系统

# TransitionAnimation类 - 转场动画配置
TransitionAnimation(transition_type='fade', duration=500, direction='left')  # 创建转场动画
    # transition_type: 'fade','ppt_cover_slide_left','ppt_cover_slide_right','wipe','cover_fade','ppt_cover_split_horizontal','ppt_cover_split_vertical','none'
    # duration: 动画时长(毫秒)
    # direction: 'left','right','up','down' (用于slide和wipe类型)

# TransitionAnimation静态方法
TransitionAnimation.fade(duration=500) -> TransitionAnimation                    # 淡入淡出转场
TransitionAnimation.slide(duration=600, direction='left') -> TransitionAnimation  # PPT风格推入转场(Cover Slide)
TransitionAnimation.wipe(duration=700, direction='left') -> TransitionAnimation    # 滤镜擦过转场
TransitionAnimation.cover_fade(duration=800) -> TransitionAnimation                # 云雾转场(FlowGeo特色,最稳定)
TransitionAnimation.ppt_cover_split(duration=800, direction='horizontal') -> TransitionAnimation  # 分割转场
TransitionAnimation.none() -> TransitionAnimation                                       # 无转场

# SlideAnimation类 - 幻灯片动画总配置
SlideAnimation()  # 创建幻灯片动画对象
slide_animation.set_transition(transition) -> SlideAnimation  # 设置转场动画
slide_animation.to_dict() -> dict  # 转换为字典配置

# 使用示例
from flowgeo.ui.animation import TransitionAnimation, SlideAnimation

# 方式1: 直接设置转场
slide.set_transition_animation(TransitionAnimation.fade(duration=700))

# 方式2: 使用完整动画配置
anim = SlideAnimation()
anim.set_transition(TransitionAnimation.slide(direction='right'))
slide.set_slide_animation(anim)

slide.set_metadata(key, value)       # 设置幻灯片元数据,返回self
slide.get_metadata(key, default)     # 获取幻灯片元数据
slide.get_object_count()             # 获取几何对象数量,返回int
slide.get_hud_count()                # 获取HUD项目数量,返回int
slide.copy_from(other_slide, copy_objects=True, copy_camera=True, copy_hud=False)  # 复制内容

相机系统 (SmartCamera)

您可以通过 scene.camera 访问和操作相机对象。

scene.camera.look_at(target, distance=None, elevation=None, azimuth=None)  # 智能聚焦
    # target: 几何对象或点
    # distance: 观察距离
    # elevation: 仰角(度)
    # azimuth: 方位角(度)

scene.camera.set_preset(preset, target=None)  # 应用预设视角
    # preset: 'iso','textbook','iso_flat','iso_steep','focus_x','focus_y','front','side','top'

scene.camera.zoom(factor)            # 缩放当前视角,返回self
    # factor: >1缩小(拉远),<1放大(拉近)

scene.camera.zoom_to(target, zoom_level=1.5, duration=1000)  # 飞向目标并缩放
    # target: 目标对象
    # zoom_level: 缩放级别,1.0原始,<1放大,>1缩小
    # duration: 动画时长(毫秒)

scene.camera.use_textbook_perspective()  # 教科书视角快捷方式
scene.camera.set_camera(eye, center=(0,0,0), up=(0,0,1))  # 手动设置相机

几何对象

基础类

Point(x=0, y=0, z=0, label="")       # 创建点
    # x,y,z: 坐标值
    # label: 点标签(如'A','B1')
    # 属性: point.x, point.y, point.z, point.coords
    # 方法: point.to_list() -> [x,y,z]

Vector(x=0, y=0, z=0)                # 创建向量
    # x,y,z: 分量值
    # 属性: vector.x, vector.y, vector.z, vector.coords
    # 方法: vector.to_list() -> [x,y,z]
    # 运算: v1+v2, v1-v2, v*scalar, scalar*v

基本几何

Line(start_point, end_point, style=None)  # 创建线段
    # start_point, end_point: Point对象
    # style: 样式字典或字符串
    # 方法: line.get_points() -> [Point,Point]
    # 方法: line.get_coordinates() -> ((x1,x2),(y1,y2),(z1,z2))
    # 方法: line.length() -> float

Polygon(points, style=None)          # 创建多边形
    # points: Point列表,至少3个点
    # style: 样式字典或字符串
    # 方法: polygon.get_coordinates() -> ([x...],[y...],[z...])
    # 方法: polygon.get_edges() -> [Line,...]
    # 方法: polygon.get_triangles() -> [Polygon,...]

Axes(origin=(0,0,0), length=6.0, show_labels=False, show_ticks=False, theme=None)   # 创建坐标轴
    # origin: 原点坐标
    # length: 轴的可见长度
    # show_labels: 是否显示轴标签(X,Y,Z)
    # show_ticks: 是否显示刻度标记
    # theme: 主题配置字典

立体几何

Cube(length=4.0, origin=(0,0,0))     # 创建立方体
    # length: 边长
    # origin: 原点位置(左下后顶点)
    # 方法: cube.get_point(label) -> Point (标签:'A','B','C','D','A1','B1','C1','D1')
    # 方法: cube.get_edge_lines() -> [Line,...] (12条棱)
    # 方法: cube.get_face_polygons() -> [Polygon,...] (6个面)
    # 方法: cube.get_ratio_point(p1_label,p2_label,ratio,label) -> Point
    # 方法: cube.get_midpoint(p1_label,p2_label,label) -> Point
    # 方法: cube.get_all_points() -> [Point,...]
    # 方法: cube.get_vertices_coordinates() -> ([x...],[y...],[z...])

Sphere(radius=2.0, center=(0,0,0), resolution=20)  # 创建球体
    # radius: 球体半径
    # center: 球心位置
    # resolution: 网格分辨率(经纬线数量)
    # 方法: sphere.get_latitude_lines(num_lines=5) -> [Line,...] (纬线)
    # 方法: sphere.get_longitude_lines(num_lines=8) -> [Line,...] (经线)
    # 方法: sphere.get_equator() -> [Line,...] (赤道)
    # 方法: sphere.get_point_on_surface(theta,phi,label) -> Point (球面坐标点)
    # 方法: sphere.get_center_point(label="O") -> Point (球心)
    # 方法: sphere.get_mesh_data() -> (x,y,z,triangles) (渲染网格数据)

Pyramid(base_points, apex, label_prefix="")  # 创建棱锥
    # base_points: 底面顶点列表(逆时针顺序)
    # apex: 顶点
    # label_prefix: 标签前缀

# Pyramid类方法
pyramid.get_base_polygon() -> Polygon  # 获取底面多边形
pyramid.get_lateral_faces() -> [Polygon,...]  # 获取所有侧面
pyramid.get_edge_lines() -> [Line,...]  # 获取所有棱线
pyramid.get_base_center(label="O") -> Point  # 获取底面中心
pyramid.get_height_line() -> Line  # 获取高线
pyramid.get_height() -> float  # 计算高度
pyramid.get_slant_height(base_point_index=0) -> float  # 计算斜高
pyramid.get_lateral_edge_length(base_point_index=0) -> float  # 计算侧棱长度

# Pyramid类方法 - 创建正棱锥
Pyramid.create_regular(n_sides=4, base_radius=2.0, height=3.0, center=(0,0,0)) -> Pyramid
    # n_sides: 底面边数
    # base_radius: 底面外接圆半径
    # height: 棱锥高度
    # center: 底面中心位置

Pyramid.create_square(side_length=4.0, height=3.0, origin=(0,0,0)) -> Pyramid
    # side_length: 底面边长
    # height: 棱锥高度
    # origin: 底面左下角位置

Pyramid.create_triangular(side_length=4.0, height=3.0, origin=(0,0,0)) -> Pyramid
    # side_length: 底面边长
    # height: 棱锥高度
    # origin: 底面中心位置

HUD系统

slide.hud.text(content, position="top_right", animation="fade_in")  # 添加文字
    # content: 文字内容
    # position: 'top_left','top_right','bottom_left','bottom_right','center'
    # animation: 'fade_in','slide_in','none'

slide.hud.formula(latex, position="top_right", animation="fade_in")  # 添加LaTeX公式
    # latex: LaTeX公式字符串(自动包装为$$...$$)

slide.hud.annotation(content, target_point=None, position="top_right", animation="fade_in")  # 添加标注
    # content: 标注内容
    # target_point: 目标点标签

slide.hud.step_info(step_number, description, position="bottom_left", animation="slide_in")  # 添加步骤信息
    # step_number: 步骤编号
    # description: 步骤描述

slide.hud.clear()                    # 清空所有HUD内容,返回self
slide.hud.remove_by_type(hud_type)   # 按类型移除,返回self
slide.hud.remove_by_position(position)  # 按位置移除,返回self
slide.hud.get_items_by_position(position) -> List[Dict]  # 获取指定位置项目
slide.hud.get_all_items() -> List[Dict]  # 获取所有HUD项目

渲染系统

Renderer(theme)                      # 创建渲染器抽象基类
    # theme: 主题配置字典

renderer.render_slide(slide, theme=None) -> RenderResult  # 渲染幻灯片
    # slide: Slide对象
    # theme: 可选主题配置,覆盖默认主题
    # 返回: RenderResult对象包含traces、layout、metadata

renderer.render_scene(scene) -> List[RenderResult]  # 渲染整个场景
    # scene: Scene对象
    # 返回: RenderResult列表

renderer.get_backend_name() -> str   # 获取后端名称('plotly','threejs'等)

PlotlyRenderer(theme=None)           # Plotly渲染后端
    # theme: 主题配置字典,为None时使用空字典

# RenderResult数据类
RenderResult(traces, layout, metadata=None)  # 渲染结果
    # traces: Plotly traces列表
    # layout: 布局配置字典
    # metadata: 额外元数据字典

样式系统

Style(color='#3498db', opacity=1.0, line_width=2.0, line_dash='solid', 
      line_color=None, border_width=2.0, border_color=None, 
      fill=True, fill_color=None, custom={})  # 创建样式对象

Style.from_dict(data) -> Style       # 从字典创建样式
    # data: 样式配置字典
    # 返回: Style对象

style.to_dict() -> dict              # 转换为字典
style.merge(other_style) -> Style    # 合并样式,返回新Style对象

# 样式预设类
StylePresets.solid_line(color, width) -> Style      # 实线样式
StylePresets.dashed_line(color, width) -> Style     # 虚线样式
StylePresets.filled_polygon(color, opacity, border_color) -> Style  # 填充多边形
StylePresets.transparent_polygon(border_color, border_width) -> Style  # 透明多边形

导出系统

HtmlExporter()                       # HTML导出器
exporter.export(scene, filename) -> str  # 导出文件,返回文件路径
exporter.get_format_name() -> str    # 获取格式名称('html')
exporter.validate_scene(scene) -> bool  # 验证场景是否可导出

主题系统

FlowGeo的配置和主题现在由Scene对象在内部通过Config类进行管理。

当您创建一个Scene实例时,它会自动加载默认配置:

# 这会自动加载 flowgeo.yaml 或默认配置
scene = Scene()

如果您想使用不同的主题,可以在创建Scene时指定主题名称:

# 使用 manim_dark 主题
scene = Scene(theme="manim_dark") 

如果您想更深入地自定义配置,建议直接修改项目根目录下的flowgeo.yaml文件。当Scene初始化时,它会自动检测并加载这个文件。

例如,在flowgeo.yaml中设置默认主题:

themes:
  default: manim_dark

常用位置参数

  • "top_left" - 左上角
  • "top_right" - 右上角
  • "bottom_left" - 左下角
  • "bottom_right" - 右下角
  • "center" - 中央

常用动画参数

  • "fade_in" - 淡入
  • "slide_in" - 滑入
  • "none" - 无动画

转场类型

  • "ppt_cover_slide" - PPT风格推入转场(覆盖层推入并推出)
  • "wipe" - 滤镜擦过转场
  • "cover_fade" - 云雾转场(FlowGeo特色,最稳定无跳变)
  • "ppt_cover_split" - 分割转场(水平/垂直分割)
  • "fade" - 淡入淡出
  • "none" - 无转场

主题名称

  • "cozy_light" - 温柔亮色
  • "manim_dark" - 深色主题