2019-02-09 15:35:44 -08:00
|
|
|
import warnings
|
|
|
|
|
2018-12-24 12:37:51 -08:00
|
|
|
from manimlib.animation.animation import Animation
|
2019-02-09 15:35:44 -08:00
|
|
|
from manimlib.mobject.numbers import DecimalNumber
|
2018-12-24 12:37:51 -08:00
|
|
|
from manimlib.utils.bezier import interpolate
|
2018-03-31 18:49:28 -07:00
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-03-31 18:49:28 -07:00
|
|
|
class ChangingDecimal(Animation):
|
|
|
|
CONFIG = {
|
2019-02-09 15:35:44 -08:00
|
|
|
"suspend_mobject_updating": False,
|
2018-03-31 18:49:28 -07:00
|
|
|
}
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2019-02-09 15:35:44 -08:00
|
|
|
def __init__(self, decimal_mob, number_update_func, **kwargs):
|
|
|
|
self.check_validity_of_input(decimal_mob)
|
|
|
|
self.yell_about_depricated_configuration(**kwargs)
|
|
|
|
self.number_update_func = number_update_func
|
|
|
|
super().__init__(decimal_mob, **kwargs)
|
|
|
|
|
|
|
|
def check_validity_of_input(self, decimal_mob):
|
|
|
|
if not isinstance(decimal_mob, DecimalNumber):
|
|
|
|
raise Exception(
|
|
|
|
"ChangingDecimal can only take "
|
|
|
|
"in a DecimalNumber"
|
|
|
|
)
|
|
|
|
|
|
|
|
def yell_about_depricated_configuration(self, **kwargs):
|
|
|
|
# Obviously this would optimally be removed at
|
|
|
|
# some point.
|
|
|
|
for attr in ["tracked_mobject", "position_update_func"]:
|
|
|
|
if attr in kwargs:
|
|
|
|
warnings.warn("""
|
|
|
|
Don't use {} for ChangingDecimal,
|
|
|
|
that functionality has been depricated
|
|
|
|
and you should use a mobject updater
|
|
|
|
instead
|
|
|
|
""".format(attr)
|
|
|
|
)
|
2018-03-31 18:49:28 -07:00
|
|
|
|
2019-02-08 11:57:27 -08:00
|
|
|
def interpolate_mobject(self, alpha):
|
2019-02-09 15:35:44 -08:00
|
|
|
self.mobject.set_value(
|
2018-08-12 19:05:31 -07:00
|
|
|
self.number_update_func(alpha)
|
2018-03-31 18:49:28 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ChangeDecimalToValue(ChangingDecimal):
|
2019-02-09 15:35:44 -08:00
|
|
|
def __init__(self, decimal_mob, target_number, **kwargs):
|
|
|
|
start_number = decimal_mob.number
|
|
|
|
super().__init__(
|
|
|
|
decimal_mob,
|
|
|
|
lambda a: interpolate(start_number, target_number, a),
|
|
|
|
**kwargs
|
|
|
|
)
|