Manim: REFACTOR : ValueTracker

Created on 3 Oct 2020  路  5Comments  路  Source: ManimCommunity/manim

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
  • ?
refactor

Most helpful comment

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

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nilaybhatia picture nilaybhatia  路  7Comments

kolibril13 picture kolibril13  路  5Comments

XorUnison picture XorUnison  路  6Comments

dakyion picture dakyion  路  8Comments

Davide95 picture Davide95  路  8Comments