Eidolang 語言參考
Eidolang 是 Eidograph 圖形的文字表示法。一個圖形就是一份腳本:指令建立物件,運算式建立相依關係,樣式與動畫也都保存在同一份文字中。拖曳、畫布工具與屬性修改,最終都會寫回這份腳本。
本頁只描述目前的語言版本 Eidolang 0.2,不包含任何已淘汰的語法。若需要可直接執行的完整腳本,請前往範例專案。
腳本骨架
每份腳本都應以空間宣告開頭:
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 …,或相對承載物件的局部座標 | 只能沿其承載物件移動 |
| 派生 | 使用基於其他物件的 = 運算式 | 無法拖曳;輸入物件變動時會自動更新 |
point A 0 0 # 自由
point P on c at 0.25 # 綁定
point M = midpoint(A, P) # 派生共用數值與運算式
純量運算式支援 + - * / ^、括號、比較運算與布林運算。常數包括 pi、tau 與 e;常用函式包括 sin、cos、tan、sqrt、abs、min、max,以及距離/向量函式。
物件屬性可以繼續帶入後續運算式,例如 base.length、c.radius、poly.area。let 可儲存任意運算式的值,fn 則定義供繪圖或曲面使用的函式:
let half = base.length / 2
fn wave(x) = sin(x) * half
plot graph wave domain -6 6無效的數值不會導致應用程式崩潰。診斷面板會回報來源位置與原因,下游物件則會被標記為無效或警告狀態。
平面(2D)指令
建構基本物件
| 元件 | 常見形式 |
|---|---|
| 點 | point A x y、point P on path at t、point M = expr |
| 線性物件 | segment s A B、line l A B、ray r A B、vector v A B |
| 圓 | circle c O radius r、circle c O through A |
| 橢圓與圓弧 | ellipse e F1 F2 through P、arc a P1 P2 P3 |
| 多邊形 | polygon tri A B C |
| 標準構造 | midpoint M A B、parallel p A l、perpendicular p A l |
| 交點 | intersections xs pathA pathB |
交點結果的型別是 list<point>。請優先使用穩定的選擇器,例如 xs.nearest(A)、xs.maxY 或 xs.minX;xs[0] 的排序在運動過程中可能會改變。
路徑、函式與區域
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)segment、line、ray、circle、ellipse、arc、函式圖形與軌跡都實作了 Path 行為,可以承載綁定點、彼此求交,也能用 subpath 與 pathjoin 組合。
變換與座標架
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.5reflect、rotate、translate 與 scale 同時提供運算式函式與指令兩種形式。相似變換會盡量保留物件的原始類型。
立體(3D)指令
space solid
point3 O 0 0 0
point3 T 0 0 3
sphere ball O radius 2
cylinder body O T radius 1| 元件 | 常見形式 |
|---|---|
| 點與線 | point3、segment3、line3、ray3、vector3 |
| 平面與球 | plane ground A B C、sphere s O radius r |
| 實體 | box、prism、pyramid、cylinder、cone |
| 座標架 | frame3 f O X Y、point3 P in f x y z |
| 空間曲線 | curve3、locus3 |
| 函式曲面 | surface waves f domain x0 x1 y0 y1 |
| 求交 | intersections3、plane_intersect_line、sphere_intersect_sphere |
| 變換 | reflect3、rotate3、translate3、scale3 |
在 3D 中,點可以綁定在線段、直線、射線或球面上。球面上的點使用兩個參數:
point3 P on ball atAngles 45deg 90degbox、prism、pyramid、cylinder 與 cone 提供 .volume、.surfaceArea 與 .centroid 等量測屬性。curve3 與 locus3 是取樣顯示物件,目前尚不能作為綁定點的承載物件。
參數、動畫與階段演示
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.8sparam會在參數面板建立一個滑桿。animate支援loop、pingpong與once。stage建立循序演示步驟;show、hide、clear與各種 reveal 模式控制物件的出現方式。- 2D 播放、3D 播放與 GIF/MP4 匯出共用同一條時間軸。
表現層指令
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.5sstyle 控制顏色、填色、線寬、不透明度與點/箭頭大小;2D 另外支援虛線樣式。完整包在 $$…$$ 中的標籤文字會以 LaTeX 呈現。textbox 僅限 2D 使用。
巨集與斷言
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 客戶端呼叫同名工具。
回傳的清單直接來自目前方言的解析器註冊表,因此永遠會與已安裝的版本保持一致。
