mirror of
https://github.com/polyfloyd/ledcat-nyancat.git
synced 2025-07-04 16:20:09 +02:00
Allow frame delays to be overridden
This commit is contained in:
parent
02274c9a7c
commit
587598e8c5
2 changed files with 48 additions and 39 deletions
|
@ -36,10 +36,13 @@ class Nyancat(object):
|
||||||
def __init__(self, width, height):
|
def __init__(self, width, height):
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
|
self.frame_index = 0
|
||||||
self.sparkles = []
|
self.sparkles = []
|
||||||
|
|
||||||
def render(self):
|
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:
|
if len(self.sparkles) < 32:
|
||||||
self.sparkles.append(Sparkle(self.width, self.height))
|
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))
|
self.sparkles = list(filter(lambda sp: sp.frame_index < len(anim_sparkle), self.sparkles))
|
||||||
|
|
||||||
sys.stdout.buffer.write(frame)
|
sys.stdout.buffer.write(frame)
|
||||||
|
self.sleep()
|
||||||
|
|
||||||
|
def sleep(self):
|
||||||
time.sleep(1 / 30)
|
time.sleep(1 / 30)
|
||||||
|
|
||||||
def plot_tail(self, width):
|
def plot_tail(self, width):
|
||||||
|
|
|
@ -31,3 +31,6 @@ class NyancatSignal(Nyancat):
|
||||||
for x in range(width):
|
for x in range(width):
|
||||||
amplitude = sum(map(lambda hist: hist[x * WAVE_FACTOR], self.samples_history)) / len(self.samples_history) * 3
|
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
|
yield int((amplitude * .5 - .5) * self.height) + self.height
|
||||||
|
|
||||||
|
def sleep(self):
|
||||||
|
pass # Handled by a blocking read from the audio source
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue