Lighting
Lighting affects rendered output in the current layer, including 2D primitives, 3D primitives, and media or framebuffer content drawn through image(). It shades character and cell colors while preserving alpha. (☆▽☆)
Ambient light
ambientLight() adds light from all directions:
t.ambientLight(40);You can pass grayscale, RGB/RGBA components, CSS strings, arrays, or TextmodeColor values:
t.ambientLight(80, 90, 120);
t.ambientLight("#223344");Multiple ambient lights are additive.
Point lights
pointLight() adds light from a position:
t.pointLight(255, 220, 180, 20, -20, 40);You can also pass an object position:
t.pointLight("#ffe0a0", { x: 20, y: -20, z: 40 });Up to five point lights are supported per frame. Additional point lights are ignored.
Falloff
lightFalloff() controls point-light attenuation:
t.lightFalloff(1, 0.04, 0.002);The formula is:
1 / (constant + distance * linear + distance * distance * quadratic)Negative inputs are clamped to 0. If all values resolve to 0, falloff resets to (1, 0, 0).
Clear lights
noLights() removes active lights and resets falloff:
t.noLights();This is useful when one part of the frame should render lit and another should render unlit.
Frame-scoped state
Lighting state is frame-scoped and resets for each layer draw callback. Set lights in the same draw callback as the drawing commands they should affect:
t.draw(() => {
t.background(0);
t.ambientLight(30);
t.pointLight(255, 220, 160, 18, -18, 40);
t.rotateY(t.frameCount);
t.char("#");
t.charColor(180, 220, 255);
t.sphere(8);
});