manim icon indicating copy to clipboard operation
manim copied to clipboard

ValueTracker: turn value into a property, replace get_value / set_value

Open huguesdevimeux opened this issue 5 years ago • 7 comments

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 ApplyMethod and not at other times.

In a nutshell :

  • getting rid of get_value and set_value in favor of a property;
  • Changing increment_value, maybe getting rid of it as we have now += operator for ValueTracker
  • ?

huguesdevimeux avatar Oct 03 '20 21:10 huguesdevimeux

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.

nilaybhatia avatar Oct 03 '20 21:10 nilaybhatia

That's an issue to solve. Maybe we can keep increment_value, then.

huguesdevimeux avatar Oct 05 '20 06:10 huguesdevimeux

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

nilaybhatia avatar Oct 07 '20 04:10 nilaybhatia

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 avatar Oct 07 '20 07:10 huguesdevimeux

@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.

leotrs avatar Nov 21 '20 23:11 leotrs

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.

behackl avatar May 15 '21 20:05 behackl

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)

friedkeenan avatar May 15 '21 21:05 friedkeenan