Skip to content
View source

Your first project

entelechy new <dir> writes a directory that runs: a Kernel, the scene that places it, a replay that checks what it draws, and a README saying what to change first.

终端窗口
entelechy new hello
play it: entelechy player hello/scene.esn
run it: entelechy run hello/scene.esn --window 640x400 --out frame.png
test it: entelechy replay hello/tests/hello.replay

--kind picture|sound|game picks the start (a picture by default).

hello/
├── README.md
├── scene.esn the scene: nodes, params, outputs
├── kernels/
│ └── hello.ent the Kernel: what each pixel computes
└── tests/
└── hello.replay the replay: a pixel's color at a frame

scene.esn: one node over the window.

// 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: each pixel works out its color from where it is and what time it is.

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);
}
}

Note requires { field.write; time.read; }: reading the clock needs the time.read capability. See Capabilities & security.

tests/hello.replay:

scene ../scene.esn
# A small window, so the pixels are few and the test is quick.
window 64 40 1
frame 0.0
expect 32 20 = 0.550 0.450 0.400 0.01
frame 0.5
expect 32 20 = 0.194 0.272 0.445 0.01
终端窗口
entelechy player hello/scene.esn # a window (needs entelechy-player)
entelechy run hello/scene.esn --window 640x400 --out frame.png # no window, one picture
entelechy replay hello/tests/hello.replay # the test

Edit kernels/hello.ent while the Player is open and the picture changes as you save; a Kernel that does not compile leaves the running one alone and says why.

The README suggests two exercises:

  1. Give the scene another param and use it in the Kernel.
  2. Add a second node that reads the first (input under: Image; and sample(under)) to draw over it.

Next, write a Kernel from scratch: Your first Kernel.