manim
manim copied to clipboard
ValueTracker: turn value into a property, replace get_value / set_value
ValueTracker needs a refactor. Quoting @leotrs :
there's many other things left to do. For example, get_value and set_value should all go away in favor of a property. And increment_value should be changed to also make use of that property, such that the code self.play(tracker.increment_value, 4.0) doesn't break.
AND THEN, there's the question of whether we even want self.play(tracker.increment_value, 4.0) to continue working at all. It's always been a mystery to me why sometimes you need
ApplyMethodand not at other times.
In a nutshell :
- getting rid of
get_valueandset_valuein favor of a property; - Changing
increment_value, maybe getting rid of it as we have now += operator for ValueTracker - ?
Question: After this refactor is done, how are users supposed to animate changing of values? Currently it is self.play(tracker.increment_value, 5.0). Won't removing increment_value break that? I don't think something like self.play(tracker += 5.0) can be achieved.
That's an issue to solve. Maybe we can keep increment_value, then.
I was just trying to use something like this without actually changing anything in the ValueTracker class. And I am surprised that it works. I don't understand why.
class Test(Scene):
def construct(self):
tracker = ValueTracker(0.0)
tracker.value = 5.0 # previously done using set_value
print(tracker.value) # previously using get_value
value is not even an attribute of ValueTracker
It's because in python,
object.field = value ~ setattr(object, 'field', value)
So if the attribute does not exist, it will create it.
(I learned this today as well lol, python has its surprises)
@huguesdevimeux @nilaybhatia so the To Do item here is to get rid of set_value and get_value and nothing else? I'd suggest adding a deprecation warning for now.
I think the value can be a property, but we should keep the set_value around to ensure we are still able to use the .animate syntax effectively.
I think the value can be a property, but we should keep the set_value around to ensure we are still able to use the .animate syntax effectively.
That's what Mobject.set is for, so you could do value_tracker.animate.set(value=1)