Spaces:
Build error
Build error
Download effects/text.py from Zeroistheoneq/Music_visualization: direct link, hf CLI and curl.
- Browser
- Download file 807 Bytes
-
https://huggingface.co/spaces/Zeroistheoneq/Music_visualization/resolve/main/effects/text.py
- Command line
-
hf download hf://spaces/Zeroistheoneq/Music_visualization/effects/text.py
-
curl -L -o text.py https://huggingface.co/spaces/Zeroistheoneq/Music_visualization/resolve/main/effects/text.py
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)) |