<commit_before>import glob
import os
import random
import shutil

from mayavi import mlab
from tvtk.api import tvtk
from tvtk.tools import visual

from camera import Camera


class AnimationException(Exception):

    def __init__(self):
        raise self

class StopAnimation(AnimationException):
    
    """Stop the animation.
    Can be instanciated inside any animator callback to immediately end the
    animation.
    """

    pass

class Stop(AnimationException):
    
    """Stop the current animator.
    Note that this will not terminate the animation (see StopAnimation).
    """

    pass

class StopAndRemove(AnimationException):
    
    """Stop the current animator and remove the current object from the scene.
    Note that this will not terminate the animation (see StopAnimation).
    """

    pass



class Animation(object):
    
    """Base class for custom animations.
    An animation is a sequence of frames, which in turn consist of objects.
    Objects can be added to or removed from the scene at any point of the
    animation. When adding an object, an associated animator can be supplied.
    This animator, which defines the behavior of the object along the
    animation, will be automatically called for each frame. If no animator is
    provided, a default animator that (typically) leaves the object still
    will be chosen. Also, a frame callback controlling the global behavior of
    the animation will be called frame after frame.
    """

    def __init__(self, width, height):
        figure = mlab.figure(size=(width, height))
        visual.set_viewer(figure)
        
        self.width = width
        self.height = height
        
        self.camera = Camera()
        
        self.frame_callbacks = [self.on_frame]
        self.obj_animations = dict()

    def _add_actor(self, actor):
        viewer = visual.get_viewer()
        # Avoiding mlab.add_actor since it resets the zoom.
        viewer.scene.add_actors(actor)

    def _remove_actor(self, actor):
        viewer = visual.get_viewer()<commit_msg>* Added background color option to animations.<commit_after>import glob
import os
import random
import shutil

from mayavi import mlab
from tvtk.api import tvtk
from tvtk.tools import visual

from camera import Camera


class AnimationException(Exception):

    def __init__(self):
        raise self

class StopAnimation(AnimationException):
    
    """Stop the animation.
    Can be instanciated inside any animator callback to immediately end the
    animation.
    """

    pass

class Stop(AnimationException):
    
    """Stop the current animator.
    Note that this will not terminate the animation (see StopAnimation).
    """

    pass

class StopAndRemove(AnimationException):
    
    """Stop the current animator and remove the current object from the scene.
    Note that this will not terminate the animation (see StopAnimation).
    """

    pass



class Animation(object):
    
    """Base class for custom animations.
    An animation is a sequence of frames, which in turn consist of objects.
    Objects can be added to or removed from the scene at any point of the
    animation. When adding an object, an associated animator can be supplied.
    This animator, which defines the behavior of the object along the
    animation, will be automatically called for each frame. If no animator is
    provided, a default animator that (typically) leaves the object still
    will be chosen. Also, a frame callback controlling the global behavior of
    the animation will be called frame after frame.
    """

    def __init__(self, width, height, bgcolor=None):
        figure = mlab.figure(size=(width, height), bgcolor=bgcolor)
        visual.set_viewer(figure)
        
        self.width = width
        self.height = height
        
        self.camera = Camera()
        
        self.frame_callbacks = [self.on_frame]
        self.obj_animations = dict()

    def _add_actor(self, actor):
        viewer = visual.get_viewer()
        # Avoiding mlab.add_actor since it resets the zoom.
        viewer.scene.add_actors(actor)

    def _remove_actor(self, actor):
        viewer = visual.get_viewer()
{'fraction_non_alphanumeric': 0.062649450023912, 'fraction_numerical': 0.0, 'mean_word_length': 2.8803339517625233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2451269', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1063, 'n_words': 457}