Space3D
Module: terminaltexteffects.engine.space3d
New in 0.16.0
Space3D and character mounting are available on development main and are not in the published 0.15.0
package.
Space3D lets an effect move its own characters through 3D. It holds a camera centered on the canvas, a light and
any number of bodies. A body is geometry that moves in 3D: a cube, a prism, a sphere, or a plain frame of reference.
Bodies own no characters. The effect mounts its characters on anchors (points on a body) and releases them when it
wants them back. While a character is mounted, only its position comes from 3D, so its scenes, events and layer keep
working as usual.
World units are terminal columns. The origin is the center of the canvas, +x points right, +y points up and +z points
toward the viewer. Angles are degrees, and axes are "x", "y", "z", "diagonal" or any (x, y, z) direction.
For the vectors, rotations and projection underneath, see Geometry 3D.
Moving bodies
An effect can change a body one step at a time from __next__. rotate, move_by, scale_by and the set_*
methods take effect immediately. It can also queue tweens that Space3D.step() plays one frame at a time: spin,
settle, turn_to, turn_to_rest, move_to, scale_to, random_pose, random_position and hold. Each tween
runs after the previous one, or alongside it with together=True, and on_complete runs a callback when one
finishes. Callbacks run once every body has moved and every mount has been refreshed, so characters released there
are handed over at the final pose. Tweens add their change to the body instead of overwriting it, so a spin keeps turning a body that the
effect is also nudging.
Mounting characters
Anchors move with their body. body.anchor(x, y, z) makes one, and layouts make many:
text_plane(characters): one anchor per character, placed so each sits on its input cell at the body's pose.surface(count),vertices()andedges(count): spread over a shape.ring(count, radius): a circle around the body.wrap(characters): text wrapped around aCylinderorSphere.
space.mount(character, anchor) hands the character's position to the anchor. The blend_frames and ease options
make it travel there from wherever it is. Mounting also sets two defaults:
layer_by_depth=Truemakes nearer characters draw over farther ones.hide_when_facing_awaycan hide a character while its side of the body faces away.
space.release(character) gives the character back where it stands, ready for a path, and undoes only what the
mount itself changed.
Mounting is part of Motion, so it works with the rest of the engine:
- A mounted character counts as active.
- Activating a path releases the mount, and mounting deactivates the path.
- The
MOUNT_COMPLETEandMOUNT_RELEASEDevents and theMOUNTandUNMOUNTactions chain mounts with paths and scenes. Usespace.new_mount()to create a mount for theMOUNTaction.
Each mount reports depth, nearness, facing, facing_amount and light after every step(). An effect can read
these to set its own appearance. A scene created with sync=Scene.SyncMetric.LIGHT or Scene.SyncMetric.DEPTH
picks its frame from the mount's light or nearness, so 3D shading can be authored as an ordinary gradient scene.
Drawing surfaces
Mounted characters leave gaps on a solid. To fill every covered cell, draw the body with a look:
Shaded(gradient, symbols)fills faces with a symbol ramp and gradient, picked by each face's angle to the light.Solid(symbol, gradient)uses one symbol, colored by the light.Textured(text=None, back="hide")wraps the input text, or any string, over the faces. Withback="dim"the far side shows through the spaces in the text.Wireframe(color, hidden_color)draws only the edges, with hidden edges dimmed or left out.
Gradients default to the TTE brand colors. body.draw(look) starts drawing, faces={tag: look} gives faces
their own looks (a die is one argument), and body.erase() stops. Each step() draws every drawn body into one
depth buffer, so overlapping bodies hide each other correctly.
The space draws surfaces with characters it creates, one per covered cell, and never uses the effect's own
characters. body.surface_characters lists the ones showing a body after the last step(). An effect can restyle
them, but each step() redraws them. Surface cells are ordered by their exact depth, like mounted characters, and
count a hair farther than they are, so text mounted on a drawn body from the default layer 0 or above reads on top
of it.
self.die = self.space.body(Cube(16)).draw(Shaded(), faces={0: Textured("1"), 2: Textured("6")})
self.die.random_pose(frames=90, ease=easing.out_cubic)
The following snippet runs inside an effect iterator, where self.terminal and self.active_characters are
available:
from terminaltexteffects import Color, Gradient, Scene, easing
from terminaltexteffects.engine.space3d import Cube, Space3D
self.space = Space3D(self.terminal)
self.cube = self.space.body(Cube(20))
self.cube.spin("y", turns=2, frames=240, ease=easing.in_out_sine).settle("x", frames=120) # (1)
characters = [c for c in self.terminal.get_characters() if c.input_symbol != " "]
shade = Gradient(Color("#5a005a"), Color("#00D1FF"), Color("#ffffff"), steps=12)
for character, anchor in zip(characters, self.cube.surface(len(characters))):
scene = character.animation.new_scene(sync=Scene.SyncMetric.LIGHT) # (2)
scene.apply_gradient_to_symbols(character.input_symbol, 1, fg_gradient=shade)
character.animation.activate_scene(scene)
self.space.mount(character, anchor, blend_frames=40, hide_when_facing_away=True)
self.terminal.set_character_visibility(character, is_visible=True)
self.active_characters.add(character)
def __next__(self) -> str:
if not self.space.animating:
raise StopIteration
self.space.step() # (3)
self.update()
return self.frame
- Two full turns about y, then a turn about x that eases out any tilt and ends at rest.
- Each frame of this scene is a step along the gradient. The mount's
lightpicks the frame, so faces brighten as they turn toward the light. - Plays the tweens and refreshes every mount's readings.
update()then ticks the characters, which moves mounted characters onto their anchors.
Bodies that move in 3D, and mounting characters on them.
An effect stays the authority over its characters. Space3D holds a camera, a light and bodies. A Body is
geometry that moves in 3D: the effect turns, moves and scales it one step at a time, or queues tweens that
Space3D.step plays. A body owns no characters. The effect mounts its own characters on anchors (points on a
body) and releases them when it wants them back. While a character is mounted, only its position comes from 3D;
its scenes, events and layer handling keep running as usual.
space = Space3D(self.terminal)
cube = space.body(Cube(20))
cube.spin("y", turns=2, frames=240)
for character, anchor in zip(characters, cube.surface(len(characters))):
space.mount(character, anchor, blend_frames=40)
self.active_characters.add(character)
def __next__(self):
self.space.step() # Advance tweens and read every mount's 3D state.
self.update() # Characters tick as usual; mounted ones move to their anchors.
return self.frame
Mounting is part of Motion: a mounted character takes its position from the mount instead of a path, counts as
active, and raises MOUNT_COMPLETE and MOUNT_RELEASED events. Activating a path releases the mount, and
mounting deactivates the path, so characters pass between 2D paths and 3D freely.
A body with a shape can also be drawn as a filled surface with Body.draw and a look (Shaded, Solid,
Textured or Wireframe). The space draws surfaces with characters it creates and manages, one per covered
cell, so the effect's own characters are never used for them.
World units are terminal columns. The origin is the canvas center, +x is right, +y is up and +z points toward the
viewer. Angles are degrees, and axes are "x", "y", "z", "diagonal" or any (x, y, z) direction.
Classes:
| Name | Description |
|---|---|
Space3D |
Camera, light, bodies and mounts for one effect. |
Body |
Geometry that moves in 3D, with step-by-step transforms, tweens and anchor layouts. |
Anchor |
A point on a body that a character can be mounted on. |
Mount |
A character's link to an anchor, with the 3D readings an effect can use. |
Shape |
Base class for body shapes. |
Shaded, Solid, Textured, Wireframe |
Looks for drawing a body as a surface. |
Functions:
| Name | Description |
|---|---|
rotation_about |
Returns a rotation of some degrees about a named axis or direction. |
Axis = typing.Union[str, tuple[float, float, float], g3.Vec3]
module-attribute
An axis name ("x", "y", "z", "diagonal") or an (x, y, z) direction.
Direction = typing.Union[str, tuple[float, float, float], g3.Vec3]
module-attribute
A light direction name (see Space3D) or an (x, y, z) direction pointing toward the light.
Look = typing.Union[Shaded, Solid, Textured, Wireframe]
module-attribute
How a body is drawn: Shaded, Solid, Textured or Wireframe.
Anchor
dataclass
A point on a body that a character can be mounted on. Make anchors with Body.anchor or a layout.
Attributes:
| Name | Type | Description |
|---|---|---|
body |
Body
|
The body the anchor moves with. |
point |
Vec3
|
Position in the body's own coordinates. |
normal |
Vec3 | None
|
Unit vector the surface faces at the point, if known. |
Source code in terminaltexteffects/engine/space3d.py
Body
Geometry that moves in 3D. It owns no characters; characters are mounted on its anchors.
Change a body one step at a time from the effect (rotate, move_by, scale_by and the set_* methods take
effect immediately), or queue tweens (spin, settle, turn_to, move_to, ...) that Space3D.step plays
one frame at a time. Each tween runs after the previous one, or alongside it with together=True. Tweens
apply changes rather than overwrite the transform, so a tween and step-by-step calls compose: a spin keeps
turning a body the effect is also nudging. A tween with frames=0 applies at once if nothing is queued ahead
of it.
Create bodies with Space3D.body. Transform methods return the body, so calls chain.
Attributes:
| Name | Type | Description |
|---|---|---|
space |
Space3D
|
The space the body belongs to. |
shape |
Shape | None
|
The body's shape, or |
Source code in terminaltexteffects/engine/space3d.py
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 | |
animating
property
Whether tweens are queued or playing.
drawn
property
Whether the body is drawn as a surface.
mesh
property
The shape's mesh in the body's own coordinates, or None without a shape.
position
property
Where the body's origin sits, in columns from the canvas center.
rotation
property
The body's orientation.
scale
property
The body's size multiplier.
shape
property
The read-only shape used to build this body's mesh and layouts.
Create a new body for a different shape. Existing anchors stay attached to their original body.
surface_characters
property
The characters showing this body after the last Space3D.step, by cell.
They belong to the space and are redrawn every step, so changes an effect makes to them last until then.
__init__(space, shape=None, *, at=(0, 0, 0))
Initialize a body. Use Space3D.body rather than calling this directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
Space3D
|
The space the body belongs to. |
required |
shape
|
Shape | None
|
The body's shape, if any. |
None
|
at
|
tuple[float, float, float]
|
Starting position in columns from the canvas center. |
(0, 0, 0)
|
Source code in terminaltexteffects/engine/space3d.py
add_char(character, anchor, **options)
Mount character on anchor, which must belong to this body. See Space3D.mount for options.
Source code in terminaltexteffects/engine/space3d.py
add_chars(characters, anchors, **options)
Mount each character on the matching anchor. See Space3D.mount for options.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the lengths differ or an anchor belongs to another body. |
Source code in terminaltexteffects/engine/space3d.py
anchor(x, y, z, *, normal=None)
Return an anchor at (x, y, z) in the body's own coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Columns right of the body's origin, before the body turns. |
required |
y
|
float
|
Columns up. |
required |
z
|
float
|
World columns toward the viewer, before the body turns; not camera depth. |
required |
normal
|
Axis | None
|
Which way the surface faces there. Mounts on anchors with a normal report
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Anchor |
Anchor
|
The new anchor. |
Source code in terminaltexteffects/engine/space3d.py
cancel()
Discard queued tweens and their callbacks, keeping the current pose.
draw(look=None, *, faces=None)
Draw the body as a surface from the next Space3D.step on, replacing any earlier look.
The space draws surfaces with characters it creates, one per covered cell, so no effect characters are used. Each cell is layered by depth, just below a mounted character at the same depth, so text mounted on a drawn body from the default layer 0 or above reads on top of it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
look
|
Look | None
|
How to draw the body: |
None
|
faces
|
Mapping[int, Look] | None
|
Looks for faces by tag (see each shape), such as one per side of a
die. Faces not listed use |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Body |
Body
|
The body, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the body has no shape, or a |
Source code in terminaltexteffects/engine/space3d.py
edges(count)
Return about count anchors spread evenly along the edges of the body's shape.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the body has no shape. |
Source code in terminaltexteffects/engine/space3d.py
erase()
Stop drawing the body. Its cells are hidden at the next Space3D.step.
hold(frames)
move_by(x=0.0, y=0.0, z=0.0)
move_to(x=0.0, y=0.0, z=0.0, frames=60, ease=None, *, together=False)
Queue a move of the body's origin to (x, y, z).
Source code in terminaltexteffects/engine/space3d.py
on_complete(callback)
Call callback(body) when the most recently queued tween finishes, or now if nothing is queued.
During Space3D.step, the callback runs after every body has moved and every mount's readings are
refreshed, so releasing characters there leaves them at the final pose.
Source code in terminaltexteffects/engine/space3d.py
on_group_complete(callback)
Call callback(body) when the last queued parallel group finishes, or now if none is queued.
Later groups added after this call do not delay the hook. Like on_complete, callbacks run after
mount readings refresh, so they can safely release characters at the endpoint pose.
Source code in terminaltexteffects/engine/space3d.py
random_pose(frames=0, ease=None, *, together=False)
Queue a turn to a random orientation, drawn evenly from all orientations with the space's RNG.
Source code in terminaltexteffects/engine/space3d.py
random_position(x=None, y=None, z=(0.0, 0.0), frames=0, ease=None, *, together=False)
Queue a move to a random point drawn with the space's RNG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
tuple[float, float] | None
|
Range for x. |
None
|
y
|
tuple[float, float] | None
|
Range for y. |
None
|
z
|
tuple[float, float]
|
Range for world z, increasing toward the viewer; not camera depth. |
(0.0, 0.0)
|
frames
|
int
|
Frames the move takes. 0 jumps. |
0
|
ease
|
EasingFunction | None
|
Easing for the move. |
None
|
together
|
bool
|
Run alongside the previously queued tween. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Body |
Body
|
This body. |
Source code in terminaltexteffects/engine/space3d.py
release_all()
Release every character mounted on this body.
release_char(character)
Release character if it is mounted on this body.
Source code in terminaltexteffects/engine/space3d.py
reset()
Return the body to the pose it was created in and clear its queued tweens, now.
ring(count, radius, *, axis='y')
Return count anchors evenly around a circle of radius about axis, facing outward.
Source code in terminaltexteffects/engine/space3d.py
rotate(axis, degrees, *, local=False)
Turn about a world axis through the origin, or a body axis with local=True, now.
Source code in terminaltexteffects/engine/space3d.py
scale_by(factor)
Multiply the body's size by factor, now. Raises ValueError unless factor is positive.
scale_to(scale, frames=60, ease=None, *, together=False)
Queue a change of the body's size multiplier to scale. Raises ValueError unless it is positive.
Source code in terminaltexteffects/engine/space3d.py
set_position(x=0.0, y=0.0, z=0.0)
set_rotation(rotation=None)
Set the body's orientation, now. None is the rest orientation. See rotation_about.
set_scale(scale)
Set the body's size multiplier, now. Raises ValueError unless scale is positive.
settle(axis='y', turns=1.0, frames=120, ease=None, *, together=False)
Queue turns turns about axis while easing out any other tilt, ending at the rest orientation.
Source code in terminaltexteffects/engine/space3d.py
spin(axis='y', turns=1.0, frames=120, ease=None, *, together=False, local=False)
Queue full turns about a world axis, or a body axis with local=True.
The local axis follows the current orientation, including other concurrent turns.
Source code in terminaltexteffects/engine/space3d.py
surface(count)
Return about count anchors spread evenly over the body's shape, facing outward.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the body has no shape. |
Source code in terminaltexteffects/engine/space3d.py
text_plane(characters)
Return an anchor for each character at its input cell, on a plane facing the viewer.
The anchors are placed so that, at the body's current pose, each projects onto its character's input cell. Turning the body tilts and flips the text like a card.
Source code in terminaltexteffects/engine/space3d.py
turn_to(rotation, frames=60, ease=None, *, together=False)
Queue a turn to rotation along the shortest path. See rotation_about.
Source code in terminaltexteffects/engine/space3d.py
turn_to_rest(frames=60, ease=None, *, together=False)
Queue a shortest-path turn back to the rest orientation, where text plane anchors meet their cells.
Source code in terminaltexteffects/engine/space3d.py
vertices()
Return an anchor on each vertex of the body's shape, facing away from the center.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the body has no shape. |
Source code in terminaltexteffects/engine/space3d.py
world_point(local)
Return where a point in the body's own coordinates is in world space right now.
Source code in terminaltexteffects/engine/space3d.py
wrap(characters)
Return an anchor for each character with its text wrapped once around a cylinder or sphere.
Text columns run around the shape, starting at the front, and text rows run from top to bottom.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the body's shape is not a |
Source code in terminaltexteffects/engine/space3d.py
Box
dataclass
Bases: Shape
A box. Faces are tagged 0 front, 1 right, 2 back, 3 left, 4 top, 5 bottom.
Source code in terminaltexteffects/engine/space3d.py
build_mesh()
texture_cell(fragment)
Return the text cell for a fragment. Each face shows the text from its own top left corner.
Source code in terminaltexteffects/engine/space3d.py
Cube
dataclass
Bases: Shape
A cube size columns wide.
Source code in terminaltexteffects/engine/space3d.py
build_mesh()
texture_cell(fragment)
Return the text cell for a fragment. Each face shows the text from its own top left corner.
Cylinder
dataclass
Bases: Shape
An upright cylinder around the y axis. wrap lays text around its side.
Source code in terminaltexteffects/engine/space3d.py
build_mesh()
surface_points(count)
Return about count points in even rings around the side.
Source code in terminaltexteffects/engine/space3d.py
texture_cell(fragment)
Return the text cell for a fragment, starting at the left edge of the front. Caps have none.
Source code in terminaltexteffects/engine/space3d.py
wrap_point(around, up)
Return the side point around turns from the front and up of the way from bottom to top.
Source code in terminaltexteffects/engine/space3d.py
Icosahedron
dataclass
Bases: Shape
A regular icosahedron with its vertices radius from the center.
Source code in terminaltexteffects/engine/space3d.py
Mount
A character's link to an anchor, created by Space3D.mount or Space3D.new_mount.
While the mount is active, the character's Motion takes its position from the anchor each tick. The readings
below are refreshed by Space3D.step, so an effect can read them after step() to drive its own appearance
decisions, and Scene.SyncMetric.LIGHT and DEPTH let a scene follow them.
Attributes:
| Name | Type | Description |
|---|---|---|
space |
Space3D
|
The space the mount belongs to. |
character |
EffectCharacter
|
The mounted character. |
anchor |
Anchor
|
Where the character rides. |
blend_frames |
int
|
Frames to travel from where the character was to the anchor. |
ease |
EasingFunction | None
|
Easing for that travel. |
layer_by_depth |
bool
|
Raise nearer characters' layers so they draw over farther ones. |
hide_when_facing_away |
bool
|
Hide the character while its anchor faces away from the viewer. |
coord |
Coord
|
The cell the anchor projects onto. |
depth |
float
|
Camera depth |
nearness |
float
|
1 at the nearest point the body can reach at its size, 0 at the farthest. |
facing |
bool
|
Whether the anchor's surface faces the viewer. True without a normal. |
facing_amount |
float
|
-1 facing directly away, 0 edge-on, 1 facing the viewer. 1 without a normal. |
light |
float
|
How directly the surface faces the light, 0 to 1. 1 without a normal. |
active |
bool
|
Whether the character is currently mounted with it. |
arrived |
bool
|
Whether the blend has finished, so the character sits on the anchor. |
projected |
bool
|
Whether the anchor is on or beyond the near plane and can be projected. Characters are hidden while this is false; the other readings retain their last valid values. |
Source code in terminaltexteffects/engine/space3d.py
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 | |
blend_progress
property
Fraction of blend frames elapsed, from 0 to 1, before easing; 1 for a zero-frame blend.
__init__(space, character, anchor, *, blend_frames=0, ease=None, layer_by_depth=True, hide_when_facing_away=False)
Initialize a mount. Use Space3D.mount or Space3D.new_mount rather than calling this directly.
Source code in terminaltexteffects/engine/space3d.py
Octahedron
dataclass
Bases: Shape
A regular octahedron with its vertices radius from the center.
Source code in terminaltexteffects/engine/space3d.py
Prism
dataclass
Bases: Shape
An upright prism with sides rectangular sides around the y axis.
Source code in terminaltexteffects/engine/space3d.py
build_mesh()
texture_cell(fragment)
Return the text cell for a fragment, starting at the left edge of the front. Caps have none.
Source code in terminaltexteffects/engine/space3d.py
Pyramid
dataclass
Bases: Shape
A pyramid with a sides-sided base and its apex up the y axis.
Source code in terminaltexteffects/engine/space3d.py
build_mesh()
texture_cell(fragment)
Return the text cell for a fragment, starting at the left edge of the front. The base has none.
Source code in terminaltexteffects/engine/space3d.py
Shaded
dataclass
Fill faces with a symbol and color picked by how directly each face meets the light.
Attributes:
| Name | Type | Description |
|---|---|---|
gradient |
Gradient | None
|
Colors from unlit to fully lit. |
symbols |
str
|
Symbols from unlit to fully lit. |
Source code in terminaltexteffects/engine/space3d.py
__post_init__()
Shape
dataclass
Base class for body shapes. Sizes are in columns.
A shape gives a body faces, vertices and edges to lay anchors on. Subclasses build a geometry3d.Mesh in
build_mesh. Built-in shapes expect positive dimensions, which are intentionally not validated. Zero or
negative sizes can collapse faces or reverse winding; shading and texture layouts are not guaranteed for
those sizes. Body scale, in contrast, is validated and must remain positive.
Source code in terminaltexteffects/engine/space3d.py
build_mesh()
surface_points(count)
Return about count points spread over the surface, each with its outward normal.
The default spreads points over the mesh's faces in proportion to their area. Curved shapes override it with an even parametric layout.
Source code in terminaltexteffects/engine/space3d.py
texture_cell(fragment)
Return where a drawn cell falls in a Textured look's text, as a fractional (column, row).
Row 0 is the top line of the text, and one unit is about one cell at the body's own size. Returns None
for faces without texture coordinates, which a Textured look shades instead. Shapes without a texture
layout return None everywhere.
Source code in terminaltexteffects/engine/space3d.py
Solid
dataclass
Fill faces with one symbol, colored by the light.
Attributes:
| Name | Type | Description |
|---|---|---|
symbol |
str
|
The fill symbol, one cell wide. |
gradient |
Gradient | None
|
Colors from unlit to fully lit. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/space3d.py
Space3D
Camera, light, bodies and mounts for one effect.
Call step() once per frame, before self.update(): it plays queued tweens and refreshes every mount's
readings, and the characters' own ticks then move mounted characters to their anchors.
Mounted characters tick like any other, so keep them in the iterator's active_characters while they ride. A
mounted character counts as active, so update() won't drop it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
terminal
|
Terminal
|
The effect's terminal. |
required |
perspective
|
float
|
1 is a natural perspective, larger values exaggerate depth, and 0 is a flat orthographic view. |
1.0
|
light
|
Direction
|
Direction toward the light: |
'upper left'
|
rng
|
Random | None
|
Random source for |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
terminal |
Terminal
|
The effect's terminal. |
camera |
Camera
|
Projects world space onto the canvas, centered on it. |
light |
Vec3
|
Unit vector toward the light. |
bodies |
list[Body]
|
Bodies in creation order. |
mounts |
dict[EffectCharacter, Mount]
|
Active mounts by character. |
rng |
Random
|
Random source for the random tweens. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/space3d.py
1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 | |
animating
property
Whether any body has tweens queued or playing.
blending
property
Whether any active mount is still traveling toward its anchor. Advances on character ticks.
input_text
property
The effect's input text, top line first, as Textured looks wrap it by default.
surface_characters
property
Every character the space has created to draw surfaces, shown or not, by cell.
__init__(terminal, *, perspective=1.0, light='upper left', rng=None)
Initialize the space. See the class docstring for the arguments.
Source code in terminaltexteffects/engine/space3d.py
body(shape=None, *, at=(0, 0, 0))
Create a body, with a shape or as a plain frame of reference for anchors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Shape | None
|
|
None
|
at
|
tuple[float, float, float]
|
Starting position in columns from the canvas center. |
(0, 0, 0)
|
Returns:
| Name | Type | Description |
|---|---|---|
Body |
Body
|
The new body. |
Source code in terminaltexteffects/engine/space3d.py
clear()
Remove all current bodies, releasing their mounts and hiding their surface cells immediately.
mount(character, anchor, *, blend_frames=0, ease=None, layer_by_depth=True, hide_when_facing_away=False)
Hand the character's position to anchor, now. Arguments are as in new_mount.
Mounting deactivates the character's path and leaves its scene alone. If the character is already mounted, that mount is released first.
Returns:
| Name | Type | Description |
|---|---|---|
Mount |
Mount
|
The active mount. |
Source code in terminaltexteffects/engine/space3d.py
new_mount(character, anchor, *, blend_frames=0, ease=None, layer_by_depth=True, hide_when_facing_away=False)
Create a mount without activating it, for Motion.activate_mount or the MOUNT event action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
character
|
EffectCharacter
|
The character to mount. |
required |
anchor
|
Anchor
|
Where it will ride. |
required |
blend_frames
|
int
|
Frames to travel from wherever the character is to the anchor. 0 jumps. |
0
|
ease
|
EasingFunction | None
|
Easing for that travel. |
None
|
layer_by_depth
|
bool
|
Raise nearer characters' layers above their layer at mounting, so they draw over farther ones. Release restores the layer. |
True
|
hide_when_facing_away
|
bool
|
Hide the character while its anchor faces away, once it has arrived. Release shows it again. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Mount |
Mount
|
The inactive mount. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/space3d.py
release(character)
Give the character back, if it is mounted in this space, on the cell its anchor last projected to.
A character still blending toward its anchor stays where it is. Release undoes only what the mount did: it
restores the layer if layer_by_depth was on and shows the character if the mount hid it. A
MOUNT_RELEASED event follows.
Source code in terminaltexteffects/engine/space3d.py
remove(body)
Remove an owned body, cancel its tweens, release its mounts and hide its surface cells now.
Repeated removal is harmless. Removed bodies are no longer drawn or stepped, and their anchors cannot be mounted again. Create a new body to add geometry back. Surface characters stay pooled for reuse.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the body belongs to another space. |
Source code in terminaltexteffects/engine/space3d.py
step()
Play one frame of every body's tweens, refresh every mount's readings and draw the surfaces.
Callbacks of tweens that finished this frame run after the readings are refreshed, so characters released from them are placed at the final pose. Readings are refreshed again after any callbacks, so changes they make show in this frame.
Source code in terminaltexteffects/engine/space3d.py
Sphere
dataclass
Bases: Shape
A sphere. wrap lays text over it between 60 degrees north and south.
Source code in terminaltexteffects/engine/space3d.py
build_mesh()
surface_points(count)
Return count points spread evenly over the sphere (a Fibonacci lattice).
Source code in terminaltexteffects/engine/space3d.py
texture_cell(fragment)
Return the text cell for a fragment, starting at the left edge of the front, from pole to pole.
Source code in terminaltexteffects/engine/space3d.py
wrap_point(around, up)
Return the point around turns from the front, up of the way from 60 degrees south to 60 north.
Source code in terminaltexteffects/engine/space3d.py
Tetrahedron
dataclass
Bases: Shape
A regular tetrahedron with its vertices radius from the center.
Source code in terminaltexteffects/engine/space3d.py
Textured
dataclass
Wrap text over the faces, colored by the light. Text repeats by default or clamps with repeat=False.
Each cell shows one symbol, so wide characters (such as CJK) are left blank.
Faces without a texture layout (prism and cylinder caps, polyhedra, the torus) are shaded in back_color.
Attributes:
| Name | Type | Description |
|---|---|---|
text |
str | None
|
The text to wrap. |
gradient |
Gradient | None
|
Colors from unlit to fully lit. |
back |
str
|
|
back_color |
Color
|
Color of the far side and of faces without a texture layout. |
offset |
tuple[float, float]
|
Text column and row added before sampling. Positive values scroll left/up. |
repeat |
bool
|
Repeat the text, or clamp sampling to its edge cells when false. |
scale |
float
|
Positive text size multiplier in both dimensions; 2 doubles each character's footprint. |
Source code in terminaltexteffects/engine/space3d.py
__post_init__()
Validate texture sampling settings.
Source code in terminaltexteffects/engine/space3d.py
Torus
dataclass
Bases: Shape
A torus lying around the y axis: a tube minor_radius thick, major_radius from the center.
Source code in terminaltexteffects/engine/space3d.py
Wireframe
dataclass
Draw only the edges, with symbols that follow each edge's slope.
Attributes:
| Name | Type | Description |
|---|---|---|
color |
Color
|
Color of edges on faces turned toward the viewer. |
hidden_color |
Color | None
|
Color of hidden edges, or |
depth_test |
bool
|
Test edges against the mesh's filled depth buffer. Use for concave meshes; the default only tests adjacent face orientation. |
Source code in terminaltexteffects/engine/space3d.py
rotation_about(axis, degrees)
Return a rotation of degrees about axis, counterclockwise when looking down the axis toward the origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
Axis
|
|
required |
degrees
|
float
|
Angle of the rotation. |
required |
Returns:
| Type | Description |
|---|---|
Rotation
|
g3.Rotation: The rotation. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |