octarine.Animation#
octarine.Animation #
A timeline of camera moves that can be played or rendered to a video.
Segments are appended one after the other; each starts where the previous one ended, so a timeline reads much like the animation itself:
anim = oc.Animation(v) # doctest: +SKIP anim.orbit(duration=6) # one turn around the scene anim.move_to("XZ", duration=2) # swing round to the lateral view anim.hold(1) # ... and stay there for a second anim.render("tour.mp4")
| PARAMETER | DESCRIPTION |
|---|---|
viewer | TYPE: |
fps | TYPE: |
Source code in octarine/anim_utils.py
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 | |
current_state property #
Camera state the next segment will start from.
duration property #
Length of the animation in seconds.
n_frames property #
Number of frames this animation renders to.
playing property #
Whether the animation is currently being played in the viewer.
clear() #
Remove all segments.
Source code in octarine/anim_utils.py
514 515 516 517 518 519 | |
hold(duration) #
Stay on the current view for duration seconds.
Source code in octarine/anim_utils.py
539 540 541 542 | |
move_to(view=None, *, duration=2, easing='in_out', path='arc') #
Move the camera to another view.
| PARAMETER | DESCRIPTION |
|---|---|
view | TYPE: |
duration | TYPE: |
easing | TYPE: |
path | TYPE: |
Source code in octarine/anim_utils.py
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 | |
orbit(objects=None, *, turns=1, duration=6, axis='up', recenter=True, scale=1.0, easing='linear') #
Circle the camera around object(s).
| PARAMETER | DESCRIPTION |
|---|---|
objects | TYPE: |
turns | TYPE: |
duration | TYPE: |
axis | TYPE: |
recenter | TYPE: |
scale | TYPE: |
easing | TYPE: |
Source code in octarine/anim_utils.py
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 | |
play(loop=False, speed=1.0) #
Play the animation in the viewer.
Playback is driven by the viewer's animation loop and follows the wall clock, so it runs at the same speed no matter the frame rate (see Viewer.max_fps if it looks choppy).
| PARAMETER | DESCRIPTION |
|---|---|
loop | TYPE: |
speed | TYPE: |
Source code in octarine/anim_utils.py
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 | |
recorder(filename=None, **kwargs) #
Return a Recorder that renders this animation frame by frame.
Use this instead of Animation.render when you need to keep control between frames - the controls panel drives one of these off a timer to keep the GUI responsive while recording.
Source code in octarine/anim_utils.py
718 719 720 721 722 723 724 725 726 | |
render(filename=None, *, fps=None, size=None, pixel_ratio=None, alpha=False, supersample=1, restore=True, progress=True) #
Render the animation.
| PARAMETER | DESCRIPTION |
|---|---|
filename | TYPE: |
fps | TYPE: |
size | TYPE: |
pixel_ratio | TYPE: |
alpha | TYPE: |
supersample | TYPE: |
restore | TYPE: |
progress | TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
list of numpy arrays | If |
pathlib.Path | The file (or directory) written to, otherwise. |
Source code in octarine/anim_utils.py
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 | |
set_time(t) #
Apply the animation's state at time t (in seconds).
Source code in octarine/anim_utils.py
654 655 656 657 658 | |
start_at(view=None) #
Set the view the timeline starts from, without animating to it.
| PARAMETER | DESCRIPTION |
|---|---|
view | TYPE: |
Source code in octarine/anim_utils.py
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 | |
stop() #
Stop playback (see Animation.play).
Source code in octarine/anim_utils.py
706 707 708 709 710 711 | |
times(fps=None) #
Times (in seconds) of the frames this animation renders to.
The last frame stops one frame short of the end so that a full turn loops seamlessly.
Source code in octarine/anim_utils.py
660 661 662 663 664 665 666 667 668 | |
zoom(factor=2, *, duration=2, easing='in_out') #
Zoom in (factor > 1) or out (factor < 1) on the current view.
Source code in octarine/anim_utils.py
632 633 634 635 636 637 638 639 640 641 642 643 644 | |
octarine.anim_utils.EASINGS = {'linear': lambda t: t, 'in': lambda t: t * t, 'out': lambda t: 1 - (1 - t) ** 2, 'in_out': _smoothstep, 'smooth': lambda t: _smoothstep(_smoothstep(t))} module-attribute #
octarine.anim_utils.Recorder #
Renders an animation one frame at a time.
Instantiating a recorder starts the recording (it resizes the canvas and opens the output file); each step renders and writes the next frame and returns False once there are none left; finish closes the output and returns it. Animation.render simply runs this to completion - drive it yourself if you need to do something between frames (e.g. keep a GUI responsive).
octarine.anim_utils.Segment #
A piece of a track, covering [start, start + duration).
Subclass this to animate something new: implement apply and add the segments to a Track on an Animation. Segments must be able to render any point in their time range without having seen the ones before it.