3D drawing
textmode.js includes 3D primitives that render as textmode cells. The API is intentionally close to p5-style creative coding while keeping the textmode character and color model. (ノ≧∀≦)ノ
3D primitives
Available methods:
box(width, height?, depth?)sphere(radius)torus(radius, tubeRadius)cone(radius, height?)cylinder(radius, height?)ellipsoid(radiusX, radiusY, radiusZ)
t.draw(() => {
t.background(8, 10, 24);
t.char("A");
t.charColor(255, 180, 90);
t.cellColor(0);
t.rotateX(t.frameCount);
t.rotateY(t.frameCount * 1.4);
t.box(12, 12, 12);
});Use 3D transforms
The same transform stack works for 2D and 3D:
t.push();
t.translate(-10, 0, 0);
t.rotateY(t.frameCount);
t.sphere(6);
t.pop();
t.push();
t.translate(10, 0, 0);
t.rotateX(t.frameCount);
t.torus(6, 2);
t.pop();Use push() and pop() to keep each object independent.
Projection
Perspective projection is the default. Switch to orthographic projection with ortho():
t.ortho();
t.box(12, 12, 12);Use perspective() to set perspective parameters:
t.perspective(60, 0.1, 1000);Projection state resets at the start of each frame, so call ortho() or custom perspective() settings in every frame where they matter.
Cameras and lights
3D scenes become easier to control with:
t.camera(0, 0, 60, 0, 0, 0);
t.ambientLight(40);
t.pointLight(255, 220, 180, 20, -20, 40);Textmode-specific styling
3D primitives still use textmode state:
t.char("#");
t.charColor(120, 220, 255);
t.cellColor(4, 8, 16);
t.charRotation(45);
t.sphere(8);The result is not a pixel-shaded mesh. It is a mesh expressed through character cells, glyph color, and cell color.