Animation
Module: terminaltexteffects.engine.animation
Animation handler for an EffectCharacter.
It contains a scene_name -> Scene mapping and the active Scene. Calls to step_animation() progress the Scene and apply the next visual to the character.
Attributes:
Name | Type | Description |
---|---|---|
scenes |
dict[str, Scene]
|
a mapping of scene IDs to Scene objects |
character |
EffectCharacter
|
the EffectCharacter object to animate |
active_scene |
Scene | None
|
the active Scene |
use_xterm_colors |
bool
|
whether to convert all colors to XTerm-256 colors |
no_color |
bool
|
whether to ignore colors |
existing_color_handling |
str
|
how to handle color ANSI sequences from the input data |
input_fg_color |
Color | None
|
the input foreground Color |
input_bg_color |
Color | None
|
the input background Color |
xterm_color_map |
dict[str, int]
|
a mapping of RGB color codes to XTerm-256 color codes |
active_scene_current_step |
int
|
the current step in the active Scene |
current_character_visual |
CharacterVisual
|
the current visual of the character |
Methods:
Name | Description |
---|---|
new_scene |
Creates a new Scene and adds it to the Animation. |
query_scene |
Returns a Scene from the Animation. |
active_scene_is_complete |
Returns whether the active scene is complete. |
set_appearance |
Applies a symbol and color to the character. |
adjust_color_brightness |
Adjusts the brightness of a given color. |
_ease_animation |
Returns the percentage of total distance that should be moved based on the easing function. |
step_animation |
Apply the next symbol in the scene to the character. |
activate_scene |
Activates a Scene. |
Source code in terminaltexteffects/engine/animation.py
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 |
|
__init__(character)
Initialize the Animation object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
character
|
EffectCharacter
|
the EffectCharacter object to animate |
required |
Source code in terminaltexteffects/engine/animation.py
activate_scene(scene)
Set the active scene and updates the current character visual.
A SCENE_ACTIVATED event is triggered.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scene
|
Scene
|
the Scene to set as active |
required |
Source code in terminaltexteffects/engine/animation.py
active_scene_is_complete()
Return whether the active scene is complete.
A scene is complete if all sequences have been played. Looping scenes are always complete.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if complete, False otherwise |
Source code in terminaltexteffects/engine/animation.py
adjust_color_brightness(color, brightness)
staticmethod
Adjust the brightness of a given color.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color
|
Color
|
The color code to adjust. |
required |
brightness
|
float
|
The brightness adjustment factor. |
required |
Returns:
Name | Type | Description |
---|---|---|
Color |
Color
|
The adjusted color code. |
Source code in terminaltexteffects/engine/animation.py
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 |
|
deactivate_scene(scene)
Deactivates a scene.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scene
|
Scene
|
the Scene to deactivate |
required |
new_scene(*, is_looping=False, sync=None, ease=None, scene_id='')
Create a new Scene and adds it to the Animation. If no ID is provided, a unique ID is generated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scene_id
|
str
|
Unique name for the scene. Used to query for the scene. |
''
|
is_looping
|
bool
|
Whether the scene should loop. |
False
|
sync
|
SyncMetric
|
The type of sync to use for the scene. |
None
|
ease
|
EasingFunction
|
The easing function to use for the scene. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Scene |
Scene
|
the new Scene |
Source code in terminaltexteffects/engine/animation.py
query_scene(scene_id)
Return a Scene from the Animation. If the scene doesn't exist, raises a ValueError.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scene_id
|
str
|
the ID of the Scene |
required |
Raises:
Type | Description |
---|---|
ValueError
|
if the Scene does not exist |
Returns:
Name | Type | Description |
---|---|---|
Scene |
Scene
|
the Scene |
Source code in terminaltexteffects/engine/animation.py
set_appearance(symbol, colors=None)
Update the current character visual with the symbol and colors provided.
If the character has an active scene, any appearance set with this method will be overwritten when the scene is stepped to the next frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
symbol
|
str
|
The symbol to apply. |
required |
colors
|
ColorPair | None
|
The colors to apply. |
None
|
Source code in terminaltexteffects/engine/animation.py
step_animation()
Progress the Scene and apply the next visual to the character.
If the active scene is complete, a SCENE_COMPLETE event is triggered.