I'm attempting to place multiple DecimalNumber
s in Manim, each with a random starting value, so that when I use a ValueTracker
on each of them they will seemingly output arbitrary arrangements. Yet when I implement this code:
all_d, all_t = [], []
for tile in tiles:
start_number = random()
k = ValueTracker(start_number)
updateFunction = lambda i: i.set_value(k.get_value())
d = DecimalNumber(num_decimal_places=2).add_updater(updateFunction)
d.move_to(tile)
all_d.append(d)
all_t.append(k)
print([k.get_value() for k in all_t]) # OUTPUT ValueTracker starting values
self.play(*[Create(d) for d in all_d])
self.play(*[k.animate.set_value(0) for k in all_t], run_time = 5)
The print statement outputs random numbers:
[0.27563412131212717,..., 0.9962578393535727]
, but all of the DecimalNumber
s on the screen output the same value, starting with 1.00 and ending with 0.00 synchronously. And if I add the same print statement after all of my code, it results in all 0's: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
.
I've tried adding: k.set_value(start_number)
after initializing the ValueTracker
, but that proved fruitless. I've also tried using this code instead:
all_d, all_t = [], []
for i, tile in enumerate(tiles):
start_number = random()
d = DecimalNumber(num_decimal_places=2)
d.move_to(tile)
all_d.append((i, d, start_number))
all_t.append(ValueTracker(start_number))
self.play(*[all_t[i].animate.set_value(start_number + 1) for i, _, start_number in all_d],
*[UpdateFromFunc(d, lambda m: m.set_value(all_t[i].get_value())) for i, d, _ in all_d],
run_time = 5)
But all of them still match up, and they go from 1.00 to 2.00.
How can I remedy this?