Allow frame delays to be overridden

This commit is contained in:
polyfloyd 2017-10-07 23:03:06 +02:00
parent 02274c9a7c
commit 587598e8c5
2 changed files with 48 additions and 39 deletions

View file

@ -36,10 +36,13 @@ class Nyancat(object):
def __init__(self, width, height):
self.width = width
self.height = height
self.frame_index = 0
self.sparkles = []
def render(self):
for anim_frame in anim_cat:
self.frame_index = (self.frame_index + 1) % len(anim_cat)
anim_frame = anim_cat[self.frame_index]
if len(self.sparkles) < 32:
self.sparkles.append(Sparkle(self.width, self.height))
@ -82,6 +85,9 @@ class Nyancat(object):
self.sparkles = list(filter(lambda sp: sp.frame_index < len(anim_sparkle), self.sparkles))
sys.stdout.buffer.write(frame)
self.sleep()
def sleep(self):
time.sleep(1 / 30)
def plot_tail(self, width):

View file

@ -31,3 +31,6 @@ class NyancatSignal(Nyancat):
for x in range(width):
amplitude = sum(map(lambda hist: hist[x * WAVE_FACTOR], self.samples_history)) / len(self.samples_history) * 3
yield int((amplitude * .5 - .5) * self.height) + self.height
def sleep(self):
pass # Handled by a blocking read from the audio source