3b1b-manim/animation/animation.py

85 lines
1.6 KiB
Python
Raw Normal View History

2015-06-10 22:00:35 -07:00
from PIL import Image
from colour import Color
import numpy as np
import warnings
import time
import os
import progressbar
import inspect
from copy import deepcopy
2015-06-10 22:00:35 -07:00
from helpers import *
2015-11-23 10:34:42 -08:00
from mobject import Mobject
2015-06-10 22:00:35 -07:00
class Animation(object):
2016-02-27 16:32:53 -08:00
CONFIG = {
"run_time" : DEFAULT_ANIMATION_RUN_TIME,
"rate_func" : smooth,
"name" : None,
}
def __init__(self, mobject, **kwargs):
2015-10-20 21:55:46 -07:00
mobject = instantiate(mobject)
assert(isinstance(mobject, Mobject))
digest_config(self, kwargs, locals())
self.starting_mobject = self.mobject.copy()
if self.rate_func is None:
self.rate_func = (lambda x : x)
if self.name is None:
self.name = self.__class__.__name__ + str(self.mobject)
self.update(0)
2015-06-10 22:00:35 -07:00
def __str__(self):
return self.name
def copy(self):
return deepcopy(self)
2015-06-10 22:00:35 -07:00
def update(self, alpha):
if alpha < 0:
2015-06-27 04:49:10 -07:00
alpha = 0.0
2015-06-10 22:00:35 -07:00
if alpha > 1:
2015-06-27 04:49:10 -07:00
alpha = 1.0
self.update_mobject(self.rate_func(alpha))
2015-06-10 22:00:35 -07:00
def filter_out(self, *filter_functions):
self.filter_functions += filter_functions
return self
def set_run_time(self, time):
self.run_time = time
return self
def set_rate_func(self, rate_func):
if rate_func is None:
rate_func = lambda x : x
self.rate_func = rate_func
2015-06-10 22:00:35 -07:00
return self
def set_name(self, name):
self.name = name
return self
def update_mobject(self, alpha):
#Typically ipmlemented by subclass
pass
def clean_up(self):
2015-06-19 08:31:02 -07:00
self.update(1)
2015-06-10 22:00:35 -07:00
2015-06-27 04:49:10 -07:00
2015-06-10 22:00:35 -07:00