第一个项目
entelechy new <目录> 会写出一个能直接运行的目录:一个 Kernel、放置它的场景、检查画面的回放测试,以及一份说明“先改什么”的 README。
entelechy new helloplay it: entelechy player hello/scene.esnrun it: entelechy run hello/scene.esn --window 640x400 --out frame.pngtest it: entelechy replay hello/tests/hello.replay--kind picture|sound|game 选择起点(默认是图片)。
hello/├── README.md├── scene.esn 场景:放置节点、声明参数和输出├── kernels/│ └── hello.ent Kernel:每个像素的计算└── tests/ └── hello.replay 回放测试:在某一帧检查某个像素的颜色scene.esn:一个节点,把 Kernel 铺满整个窗口。
// One node: the Kernel over a window's worth of pixels.use "kernels/";
param rate: Float = 0.35;
node picture: hello.draw@1 { rate = rate; domain = window(); }
output result <- picture.result;kernels/hello.ent:每个像素根据自己的位置和当前时间算出颜色。
kernel hello.draw@1 { requires { field.write; time.read; } param rate: Float = 0.35; // how fast the colors turn output result: Image; compute { // Where this pixel is, from -1 to 1 across the shorter side. let { x: width, y: height } = domain(); let place = (coord() * 2.0 - domain()) / min(width, height); let away = length(place); let turn = time() * rate; // Rings that move outwards, and a color that goes round. let ring = sin(away * 8.0 - turn * 6.2831853) * 0.5 + 0.5; let color = mix( vec3(0.15, 0.25, 0.45), vec3(0.95, 0.65, 0.35), ring * saturate(1.2 - away) ); return vec4(color, 1.0); }}注意 requires { field.write; time.read; }:Kernel 要读时钟,就必须声明 time.read 能力。见能力与安全。
tests/hello.replay:
scene ../scene.esn
# A small window, so the pixels are few and the test is quick.window 64 40 1frame 0.0expect 32 20 = 0.550 0.450 0.400 0.01frame 0.5expect 32 20 = 0.194 0.272 0.445 0.01entelechy player hello/scene.esn # 打开窗口(需要 entelechy-player)entelechy run hello/scene.esn --window 640x400 --out frame.png # 无窗口,输出一张图entelechy replay hello/tests/hello.replay # 跑测试在 Player 打开时修改 kernels/hello.ent 并保存,画面会立即变化;如果改错了,正在运行的版本保持不变,并告诉你错在哪里。
生成的 README 建议了两个练习:
- 给场景再加一个
param,并在 Kernel 中使用它。 - 加第二个节点读取第一个节点(
input under: Image;和sample(under)),在它上面再画一层。
下一页会从零写一个 Kernel:第一个 Kernel。

