World
Modules: terminaltexteffects.engine.world, camera, tweens, shapes, surfaces, drawing, view
New in 0.16.0
The world is on the native-3d development branch and is not in the published 0.15.0 package.
Every terminal has a world, terminal.world: a tree of nodes in 3D, a camera and a light. Characters and bodies
are nodes. A body has a position, rotation and scale, and the nodes attached to it move, turn and scale with it.
A body with a shape has a surface, a grid of cells over the shape that characters sit on and travel over.
world.rootnever moves; free nodes are its children.world.text_planeis the flat body the input characters start on, at their input cells. Turn or move it and the text goes with it.world.screenis fixed to the canvas: characters attached to it stay on their cells whatever the camera does, for labels and overlays.world.body(shape, at=...)makes a body.body.draw(look)draws it with characters the world adds, andworld.remove(body)takes it out.world.cameraprojects the world onto the canvas, and moves now or over frames.world.set_light()points the light.
Units are columns; a row is two units tall. The origin is the middle of the canvas, +x is right, +y is up and +z points toward the default camera. Angles are degrees.
A frame
update() plays one frame: the world steps (camera and body tweens, then body paths, then tween callbacks), every
character is projected again if the view changed, active characters tick, and the world paints drawn bodies. Characters
and drawn cells are painted farther first, so the nearest wins each cell. A character facing the camera on a drawn
body's surface draws over the body's own cell beneath it.
Turning and scaling bodies
rotate, reset and the position, rotation and scale setters change a body now. spin, settle, turn_to,
turn_to_rest, random_pose, scale_to and hold queue tweens that the world plays one frame at a time, one after
another or alongside the last with together=True. Tweens apply their change as a delta, so they compose with each
other and with changes made now. on_complete and on_group_complete run callbacks once every body and the camera
have moved. Bodies move over frames along body.motion paths, like characters.
Reading the view
character.view reports how a character is seen this frame: its cell, depth, nearness, whether it is facing
the camera and by how much, the light on it and the face of its parent's surface it is on. Scenes synced to
LIGHT or DEPTH read it. A character behind the camera is hidden, and so is one facing away on a body with
hide_facing_away set; it shows again once the view sees it.
The 3D world every effect runs in: spatial nodes, bodies, the text plane and the camera.
Every character is a point in 3D space. The familiar 2D canvas is the world's text plane: a flat body at z = 0,
facing the default camera, whose surface positions are canvas coordinates. Input characters start on it, so a
position (column, row, 0) on the text plane is drawn in exactly that cell, and 2D effects work unchanged.
world = terminal.world
character.motion.position # Vec3(column, row, height) on the text plane
path.new_waypoint(Vec3(20, 10, 30)) # a height lifts the character toward the camera
A node's position is measured in its parent's frame, and what the three numbers mean depends on the parent:
- On a body with a surface, such as the text plane, it is
(column, row, height): column and row in cells, and height off the surface along its normal, in units. - On a shapeless body, such as
world.root, it is(x, y, z)in the parent's axes, in units.
One unit is the width of one terminal cell; a row is TERMINAL_ROW_SCALE (2) units tall. The world origin is the
canvas center, +x is right, +y is up and +z points toward the default camera.
Classes:
| Name | Description |
|---|---|
SpatialNode |
The common base of characters and bodies: a parent, children and a position. |
Body |
A node with rotation and scale, which other nodes are measured against, and optionally a shape. |
SurfaceTarget |
A point on a body's surface that moves with it: a live target for waypoints. |
World |
The root, the text plane, the camera and the light for one terminal. |
A body with a shape has a surface, a grid of cells over the shape. Characters attached to it sit on the surface at
(column, row, height) and travel over it:
cube = world.body(Cube(16), at=(0, 0, -20))
cube.surface.face("front").layout_text(characters)
path.new_waypoint(cube.surface.face("top").center) # the shortest way, over the edge and across the lid
Moving nodes between parents:
character.attach(pivot) # keeps its place in the world; its position is now in the pivot's frame
character.attach(pivot, at=g3.Vec3(5, 0, 0)) # placed at that position in the pivot's frame
character.detach() # free in the world: the same as attach(world.root)
LIGHTS = {'upper left': g3.Vec3(-0.5, 0.6, 1.0), 'upper right': g3.Vec3(0.5, 0.6, 1.0), 'front': g3.Z_AXIS, 'above': g3.Vec3(0.0, 1.0, 0.3), 'left': g3.Vec3(-1.0, 0.0, 0.4), 'right': g3.Vec3(1.0, 0.0, 0.4)}
module-attribute
Named light directions for World.set_light, each pointing from the scene toward the light.
Body
Bases: SpatialNode, TweenQueue
A node with rotation and scale, which other nodes are measured against.
A body's own position is in its parent's local frame. Its children are measured in its frame: surface positions
when it has a surface, otherwise (x, y, z) in its axes. Moving, turning or scaling a body carries its children
with it.
A body moves like a character: body.motion takes paths of Vec3 waypoints in its parent's local frame, and
body.event_handler registers path and attach events with the node actions (ACTIVATE_PATH,
DEACTIVATE_PATH, SET_COORDINATE, ATTACH, DETACH, CALLBACK). The world steps bodies' paths at the
start of every frame.
A body turns and scales now (rotate, the rotation and scale setters) or over frames with queued tweens
(spin, settle, turn_to, scale_to, ...) that the world plays inside update(). Each tween runs after the
previous one, or alongside it with together=True, and applies its change as a delta, so tweens compose with
each other and with changes made now. Tween methods return the body, so calls chain.
A body with a shape has a surface: a grid of cells over the shape. Characters attached to it sit on the surface
at (column, row, height), and their paths follow it, over folds and round laps.
Attributes:
| Name | Type | Description |
|---|---|---|
world |
World
|
The world the body belongs to. |
shape |
Shape | None
|
The body's shape, or |
surface |
Surface
|
The grid of cells over the shape. Raises |
has_surface |
bool
|
Whether the body has a surface. |
position |
Vec3
|
Position in the parent's frame, in units. |
rotation |
Rotation
|
Orientation relative to the parent. |
scale |
float
|
Uniform scale relative to the parent. |
motion |
BodyMotion
|
Moves the body along paths in its parent's local frame. |
event_handler |
EventHandler
|
Handles the body's path and attach events. |
animating |
bool
|
Whether turn or scale tweens are queued or playing. |
mesh |
Mesh | None
|
The shape's mesh in the body's axes, or |
drawn |
bool
|
Whether the body is drawn with a look. |
hide_facing_away |
bool
|
Hide characters on the body's surface while their spot faces away from the camera. Off by default. |
Source code in terminaltexteffects/engine/world.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 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 | |
children
property
Nodes whose parent is this body.
drawn
property
Whether the body is drawn with a look.
event_handler
property
Handles the body's path and attach events.
has_surface
property
Whether the body has a surface characters can sit on.
mesh
property
The shape's mesh in the body's own axes, or None without a shape.
motion
property
Moves the body along paths of Vec3 waypoints in its parent's local frame.
position
property
writable
Position in the parent's frame, in units.
rotation
property
writable
Orientation relative to the parent.
scale
property
writable
Uniform scale relative to the parent.
surface
property
The grid of cells over the body's shape.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the body has no surface: it is a pivot, or its shape has none. Check |
surface_characters
property
The characters showing the drawn body after the last frame, by cell.
They belong to the world and are redrawn every frame, so changes an effect makes to them last until then.
world_position
property
Position in the world frame.
world_rotation
property
The body's orientation in the world: its own rotation after its ancestors'.
world_scale
property
The body's scale in the world: its own scale times its ancestors'.
__init__(world, parent, *, at=g3.ORIGIN, shape=None, surface=None)
Create a body. Bodies are made by a World, not directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
world
|
World
|
The owning world. |
required |
parent
|
Body | None
|
The parent body, or |
required |
at
|
Point3
|
Position in the parent's frame. |
ORIGIN
|
shape
|
Shape | None
|
The body's shape, or |
None
|
surface
|
Surface | None
|
The body's surface. Defaults to the shape's. |
None
|
Source code in terminaltexteffects/engine/world.py
draw(look=None, *, faces=None)
Draw the body with a look, from this frame on, replacing any earlier look.
The world draws the body with characters it creates, one per covered cell, so none of the effect's own characters are used. Drawn cells and characters are painted farther first, so the nearest wins each cell, and characters sitting on the body's surface draw over it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
look
|
Look | None
|
|
None
|
faces
|
Mapping[str | int, Look] | None
|
Looks for faces by the shape's face tags, such as one per side
of a die. Faces not listed use |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Body |
Body
|
This body, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the body has no shape, or a |
Source code in terminaltexteffects/engine/world.py
erase()
Stop drawing the body. Its cells are hidden when the world next paints.
Returns:
| Name | Type | Description |
|---|---|---|
Body |
Body
|
This body, for chaining. |
Source code in terminaltexteffects/engine/world.py
from_world(point, *, surface=True)
Return a world point as a position in this body's frame, for its children.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
Point3
|
A point in the world. |
required |
surface
|
bool
|
Return a surface position |
True
|
Source code in terminaltexteffects/engine/world.py
random_pose(frames=0, ease=None, *, together=False)
Queue a turn to a random orientation, drawn evenly from all orientations with the random module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
int
|
Duration in frames. Zero applies at once when nothing is queued ahead. |
0
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued tween instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Body |
Body
|
This body, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/world.py
reset()
Cancel tweens and put the body back where, and how, it was made: position, rotation and scale.
Returns:
| Name | Type | Description |
|---|---|---|
Body |
Body
|
This body, for chaining. |
Source code in terminaltexteffects/engine/world.py
rotate(axis, degrees=0.0, *, local=False)
Turn the body, now: degrees about an axis of its parent, or of its own with local=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
Axis | Rotation
|
An axis name ( |
required |
degrees
|
float
|
The angle to turn. |
0.0
|
local
|
bool
|
Turn about the body's own axis rather than its parent's. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Body |
Body
|
This body, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the axis is unknown or zero. |
Source code in terminaltexteffects/engine/world.py
scale_to(scale, frames=60, ease=None, *, together=False)
Queue a change of the body's scale to scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale
|
float
|
The positive scale to end at. |
required |
frames
|
int
|
Duration in frames. Zero applies at once when nothing is queued ahead. |
60
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued tween instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Body |
Body
|
This body, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/world.py
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
Axis
|
Axis name or nonzero |
'y'
|
turns
|
float
|
Number of full turns; negative values turn the other way. |
1.0
|
frames
|
int
|
Duration in frames. Zero applies at once when nothing is queued ahead. |
120
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued tween instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Body |
Body
|
This body, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/world.py
spin(axis='y', turns=1.0, frames=120, ease=None, *, together=False, local=False)
Queue full turns about an axis of the parent, or of the body with local=True.
A local axis follows the body's orientation, including other turns playing at the same time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
Axis
|
Axis name or nonzero |
'y'
|
turns
|
float
|
Number of full turns; negative values turn the other way. |
1.0
|
frames
|
int
|
Duration in frames. Zero applies at once when nothing is queued ahead. |
120
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued tween instead of after it. |
False
|
local
|
bool
|
Turn about the body's own axis. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Body |
Body
|
This body, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/world.py
to_world(position, *, surface=True)
Return a child's position, in this body's frame, as a world point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
Point3
|
The position: |
required |
surface
|
bool
|
Read the position as a surface position when the body has a surface. Bodies' positions are always in their parent's axes. |
True
|
Source code in terminaltexteffects/engine/world.py
turn_to(rotation, frames=60, ease=None, *, together=False)
Queue a turn to rotation, relative to the parent, the shortest way round.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rotation
|
Rotation
|
The orientation to end at. See |
required |
frames
|
int
|
Duration in frames. Zero applies at once when nothing is queued ahead. |
60
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued tween instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Body |
Body
|
This body, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/world.py
turn_to_rest(frames=60, ease=None, *, together=False)
Queue a turn back to the rest orientation, the shortest way round.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
int
|
Duration in frames. Zero applies at once when nothing is queued ahead. |
60
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued tween instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Body |
Body
|
This body, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/world.py
SpatialNode
The common base of characters and bodies: a parent, children and a position in the parent's frame.
Every node has a parent body. A node that is free in the world is a child of world.root. Subclasses store the
position: a character's lives in its motion, a body's in the body.
Attributes:
| Name | Type | Description |
|---|---|---|
parent |
Body
|
The body this node's position is measured against. |
children |
tuple[SpatialNode, ...]
|
Nodes whose parent is this node (always empty for characters). |
position |
Vec3
|
Position in the parent's frame. |
world_position |
Vec3
|
Position in the world frame, the root's frame. |
motion |
Motion
|
Moves the node's position along paths in its parent's frame. |
event_handler |
EventHandler
|
Handles the node's path and attach events. |
Source code in terminaltexteffects/engine/world.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
children
property
Nodes whose parent is this node.
parent
property
The body this node's position is measured against.
position
property
Position in the parent's frame.
world_position
property
Position in the world frame.
attach(parent, *, at=None)
Become a child of parent, so the node moves, turns and scales with it.
Without at, the node stays where it is in the world: its position becomes that same place in the new
parent's frame, so it doesn't jump on screen. With at, it is placed at that position in the new parent's
frame. Either way the active path is cancelled, because its waypoints were in the old frame.
Attaching triggers DETACHED (the caller is the old parent) unless the old parent was the world root,
then ATTACHED (the caller is the new parent) unless the new parent is the root.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
Body
|
The new parent: a body in the same world, or |
required |
at
|
Point3 | Coord | None
|
Where to place the node in the new parent's frame. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/world.py
descendants()
detach()
Leave the current parent and stay where the node is, free in the world. The same as attach(world.root).
SurfaceTarget
Bases: SpatialNode
A point on a body's surface that moves with the body: a live target for waypoints.
Made by body.surface.target(column, row, height). A path heading for it reads where it is every tick, so the
mover arrives on the spot however the body moved, turned or scaled meanwhile. It isn't one of the body's
children and can't be attached anywhere.
Attributes:
| Name | Type | Description |
|---|---|---|
parent |
Body
|
The body whose surface the target is on. |
position |
Vec3
|
|
world_position |
Vec3
|
Where the target is in the world now. |
Source code in terminaltexteffects/engine/world.py
position
property
(column, row, height) on the body's surface.
__init__(body, position)
attach(parent, *, at=None)
Raise: a target stays on its spot. Make a new one with surface.target instead.
Source code in terminaltexteffects/engine/world.py
World
The 3D world of one terminal: the root, the text plane, the camera and the light.
Every terminal has one, as terminal.world. The text plane starts at z = 0, sized to the canvas and facing the
default camera, which projects it back onto the canvas cell for cell.
Attributes:
| Name | Type | Description |
|---|---|---|
root |
Body
|
A shapeless body at the world origin that never moves. Free nodes are its children. |
text_plane |
Body
|
The flat body the input characters start on. Its surface positions are canvas coordinates. |
screen |
Body
|
A flat body fixed to the canvas, for labels and overlays: characters attached to it sit on their canvas cells whatever the camera does. It never moves, and heights on it are ignored. |
bodies |
tuple[Body, ...]
|
The bodies made with |
camera |
Camera
|
Projects world points onto canvas cells, with controls that move it now or over frames. |
light |
Vec3
|
Unit vector from the scene toward the light, in |
light_space |
str
|
|
Source code in terminaltexteffects/engine/world.py
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 | |
animating
property
Whether the camera or any body has tweens playing, or a body is still moving along a path.
bodies
property
The bodies made with body() and not removed, oldest first, without the root, text plane and screen.
flat
property
Whether the text plane and camera are as the world created them, so the plane maps cell for cell.
surface_characters
property
Every character the world has created to draw bodies, shown or not, by cell.
world_light
property
The light direction in world space.
__init__(canvas)
Create the world for a canvas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
canvas
|
Canvas
|
The canvas the text plane covers. |
required |
Source code in terminaltexteffects/engine/world.py
body(shape=None, *, at=g3.ORIGIN, parent=None)
Create a body: a shape characters can sit on and travel over, or without one, a pivot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Shape | None
|
The body's shape, such as |
None
|
at
|
Point3
|
Position in the parent's frame, in units. |
ORIGIN
|
parent
|
Body | None
|
The parent body; |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Body |
Body
|
The new body. |
Source code in terminaltexteffects/engine/world.py
paint()
Draw the drawn bodies for this frame. Called by update() once the characters have moved.
remove(body)
Take a body out of the world. Its children are detached and stay where they are in the world.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
body
|
Body
|
The body to remove. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
For the root, text plane or screen, which every world keeps, or a body from another world. |
Source code in terminaltexteffects/engine/world.py
set_light(direction, space='world')
Point the light, now. Can be called on any frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
str | Point3
|
A name from |
required |
space
|
str
|
|
'world'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the name or space is unknown, or the direction is zero. |
Source code in terminaltexteffects/engine/world.py
step()
Play camera and body tweens, move bodies along their paths and note changes since the last frame.
Called by update() before characters move. Callbacks of tweens that finished run once the camera and every
body have moved.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Whether the view changed, so characters that didn't move must still be projected again. |
Source code in terminaltexteffects/engine/world.py
free_text_plane()
Return the text plane of the shared world that characters without a terminal belong to.
The world's camera: projection onto the canvas, plus controls that move it now or over frames.
camera = terminal.world.camera
camera.set_perspective(1.5) # exaggerate depth
camera.orbit("y", 90, around=cube, frames=120)
camera.look_at(character) # every frame, to follow it
Distances are in units (one unit is a cell's width), angles in degrees, and turns are about the camera's own axes.
Classes:
| Name | Description |
|---|---|
Camera |
The world's camera. |
Camera
dataclass
Bases: Camera, TweenQueue
The world's camera: where the eye is, how it projects, and controls that move it now or over frames.
Every world has one, terminal.world.camera, centered on the canvas. Identity orientation looks along local -z;
+x is right and +y is up. Pan, tilt and roll use degrees about the camera's local +y, +x and +z axes. Positive
dolly moves forward, truck right and pedestal up. Methods return the camera, so calls chain.
look_at and orbit apply now unless frames is given. A target is a point or any node, a body or a
character, sampled when the tween begins; call look_at(node) every frame to follow a moving node. Queued
movements apply deltas, so changes made now compose with them. zoom_to takes an absolute focal length. The
world plays queued movements inside update(), before nodes move.
Source code in terminaltexteffects/engine/camera.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 | |
__post_init__()
Validate settings and remember the initial view for reset.
Source code in terminaltexteffects/engine/camera.py
dolly(amount)
Move forward amount columns, now; negative amounts move backward.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
float
|
Signed travel in units along the named camera-local direction. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Source code in terminaltexteffects/engine/camera.py
dolly_by(amount, frames=60, ease=None, *, together=False)
Queue relative forward travel; capture the forward axis when the tween begins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
float
|
Signed travel in units along the named camera-local direction. |
required |
frames
|
int
|
Duration in frames. Zero applies immediately only when no earlier tween is queued. |
60
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued group instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/camera.py
look_at(x, y=None, z=None, *, up='y', frames=None, ease=None, together=False)
Aim at world (x, y, z) or a node, now or over frames along the shortest turn.
up is a nonzero world direction. At a pole, the previous right axis supplies the roll.
Raises ValueError if the target is at the eye, up is zero, or frames is negative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float | SpatialNode | Vec3 | tuple[float, float, float]
|
Target world x, a |
required |
y
|
float | None
|
World y in units when x is numeric; omitted/ |
None
|
z
|
float | None
|
World z in units when x is numeric; omitted/ |
None
|
up
|
Axis
|
Nonzero world |
'y'
|
frames
|
int | None
|
|
None
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued group instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If a point is malformed, or y/z is combined with a point or node target. |
ValueError
|
If frames is negative, up is unknown or zero, or the target is at the eye when aiming begins. |
Source code in terminaltexteffects/engine/camera.py
move_by(x=0, y=None, z=None)
Move by world displacement (x, y, z), now.
Do not combine a complete point with y or z; mixed forms raise TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float | Point3
|
World displacement as a |
0
|
y
|
float | None
|
Scalar y in units; omit for a complete point. Omitted/ |
None
|
z
|
float | None
|
Scalar z in units; omit for a complete point. Omitted/ |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If a point is not a |
Source code in terminaltexteffects/engine/camera.py
move_to(x=0, y=None, z=None, frames=60, ease=None, *, together=False)
Queue an absolute world position, applying deltas that preserve concurrent nudges.
Do not combine a complete point with y or z; mixed forms raise TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float | Point3
|
Absolute world position as a |
0
|
y
|
float | None
|
Scalar y in units; omit for a complete point. Omitted/ |
None
|
z
|
float | None
|
Scalar z in units; omit for a complete point. Omitted/ |
None
|
frames
|
int
|
Duration in frames. Zero applies immediately only when no earlier tween is queued. |
60
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued group instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If a point is not a |
ValueError
|
If |
Source code in terminaltexteffects/engine/camera.py
orbit(axis='y', degrees=None, *, around=g3.ORIGIN, turns=None, up='y', frames=None, ease=None, together=False)
Turn the eye around a world axis through around, keeping it aimed there.
Supply degrees or turns (default one turn), and frames to queue it. The target
is sampled at the start. Without concurrent edits, the radius stays constant.
up sets the aiming roll; at poles the previous right axis supplies it.
Raises ValueError for both angle forms, invalid directions, negative frames or zero radius.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
Axis
|
World axis name or nonzero |
'y'
|
degrees
|
float | None
|
Signed angle in degrees. |
None
|
around
|
SpatialNode | Vec3 | tuple[float, float, float]
|
World |
ORIGIN
|
turns
|
float | None
|
Signed full turns, as an alternative to degrees. Defaults to one turn if neither is supplied. |
None
|
up
|
Axis
|
Nonzero world |
'y'
|
frames
|
int | None
|
|
None
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued group instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both angle forms are supplied, an axis or up direction is invalid, frames is negative, or the sampled target is at the eye when the action begins. |
Source code in terminaltexteffects/engine/camera.py
pan(degrees, *, frames=None, ease=None, together=False)
Yaw about local +y, now or over frames; positive angles turn the view left.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
degrees
|
float
|
Signed angle in degrees. |
required |
frames
|
int | None
|
|
None
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued group instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/camera.py
pedestal(amount, *, frames=None, ease=None, together=False)
Move up amount columns, now or over frames, along the starting local axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
float
|
Signed travel in units along the named camera-local direction. |
required |
frames
|
int | None
|
|
None
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued group instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/camera.py
reset()
Cancel animations and restore the settings and pose the world created the camera with.
The perspective stays as set_perspective last set it.
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Source code in terminaltexteffects/engine/camera.py
roll(degrees, *, frames=None, ease=None, together=False)
Turn about local +z, now or over frames; positive angles rotate the camera counterclockwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
degrees
|
float
|
Signed angle in degrees. |
required |
frames
|
int | None
|
|
None
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued group instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/camera.py
set_perspective(strength=1.0)
Set how strongly depth shrinks things, now: 1 is natural, larger exaggerates depth, 0 is orthographic.
The eye's reference distance becomes 120 / strength (120 when orthographic) and focal length follows it, so
the z = 0 plane keeps its size at any strength. An explicitly positioned eye stays where it is. reset
keeps the perspective set here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strength
|
float
|
Perspective strength; 0 or more, and less than 120 divided by |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/camera.py
set_position(x=0, y=None, z=None)
Set the eye's world position, now, without changing distance or focal length.
Do not combine a complete point with y or z; mixed forms raise TypeError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float | Point3
|
Absolute world position as a |
0
|
y
|
float | None
|
Scalar y in units; omit for a complete point. Omitted/ |
None
|
z
|
float | None
|
Scalar z in units; omit for a complete point. Omitted/ |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If a point is not a |
Source code in terminaltexteffects/engine/camera.py
set_rotation(rotation=None)
Set the world orientation, now; None restores the -z view direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rotation
|
Rotation | None
|
Target world orientation; |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Source code in terminaltexteffects/engine/camera.py
tilt(degrees, *, frames=None, ease=None, together=False)
Pitch about local +x, now or over frames; positive angles look upward.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
degrees
|
float
|
Signed angle in degrees. |
required |
frames
|
int | None
|
|
None
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued group instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/camera.py
truck(amount, *, frames=None, ease=None, together=False)
Move right amount columns, now or over frames, along the starting local axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
float
|
Signed travel in units along the named camera-local direction. |
required |
frames
|
int | None
|
|
None
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued group instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/camera.py
turn_to(rotation, frames=60, ease=None, *, together=False)
Queue the shortest turn to a world orientation, preserving concurrent rotation deltas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rotation
|
Rotation
|
Target world orientation as a |
required |
frames
|
int
|
Duration in frames. Zero applies immediately only when no earlier tween is queued. |
60
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued group instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/camera.py
zoom(factor)
Multiply focal length by positive factor, now; orthographic size is unaffected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor
|
float
|
Positive multiplier of the current focal length. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/camera.py
zoom_to(focal, frames=60, ease=None, *, together=False)
Queue a positive absolute focal length, composing multiplicatively with immediate zooms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
focal
|
float
|
Positive target focal length in units. |
required |
frames
|
int
|
Duration in frames. Zero applies immediately only when no earlier tween is queued. |
60
|
ease
|
EasingFunction | None
|
Easing function, or |
None
|
together
|
bool
|
Play alongside the last queued group instead of after it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Camera |
Camera
|
This camera, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/camera.py
Queued animations for bodies and the camera, played one frame at a time by the world.
A tween applies its change as a delta each frame, so tweens compose with immediate changes and with each other: a
spin keeps turning a body the effect is also nudging. Tweens queue one after another, or play alongside the last
group with together=True. A tween with frames=0 applies at once if nothing is queued ahead of it.
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.
Tween
dataclass
Bases: Generic[_Owner]
One queued animation. apply receives the previous and current eased progress.
Source code in terminaltexteffects/engine/tweens.py
advance()
Play one frame, or the whole tween when it has no frames.
Source code in terminaltexteffects/engine/tweens.py
TweenQueue
The queue of tweens a body or the camera plays, one frame per world step.
Source code in terminaltexteffects/engine/tweens.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
animating
property
Whether tweens are queued or playing.
cancel()
Discard queued tweens and their callbacks, keeping the current pose.
Returns:
| Name | Type | Description |
|---|---|---|
TweenQueue |
_Queue
|
This object, for chaining. |
Source code in terminaltexteffects/engine/tweens.py
hold(frames)
Queue a pause of frames frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frames
|
int
|
Number of frames to pause; must not be negative. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TweenQueue |
_Queue
|
This object, for chaining. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/tweens.py
on_complete(callback)
Call callback(self) when the most recently queued tween finishes, or now if nothing is queued.
In the world's step, callbacks run once every body and the camera have moved, so a callback that changes what characters do sees the final pose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable
|
Called with this object when the tween finishes. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TweenQueue |
_Queue
|
This object, for chaining. |
Source code in terminaltexteffects/engine/tweens.py
on_group_complete(callback)
Call callback(self) when the last queued group finishes, or now if none is queued.
Groups added after this call don't delay it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable
|
Called with this object when the group finishes. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TweenQueue |
_Queue
|
This object, for chaining. |
Source code in terminaltexteffects/engine/tweens.py
direction(value, names, kind)
Return value as a unit vector, looking names up in names.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/tweens.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 |
Source code in terminaltexteffects/engine/tweens.py
How a character is seen: its cell, depth, which way its surface faces, and how lit it is.
view = character.view
if view.facing:
character.animation.set_appearance(symbol, gradient.get_color_at_fraction(view.light))
Readings are worked out on the first read after the world steps, from the character's place in the world, the camera and the light, so they work for any character on any body.
Classes:
| Name | Description |
|---|---|
View |
The readings for one character. |
View
How a character is seen from the camera, read through character.view.
Readings follow the character's surface: the outward normal of its parent's surface where it sits. A character
on a body without a surface, free in the world or on world.screen has no normal, so it counts as facing the
camera and fully lit.
Attributes:
| Name | Type | Description |
|---|---|---|
cell |
Coord
|
The cell the character projects onto. |
depth |
float
|
Distance from the eye along the camera's view axis, in units. Smaller is nearer. |
nearness |
float
|
1 at the nearest point its parent body reaches at its size, 0 at the farthest. |
facing |
bool
|
Whether its surface faces the camera. |
facing_amount |
float
|
-1 facing directly away, 0 edge-on, 1 facing the camera. |
light |
float
|
How directly its surface faces the light, from 0 to 1. |
face |
str | int | None
|
The face of its parent's surface it is on, as |
projected |
bool
|
Whether the character is in front of the camera's near plane. While it isn't, it is hidden and the other readings keep their last values. |
Source code in terminaltexteffects/engine/view.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
cell
property
The cell the character projects onto.
depth
property
Distance from the eye along the camera's view axis, in units. Smaller is nearer.
face
property
The face of its parent's surface it is on, or None.
facing
property
Whether its surface faces the camera.
facing_amount
property
-1 facing directly away, 0 edge-on, 1 facing the camera.
light
property
How directly its surface faces the light, from 0 to 1.
nearness
property
1 at the nearest point its parent body reaches at its size, 0 at the farthest.
projected
property
Whether the character is in front of the camera's near plane.
__init__(character)
Create the readings for a character. Use character.view.
Source code in terminaltexteffects/engine/view.py
Shapes for bodies: the geometry a body is drawn with, and the surface characters sit on.
Sizes are in units. One unit is the width of a terminal cell; a row is two units tall, so a cube 10 units on every side looks square on screen, about 10 cells wide and 5 rows tall.
cube = terminal.world.body(Cube(16))
cube.surface.face("front").layout_text(characters)
Classes:
| Name | Description |
|---|---|
Shape |
The base class: |
Plane |
A flat rectangle facing +z, an open grid of cells like the text plane. |
Box, Cube, Prism, Pyramid, Cylinder, Sphere, Torus |
Shapes with surfaces. |
Tetrahedron, Octahedron, Icosahedron |
Shapes without surfaces yet. |
Box
dataclass
Bases: Shape
A box. Faces are tagged 0 front, 1 right, 2 back, 3 left, 4 top, 5 bottom.
Attributes:
| Name | Type | Description |
|---|---|---|
width |
float
|
Width along x, in columns. Defaults to 16. |
height |
float
|
Height along y, in columns. Defaults to 16. |
depth |
float
|
Depth along z, in columns. Defaults to 16. |
Source code in terminaltexteffects/engine/shapes.py
build_mesh()
Return the box mesh.
Returns:
| Type | Description |
|---|---|
Mesh
|
g3.Mesh: The shape's mesh in local coordinates, centered on the origin. |
build_surface()
Return the box's surface: columns around the sides from the left edge of the front, then the caps.
Returns:
| Name | Type | Description |
|---|---|---|
ExtrudedSurface |
ExtrudedSurface
|
Faces |
Source code in terminaltexteffects/engine/shapes.py
texture_cell(fragment)
Return the text cell for a fragment. Each face shows the text from its own top left corner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fragment
|
Fragment
|
Rasterized surface fragment whose texture coordinates are sampled. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float] | None
|
tuple[float, float] | None: Fractional text (column, row), or |
Source code in terminaltexteffects/engine/shapes.py
Cube
dataclass
Bases: Shape
A cube size columns wide.
Attributes:
| Name | Type | Description |
|---|---|---|
size |
float
|
Edge length in columns. Defaults to 16. |
Source code in terminaltexteffects/engine/shapes.py
build_mesh()
Return the cube mesh.
Returns:
| Type | Description |
|---|---|
Mesh
|
g3.Mesh: The shape's mesh in local coordinates, centered on the origin. |
build_surface()
Return the cube's surface: columns around the sides from the left edge of the front, then the caps.
Returns:
| Name | Type | Description |
|---|---|---|
ExtrudedSurface |
ExtrudedSurface
|
Faces |
Source code in terminaltexteffects/engine/shapes.py
texture_cell(fragment)
Return the text cell for a fragment. Each face shows the text from its own top left corner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fragment
|
Fragment
|
Rasterized surface fragment whose texture coordinates are sampled. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float] | None
|
tuple[float, float] | None: Fractional text (column, row), or |
Source code in terminaltexteffects/engine/shapes.py
Cylinder
dataclass
Bases: Shape
An upright cylinder around the y axis. wrap lays text around its side.
Attributes:
| Name | Type | Description |
|---|---|---|
radius |
float
|
Radius of the side, in columns. Defaults to 10. |
height |
float
|
Height along y, in columns. Defaults to 12. |
segments |
int
|
Number of mesh sides, at least 3. Defaults to 32. |
Source code in terminaltexteffects/engine/shapes.py
build_mesh()
Return the cylinder mesh.
Returns:
| Type | Description |
|---|---|
Mesh
|
g3.Mesh: The shape's mesh in local coordinates, centered on the origin. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/shapes.py
build_surface()
Return the cylinder's surface: columns around the side from the left edge of the front quarter.
Returns:
| Name | Type | Description |
|---|---|---|
ExtrudedSurface |
ExtrudedSurface
|
Faces |
Source code in terminaltexteffects/engine/shapes.py
texture_cell(fragment)
Return the text cell for a fragment, starting at the left edge of the front. Caps have none.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fragment
|
Fragment
|
Rasterized surface fragment whose texture coordinates are sampled. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float] | None
|
tuple[float, float] | None: Fractional text (column, row), or |
Source code in terminaltexteffects/engine/shapes.py
Icosahedron
dataclass
Bases: Shape
A regular icosahedron with its vertices radius from the center.
Attributes:
| Name | Type | Description |
|---|---|---|
radius |
float
|
Distance from the center to each vertex, in columns. Defaults to 10. |
Source code in terminaltexteffects/engine/shapes.py
build_mesh()
Return the icosahedron mesh.
Returns:
| Type | Description |
|---|---|
Mesh
|
g3.Mesh: The shape's mesh in local coordinates, centered on the origin. |
Octahedron
dataclass
Bases: Shape
A regular octahedron with its vertices radius from the center.
Attributes:
| Name | Type | Description |
|---|---|---|
radius |
float
|
Distance from the center to each vertex, in columns. Defaults to 10. |
Source code in terminaltexteffects/engine/shapes.py
build_mesh()
Return the octahedron mesh.
Returns:
| Type | Description |
|---|---|
Mesh
|
g3.Mesh: The shape's mesh in local coordinates, centered on the origin. |
Plane
dataclass
Bases: Shape
A flat rectangle facing +z: an open grid of cells, like the text plane.
Its surface positions are (column, row, height) with columns from 1 to width and rows from 1 to height / 2,
numbered like the canvas from the bottom left, and centered on the body's origin. Characters can sit past its
edges, where the grid carries on.
Attributes:
| Name | Type | Description |
|---|---|---|
width |
float
|
Width along x, in units (columns). Defaults to 40. |
height |
float
|
Height along y, in units; a row is two. Defaults to 20. |
Source code in terminaltexteffects/engine/shapes.py
build_mesh()
Return the plane as one quad, textured from 0 to 1.
Returns:
| Type | Description |
|---|---|
Mesh
|
g3.Mesh: The shape's mesh in local coordinates, centered on the origin. |
Source code in terminaltexteffects/engine/shapes.py
build_surface()
Return the plane's grid: round(width) columns by round(height / 2) rows, centered on the origin.
Returns:
| Name | Type | Description |
|---|---|---|
PlaneSurface |
PlaneSurface
|
The surface, with one face, |
Source code in terminaltexteffects/engine/shapes.py
Prism
dataclass
Bases: Shape
An upright prism with sides rectangular sides around the y axis.
Attributes:
| Name | Type | Description |
|---|---|---|
sides |
int
|
Number of rectangular sides, at least 3. Defaults to 6. |
radius |
float
|
Distance from the y axis to each corner, in columns. Defaults to 10. |
height |
float
|
Height along y, in columns. Defaults to 12. |
Source code in terminaltexteffects/engine/shapes.py
build_mesh()
Return the prism mesh.
Returns:
| Type | Description |
|---|---|
Mesh
|
g3.Mesh: The shape's mesh in local coordinates, centered on the origin. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/shapes.py
build_surface()
Return the prism's surface. Columns start at the front corner; side 0 is the one to its right.
Returns:
| Name | Type | Description |
|---|---|---|
ExtrudedSurface |
ExtrudedSurface
|
Faces |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/shapes.py
texture_cell(fragment)
Return the text cell for a fragment, starting at the left edge of the front. Caps have none.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fragment
|
Fragment
|
Rasterized surface fragment whose texture coordinates are sampled. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float] | None
|
tuple[float, float] | None: Fractional text (column, row), or |
Source code in terminaltexteffects/engine/shapes.py
Pyramid
dataclass
Bases: Shape
A pyramid with a sides-sided base and its apex up the y axis.
Attributes:
| Name | Type | Description |
|---|---|---|
sides |
int
|
Number of base edges, at least 3. Defaults to 4. |
radius |
float
|
Distance from the y axis to each base corner, in columns. Defaults to 10. |
height |
float
|
Distance from base to apex, in columns. Defaults to 14. |
Source code in terminaltexteffects/engine/shapes.py
build_mesh()
Return the pyramid mesh.
Returns:
| Type | Description |
|---|---|
Mesh
|
g3.Mesh: The shape's mesh in local coordinates, centered on the origin. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/shapes.py
build_surface()
Return the pyramid's surface. Columns start at the front corner; side 0 is the one to its right.
Returns:
| Name | Type | Description |
|---|---|---|
PyramidSurface |
PyramidSurface
|
Faces |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/shapes.py
texture_cell(fragment)
Return the text cell for a fragment, starting at the left edge of the front. The base has none.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fragment
|
Fragment
|
Rasterized surface fragment whose texture coordinates are sampled. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float] | None
|
tuple[float, float] | None: Fractional text (column, row), or |
Source code in terminaltexteffects/engine/shapes.py
Shape
dataclass
Base class for body shapes. Sizes are in units: one unit is a column's width, and a row is two units tall.
A shape gives a body its geometry: a geometry3d.Mesh from build_mesh, for drawing, and a surface from
build_surface, a grid of cells for characters to sit on and travel over. Built-in shapes expect positive
dimensions, which are intentionally not validated. Zero or negative sizes can collapse faces or reverse winding;
shading, texture layouts and surfaces are not guaranteed for those sizes. Body scale, in contrast, is validated
and must remain positive.
Source code in terminaltexteffects/engine/shapes.py
build_mesh()
Return the shape's mesh, centered on the body's origin.
Returns:
| Type | Description |
|---|---|
Mesh
|
g3.Mesh: The shape's mesh in local coordinates, centered on the origin. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This base method must be implemented by a shape subclass. |
Source code in terminaltexteffects/engine/shapes.py
build_surface()
Return a new surface for a body of this shape, or None for shapes without one.
Returns:
| Type | Description |
|---|---|
Surface | None
|
Surface | None: The shape's grid of cells, centered on the body's origin. |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fragment
|
Fragment
|
Rasterized surface fragment whose texture coordinates are sampled. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float] | None
|
tuple[float, float] | None: Fractional text (column, row), or |
Source code in terminaltexteffects/engine/shapes.py
Sphere
dataclass
Bases: Shape
A sphere. wrap lays text over it between 60 degrees north and south.
Attributes:
| Name | Type | Description |
|---|---|---|
radius |
float
|
Radius in columns. Defaults to 10. |
segments |
int
|
Number of mesh slices around y, at least 3. Defaults to 24. |
rings |
int
|
Number of mesh bands from pole to pole, at least 2. Defaults to 12. |
Source code in terminaltexteffects/engine/shapes.py
build_mesh()
Return the sphere mesh.
Returns:
| Type | Description |
|---|---|
Mesh
|
g3.Mesh: The shape's mesh in local coordinates, centered on the origin. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/shapes.py
build_surface()
Return the sphere's surface: columns around from the left edge of the front quarter, rows pole to pole.
Returns:
| Name | Type | Description |
|---|---|---|
SphereSurface |
SphereSurface
|
The surface. A sphere has no faces. |
Source code in terminaltexteffects/engine/shapes.py
texture_cell(fragment)
Return the text cell for a fragment, starting at the left edge of the front, from pole to pole.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fragment
|
Fragment
|
Rasterized surface fragment whose texture coordinates are sampled. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float] | None
|
tuple[float, float] | None: Fractional text (column, row), or |
Source code in terminaltexteffects/engine/shapes.py
Tetrahedron
dataclass
Bases: Shape
A regular tetrahedron with its vertices radius from the center.
Attributes:
| Name | Type | Description |
|---|---|---|
radius |
float
|
Distance from the center to each vertex, in columns. Defaults to 10. |
Source code in terminaltexteffects/engine/shapes.py
build_mesh()
Return the tetrahedron mesh.
Returns:
| Type | Description |
|---|---|
Mesh
|
g3.Mesh: The shape's mesh in local coordinates, centered on the origin. |
Torus
dataclass
Bases: Shape
A torus lying around the y axis: a tube minor_radius thick, major_radius from the center.
Attributes:
| Name | Type | Description |
|---|---|---|
major_radius |
float
|
Distance from the hole center to the tube center, in columns. Defaults to 10. |
minor_radius |
float
|
Tube radius in columns. Defaults to 4. |
segments |
int
|
Number of sections around the hole, at least 3. Defaults to 36. |
sides |
int
|
Number of faces around each tube section, at least 3. Defaults to 18. |
Source code in terminaltexteffects/engine/shapes.py
build_mesh()
Return the torus mesh.
Returns:
| Type | Description |
|---|---|
Mesh
|
g3.Mesh: The shape's mesh in local coordinates, centered on the origin. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/shapes.py
build_surface()
Return the torus's surface: columns around the ring, rows around the tube. Both wrap.
Returns:
| Name | Type | Description |
|---|---|---|
TorusSurface |
TorusSurface
|
The surface. A torus has no faces. |
Source code in terminaltexteffects/engine/shapes.py
Surfaces: a grid of cells over a body's shape, for characters to sit on and travel over.
A shaped body's surface turns positions (column, row, height) into points in the body's own axes. Columns and
rows count cells, a column one unit wide and a row two units tall (TERMINAL_ROW_SCALE), as on the text plane.
Height is in units, outward from the surface.
Every closed shape except the torus uses the same layout, like a map of a globe:
- Columns go around the shape, starting at the front and increasing to the right as seen from outside.
- Rows go from the bottom pole to the top pole: across the bottom cap from its center out to its edge, up the sides, then across the top cap from its edge in to its center. Cells squeeze together toward the poles.
The torus wraps both ways: columns go around the ring, rows around the tube, starting at the outside equator and going up over the top. A plane is an open grid like the text plane: its cells carry on past its edges.
Positions are always normalized: column 70 on a surface 40 columns around is column 30, and a row past a pole comes back down the far side.
Characters travel over a closed surface along the shortest straight route (new_waypoint), or straight ahead by
an amount (Path.walk), crossing as many folds as it takes. Routes are worked out once, when a path is activated,
and cached by cell.
Classes:
| Name | Description |
|---|---|
Surface |
The common base: grid size, conversions, faces, random positions, targets and text layout. |
PlaneSurface |
A flat, open grid of cells. The text plane's surface. |
ExtrudedSurface |
A box, cube, prism or cylinder: a profile swept up the y axis and capped. |
PyramidSurface |
A pyramid: a polygon base and sloping sides meeting at the apex. |
SphereSurface |
A sphere, gridded by longitude and latitude. |
TorusSurface |
A torus, gridded around the ring and around the tube. |
Face |
One face of a surface, a flat grid of its own with the text the right way up. |
Route = tuple[tuple[XYZ, ...], tuple[float, ...]]
module-attribute
Points from a segment's start to its end in grid positions, unwrapped, and the distance travelled to each.
ExtrudedSurface
Bases: _PolyhedralSurface
A box, cube, prism or cylinder: a profile swept up the y axis, capped top and bottom.
Columns go around the sides, rows from the center of the bottom cap out to its edge, up the sides, and across
the top cap to its center. Each cap is reference / 2 rows deep, where reference is how far the sides are
from the axis (the nearest side of a box or prism, the radius of a cylinder), so a cap's rings are a row apart
along its narrowest spoke.
Heights are measured out from the body's center, so they stay continuous over the folds.
Source code in terminaltexteffects/engine/surfaces.py
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 | |
__init__(profile, height, *, side_names, facets=None)
Create the surface of a swept profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile
|
_Profile
|
The outline of the sides. |
required |
height
|
float
|
Height along y, in units. |
required |
side_names
|
Sequence[str | int]
|
Names for the faces of the sides, in column order. A cylinder has one. |
required |
facets
|
_Polygon | None
|
A polygon to find routes over, for a round profile. |
None
|
Source code in terminaltexteffects/engine/surfaces.py
random_coord()
Return a random position on the surface, spread evenly by area.
Source code in terminaltexteffects/engine/surfaces.py
Face
One face of a body's surface: a flat grid of its own, seen from outside with the text the right way up.
Cells are numbered from 1, like the canvas: columns from left to right, rows from bottom to top. A face
that isn't a rectangle (a triangle, a polygon, a disc) gets the smallest grid that covers it, and only the cells
whose centers are on the face count as on it: contains and row_extent say which.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str | int
|
The face's name on its surface. |
width |
int
|
Columns in the face's grid. |
height |
int
|
Rows in the face's grid. |
left |
int
|
The first column, 1. |
right |
int
|
The last column. |
bottom |
int
|
The first row, 1. |
top |
int
|
The last row. |
center_column |
int
|
The middle column (the lower one when there are two). |
center_row |
int
|
The middle row (the lower one when there are two). |
center |
Vec3
|
The surface position of the middle cell. |
Source code in terminaltexteffects/engine/surfaces.py
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 | |
center
property
The surface position of the middle cell.
at(column, row, height=0.0)
Return the surface position of a cell on this face, for waypoints, attach(at=) and set_coordinate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
int
|
Column in the face's grid. |
required |
row
|
int
|
Row in the face's grid. |
required |
height
|
float
|
Units out from the surface. |
0.0
|
Returns:
| Type | Description |
|---|---|
Vec3
|
g3.Vec3: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the cell isn't on the face. |
Source code in terminaltexteffects/engine/surfaces.py
contains(column, row)
Return whether a cell is on the face.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
int
|
Column in the face's grid. |
required |
row
|
int
|
Row in the face's grid. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Whether the cell's center is on the face. |
Source code in terminaltexteffects/engine/surfaces.py
layout_text(characters, overflow='extend')
Attach characters and lay them out flat on this face as the input reads, centered.
One character per cell, keeping the input's rows and columns; each row is centered within its extent on a face that isn't a rectangle. The text is never scaled or reflowed. Past the face's edge:
"extend": characters carry on across the surface beyond, in line, the waywalk()goes. On a plane they sit in its open grid."clip": characters past the edge aren't attached. They stay where they are and are returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
characters
|
Iterable[EffectCharacter]
|
The characters, in any order. Their input coordinates decide where each goes. |
required |
overflow
|
str
|
|
'extend'
|
Returns:
| Type | Description |
|---|---|
list[EffectCharacter]
|
list[EffectCharacter]: The characters that weren't placed, including any that would land on another. |
Raises:
| Type | Description |
|---|---|
ValueError
|
For an unknown |
Source code in terminaltexteffects/engine/surfaces.py
random_coord()
Return the surface position of a random cell on the face.
row_extent(row)
Return the first and last column of a row that are on the face, or None if none are.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row
|
int
|
Row in the face's grid. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int] | None
|
tuple[int, int] | None: The row's first and last column on the face. |
Source code in terminaltexteffects/engine/surfaces.py
PlaneSurface
Bases: Surface
A flat, open grid of cells, facing +z: the text plane's surface, and a Plane body's.
Cells are numbered from left and bottom, as on the canvas, and carry on past the edges. center_column and
center_row sit on the body's origin.
Attributes:
| Name | Type | Description |
|---|---|---|
left |
int
|
The first column. |
right |
int
|
The last column. |
bottom |
int
|
The first row. |
top |
int
|
The last row. |
center_column |
float
|
The column at the body's origin. |
center_row |
float
|
The row at the body's origin. |
Source code in terminaltexteffects/engine/surfaces.py
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 | |
center
property
The position at the body's origin.
faces
property
A plane has one face, "front": the whole grid.
__init__(left, right, bottom, top, *, center_column=None, center_row=None)
Create a plane's grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
int
|
The first column. |
required |
right
|
int
|
The last column. |
required |
bottom
|
int
|
The first row. |
required |
top
|
int
|
The last row. |
required |
center_column
|
float | None
|
The column at the body's origin. Defaults to the middle. |
None
|
center_row
|
float | None
|
The row at the body's origin. Defaults to the middle. |
None
|
Source code in terminaltexteffects/engine/surfaces.py
random_coord()
Return a random position within the plane's edges.
PyramidSurface
Bases: _PolyhedralSurface
A pyramid: a polygon base and sloping sides meeting at the apex, up the y axis.
Columns go around the base's edge. Rows go from the center of the base out to its edge, then up the sides to the apex, which is the top pole.
Source code in terminaltexteffects/engine/surfaces.py
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 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 | |
__init__(polygon, height)
Create a pyramid's surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygon
|
_Polygon
|
The base, centered on the axis. |
required |
height
|
float
|
From base to apex, in units. |
required |
Source code in terminaltexteffects/engine/surfaces.py
SphereSurface
Bases: Surface
A sphere, gridded like a globe: columns around the equator, rows from the south pole to the north pole.
The grid has 2 * pi * radius columns, so cells are a unit wide at the equator, and pi * radius / 2 rows.
Routes follow great circles.
Source code in terminaltexteffects/engine/surfaces.py
1392 1393 1394 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 | |
__init__(radius)
Create a sphere's surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius in units. |
required |
Source code in terminaltexteffects/engine/surfaces.py
random_coord()
Return a random position on the sphere, spread evenly by area.
Source code in terminaltexteffects/engine/surfaces.py
Surface
A grid of cells over a body's shape. Made with the body: world.body(shape).surface.
Positions are (column, row, height): columns and rows in cells, height in units, outward from the surface.
Attributes:
| Name | Type | Description |
|---|---|---|
columns |
float
|
How many columns the grid has: around a closed shape, across a plane. |
rows |
float
|
How many rows: pole to pole on a closed shape, around the tube of a torus, up a plane. |
closed |
bool
|
Whether the grid joins up with itself. Only a plane's doesn't. |
center |
Vec3
|
The position at the front of the shape, half way up. |
faces |
tuple[str | int, ...]
|
The names |
Source code in terminaltexteffects/engine/surfaces.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 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 | |
center
property
The position at the front of the shape, half way up.
faces
property
The names face() takes.
face(name)
Return one face of the surface, a flat grid of its own with the text the right way up.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | int
|
The face, from |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Face |
Face
|
The face. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the surface has no face of that name. |
Source code in terminaltexteffects/engine/surfaces.py
layout_text(characters, overflow='extend')
Attach characters and lay them out around the surface as the input reads, centered on center.
One character per cell, keeping the input's rows and columns. On a closed shape, text too wide to go round
without lapping its own start, or too tall to fit pole to pole, isn't placed. On a plane, overflow says
what happens past the edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
characters
|
Iterable[EffectCharacter]
|
The characters, in any order. Their input coordinates decide where each goes. |
required |
overflow
|
str
|
|
'extend'
|
Returns:
| Type | Description |
|---|---|
list[EffectCharacter]
|
list[EffectCharacter]: The characters that weren't placed. |
Raises:
| Type | Description |
|---|---|
ValueError
|
For an unknown |
Source code in terminaltexteffects/engine/surfaces.py
locate(point)
Return the surface position of a point in the body's own axes. The reverse of point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
Point3
|
A point in the body's axes, in units. |
required |
Returns:
| Type | Description |
|---|---|
Vec3
|
g3.Vec3: |
Source code in terminaltexteffects/engine/surfaces.py
normalize(position)
Return a position in its normal form: column within the grid, row within pole to pole.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
Point3
|
|
required |
Returns:
| Type | Description |
|---|---|
Vec3
|
g3.Vec3: The same place on the surface, normalized. |
Source code in terminaltexteffects/engine/surfaces.py
point(column, row=None, height=None)
Return a surface position as a point in the body's own axes, and the outward normal there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
float | Point3
|
Column on the grid, or a whole |
required |
row
|
float | None
|
Row on the grid. |
None
|
height
|
float | None
|
Units out from the surface. Defaults to 0. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Vec3, Vec3]
|
tuple[g3.Vec3, g3.Vec3]: The point, in units, and the unit normal. |
Source code in terminaltexteffects/engine/surfaces.py
random_coord()
Return a random position on the surface, spread evenly by area rather than by cell.
target(column, row=None, height=None)
Return a live target for waypoints: this surface position, followed as the body moves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
float | Point3
|
Column on the grid, or a whole |
required |
row
|
float | None
|
Row on the grid. |
None
|
height
|
float | None
|
Units out from the surface. Defaults to 0. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
SurfaceTarget |
SurfaceTarget
|
A node a path can head for. It stays on its spot as the body moves, turns and scales. |
Source code in terminaltexteffects/engine/surfaces.py
world_point(column, row=None, height=None)
Return where a surface position is in the world right now.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
float | Point3
|
Column on the grid, or a whole |
required |
row
|
float | None
|
Row on the grid. |
None
|
height
|
float | None
|
Units out from the surface. Defaults to 0. |
None
|
Returns:
| Type | Description |
|---|---|
Vec3
|
g3.Vec3: The world point. |
Source code in terminaltexteffects/engine/surfaces.py
TorusSurface
Bases: Surface
A torus lying around the y axis, gridded around the ring and around the tube. Both wrap.
Columns go around the ring, starting at the left edge of the front quarter, sized at the middle of the tube. Rows go around the tube, starting at the outside equator and going up over the top. Heights are along the tube's normal.
Source code in terminaltexteffects/engine/surfaces.py
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 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 | |
center
property
The position at the front of the ring, on the outside equator.
__init__(major_radius, minor_radius)
Create a torus's surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
major_radius
|
float
|
From the center of the hole to the center of the tube, in units. |
required |
minor_radius
|
float
|
The tube's radius, in units. |
required |
Source code in terminaltexteffects/engine/surfaces.py
random_coord()
Return a random position on the torus, spread evenly by area.
Source code in terminaltexteffects/engine/surfaces.py
Drawing bodies: looks for their faces, and painting them in one depth order with the characters.
cube = world.body(Cube(16))
cube.draw(Shaded()) # or Solid(), Textured(), Wireframe()
cube.draw(faces={"front": Textured(), "top": Solid("#")})
A drawn body is shown with characters the world creates and manages, one per covered cell, so an effect's own characters are never used for it. Drawn cells and characters are painted in one order: by layer, then farther first, so the nearest wins each cell. A character sitting on its body's surface (height 0) and facing the camera draws over that body's own cell beneath it, like a decal, and anything genuinely in front of it still hides it.
Classes:
| Name | Description |
|---|---|
Shaded, Solid, Textured, Wireframe |
Looks for drawing a body. |
Look = typing.Union[Shaded, Solid, Textured, Wireframe]
module-attribute
How a body is drawn: Shaded, Solid, Textured or Wireframe.
Painter
Draws a world's drawn bodies with pooled characters, once per frame after the characters move.
Source code in terminaltexteffects/engine/drawing.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | |
input_text
property
The effect's input text, top line first, as Textured looks wrap it by default.
terminal
property
The terminal the pooled characters belong to.
hide(body)
Hide a body's cells now, for a body that stops being drawn or leaves the world.
Source code in terminaltexteffects/engine/drawing.py
paint()
Draw every drawn body into one depth buffer and show it with the pooled characters.
Source code in terminaltexteffects/engine/drawing.py
pair(color)
Return a shared foreground ColorPair for color, so unchanged cells can be spotted by identity.
Source code in terminaltexteffects/engine/drawing.py
surface_characters()
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. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/drawing.py
__post_init__()
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/drawing.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]
|
|
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. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in terminaltexteffects/engine/drawing.py
__post_init__()
Validate texture sampling settings.
Source code in terminaltexteffects/engine/drawing.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/drawing.py
depth_order(depth, distance)
Return the order within a layer at depth: nearer than the text plane paints later, farther earlier.