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/MP4 匯出共用同一條時間軸。

表現層指令

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 另外支援虛線樣式。完整包在 $$…$$ 中的標籤文字會以 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"

defuse 可重複利用一段構造,並在展開時隔離其內部名稱。assert 只會檢查關係並產生警告,不會約束或求解圖形。

在應用程式內查詢完整簽章

本頁依用途整理常用指令。若需要目前安裝版本的精確完整簽章,可以:

  • 在 Eidolang 編輯器中使用 help
  • 讓應用內 Agent 呼叫 list_commands
  • 讓外部 MCP/REST 客戶端呼叫同名工具。

回傳的清單直接來自目前方言的解析器註冊表,因此永遠會與已安裝的版本保持一致。