Skip to content

Eidolang 语言参考

Eidolang 是 Eidograph 图形的文本表示。一个图形就是一份脚本:命令创建对象,表达式建立依赖,样式和动画仍然写在同一份文本中。画布上的拖动、工具操作与属性修改最终都会写回这份脚本。

本页只描述当前语言(Eidolang 0.2),不包含已废弃语法。需要可直接运行的完整脚本时,请前往示例项目

脚本骨架

每个脚本应以空间声明开始:

txt
space plane
version 0.2

# 一行一条命令;# 后是注释
point A -2 0
point B 2 0
segment base A B
point M = midpoint(A, B)
  • space plane 使用 2D 平面方言,space solid 使用 3D 立体方言。
  • version 0.2 可选;它是语言版本,不是 .eido manifest 版本。
  • 名称区分大小写,必须先定义后使用。
  • 角度字面量默认是弧度;角度数值应明确写成 45deg
  • 字符串使用双引号,颜色可使用 #3366cc 形式。

自由度模型

每个几何对象恰好属于一种层级:

层级定义行为
自由坐标或数值直接写为字面量可以拖动或通过属性面板修改
绑定on … at … 或局部坐标绑定到承载对象只能沿承载对象移动
派生使用 = 表达式从其他对象计算不能直接拖动;输入变化时自动更新
txt
point A 0 0                    # 自由
point P on c at 0.25           # 绑定
point M = midpoint(A, P)        # 派生

通用值与表达式

标量表达式支持 + - * / ^、括号、比较和布尔运算。常量包括 pitaue;常用函数包括 sincostansqrtabsminmax 和距离/向量函数。

对象属性可以继续参与表达式,例如 base.lengthc.radiuspoly.arealet 保存任意表达式值,fn 定义可供绘图或曲面使用的函数:

txt
let half = base.length / 2
fn wave(x) = sin(x) * half
plot graph wave domain -6 6

无效值不会让应用崩溃:诊断会指出源代码位置和原因,下游对象会标记为无效或警告状态。

平面(2D)命令

构造基础对象

组件常用形式
point A x ypoint P on path at tpoint M = expr
线性对象segment s A Bline l A Bray r A Bvector v A B
circle c O radius rcircle c O through A
椭圆与圆弧ellipse e F1 F2 through Parc a P1 P2 P3
多边形polygon tri A B C
标准构造midpoint M A Bparallel p A lperpendicular p A l
交点intersections xs pathA pathB

交点结果是 list<point>。优先用稳定选择器,例如 xs.nearest(A)xs.maxYxs.minXxs[0] 的排序可能在运动过程中变化。

路径、函数与区域

txt
plot graph sin domain -6 6
curve loop (cos(t), sin(t)) t from 0 to tau samples 160
polar rose (2*cos(3*a)) a from 0 to tau
equation unit x^2 + y^2 = 1
locus trace P driver u samples 180

region disk = c
region lens = intersection(c1, c2)

segmentlineraycircleellipsearc、函数图形和轨迹都实现 Path 行为,可承载绑定点、参与求交,也可用 subpathpathjoin 组合。

变换与坐标架

txt
point Q = reflect(P, axis)
rotate tri2 tri around O by 30deg
translate c2 c by (2, -1)
scale big tri around O by 2

frame f O X
point L in f 1 0.5

reflectrotatetranslatescale 既有表达式函数,也有命令形式。相似变换会尽量保留对象类型。

立体(3D)命令

txt
space solid
point3 O 0 0 0
point3 T 0 0 3
sphere ball O radius 2
cylinder body O T radius 1
组件常用形式
点与线point3segment3line3ray3vector3
平面与球plane ground A B Csphere s O radius r
实体boxprismpyramidcylindercone
坐标架frame3 f O X Ypoint3 P in f x y z
空间曲线curve3locus3
函数曲面surface waves f domain x0 x1 y0 y1
求交intersections3plane_intersect_linesphere_intersect_sphere
变换reflect3rotate3translate3scale3

3D 中可以把点绑定在线段、直线、射线或球面上。球面点使用两个参数:

txt
point3 P on ball atAngles 45deg 90deg

boxprismpyramidcylindercone 提供 .volume.surfaceArea.centroid 等度量。curve3locus3 是采样显示对象,目前不能作为绑定点的承载路径。

参数、动画与演示阶段

txt
param r 1 range 0.5 4 step 0.1
circle c O radius r
animate r duration 2s mode pingpong

stage result duration 1.2s reveal draw
show c transition draw duration 0.8s
  • param 会在参数面板生成滑块。
  • animate 支持 looppingpongonce
  • stage 创建顺序演示步骤;showhideclear 与 reveal 方式控制出现和移除。
  • 2D、3D 播放和 GIF 导出共享同一时间线。

表现层命令

txt
style base stroke #3366cc width 2 opacity 0.9
label base text "given segment"
textbox note -4 3 width 5 height 2 text "Drag A or B"
group helpers A B base
hide helpers transition fade duration 0.5s

style 可设置颜色、填充、线宽、透明度、点/箭头尺寸;2D 还支持虚线。完整包在 $$…$$ 中的 label 文本会按 LaTeX 排版。textbox 仅用于 2D。

宏与断言

txt
def bisect(A, B) -> (M, b) {
midpoint M A B
perpendicular_bisector b A B
}

use bisect P Q -> M1 b1
assert dist(P, M1) == dist(M1, Q) tolerance 1e-6 note "M1 is midpoint"

def/use 用于复用构造,展开时会隔离内部名称。assert 只检查关系并产生警告,不会约束或求解图形。

在应用内查询完整签名

本页按功能组织常用命令。需要当前方言的精确完整签名时,可以:

  • 在 Eidolang 编辑器中使用 help
  • 让应用内 Agent 调用 list_commands
  • 让外部 MCP/REST 客户端调用同名工具。

这样返回的列表直接来自当前解析器命令注册表,会与已安装版本保持一致。