Zeroistheoneq's picture
Create effects/text.py
34e0928 verified
Raw History Blame Contribute Delete
807 Bytes
from .base_effect import BaseEffect
from PIL import ImageFont
class ScrollingTextEffect(BaseEffect):
def __init__(self, text, width, height):
self.text = text
self.width = width
self.height = height
try:
self.font = ImageFont.truetype("assets/DejaVuSans.ttf", size=48)
except IOError:
self.font = ImageFont.load_default()
def draw(self, draw, current_time, audio_features):
if not self.text: return
text_width = draw.textlength(self.text, font=self.font)
x = self.width - ((current_time * 150) % (self.width + text_width))
y = self.height - 80
draw.text((x+2, y+2), self.text, font=self.font, fill=(0, 0, 0, 150))
draw.text((x, y), self.text, font=self.font, fill=(255, 255, 255, 220))