[SOLVED] Arithmetic needed to animate a numeric counter
Posted: Sun Feb 20, 2022 5:47 pm
Hello boys. I have tried to implement an animated count similar to AnimatedValue(), but to animate numbers.
This is the code I have created:
I make it work like this:
The code runs the count in an animated way and it works fine, except for one thing. The time it should take to count from 0 to self.hit is given by self.delay , which is used to calculate the refresh interval in self.update_rate.
This should work fine, but the time it takes to get from 0 to self.hit isn't appropriate, and I'm very aware that it's a bug in the arithmetic I'm using to calculate the update interval.
The calculation runs on:
What I need at this point is some advice or help to find the correct calculation for this operation, since the code itself works correctly, except for the count delay.
I appreciate the help guys!
This is the code I have created:
Code: Select all
class AnimatedCounter:
def __init__(self, hit, delay):
self.hit = hit ## The value to be reached
self.delay = delay ## The time it takes to get from 0 to self.hit
self.update_rate = None ## Used to calculate the update interval
self.update_count = 0 ## The current count
def count(self, st, at):
if self.update_rate is None:
self.update_rate = self.delay / self.hit
if self.update_count < self.hit:
self.update_count += 1
return Text("%s" % self.update_count), self.update_rate
Code: Select all
screen anim_num(delay, hit):
default counter = AnimatedCounter(hit = hit, delay = delay)
add DynamicDisplayable(counter.count) align(0.5, 0.5)
This should work fine, but the time it takes to get from 0 to self.hit isn't appropriate, and I'm very aware that it's a bug in the arithmetic I'm using to calculate the update interval.
The calculation runs on:
Code: Select all
if self.update_rate is None:
self.update_rate = self.delay / self.hit
I appreciate the help guys!