Last active
July 3, 2023 10:25
-
-
Save tthn0/5636b9b15d41d53c241f87a884490728 to your computer and use it in GitHub Desktop.
"Typewrite" effect in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A snippet for string "typewriting" in Python. | |
Note: On PyCharm, this effect doesnt look that good because | |
PyCharm outputs the letters at low FPS (on my machine). | |
Author: tthn0 (GitHub) | |
Gist Link: https://gist.github.com/tthn0/5636b9b15d41d53c241f87a884490728 | |
""" | |
import sys | |
from time import sleep | |
DELAY: float = .05 # Change this to speed up/slow down typewriting speed | |
def typewrite(*paragraph: str) -> None: | |
"""This function mimics a typewriting effect by printing strings letter by letter. | |
Args: | |
*paragraph -- variable length args of setences to typewrite | |
""" | |
for sentence in paragraph: | |
for char in sentence: | |
sys.stdout.write(char) | |
sys.stdout.flush() | |
sleep(DELAY) | |
print() | |
sleep(DELAY) | |
# Usage (you can put as many sentences as you want) | |
typewrite( | |
"Hello World!", | |
"Another Sentence.", | |
"The quick brown fox jumps over the lazy dog.", | |
) |
@eggnaut I'm not sure! I'm not familiar with Pygame unfortunately.
@eggnaut I'm not sure! I'm not familiar with Pygame unfortunately.
Oh okay, no problemo :)
if I am not wrong this is console based only.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any way to make this compatible with Pygame?
I think you'd need a whole new custom text engine though...