Created
January 4, 2020 07:26
-
-
Save mmoran0032/dbbffc4dc7b1ae99f432f9b92430202d to your computer and use it in GitHub Desktop.
Terminal artwork examples
This file contains hidden or 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
| import random | |
| import shutil | |
| from typing import Tuple | |
| def generate_output(**kwargs) -> None: | |
| print(create_output(*shutil.get_terminal_size(), **kwargs)) | |
| def create_output( | |
| width: int, | |
| height: int, | |
| charset: Tuple[str] = ("/", "\\"), | |
| weights: Tuple[float] = (0.5, 0.5), | |
| ) -> str: | |
| """ create the full terminal output | |
| """ | |
| lines = [create_line(width, charset, weights) for _ in range(height)] | |
| return "\n".join(lines) | |
| def create_line(width: int, charset: Tuple[str], weights: Tuple[float]) -> str: | |
| """ create a single line of the artwork with provided characters | |
| """ | |
| output_chars = random.choices(population=charset, weights=weights, k=width) | |
| return "".join(output_chars) | |
| if __name__ == "__main__": | |
| generate_output() | |
| print() | |
| generate_output(charset=("/", " ", "\\"), weights=(0.2, 0.6, 0.2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment