Created
April 7, 2021 08:56
-
-
Save nonnullish/b84d656aef1601664cd8a9fd74345ab2 to your computer and use it in GitHub Desktop.
generate abstract ascii patterns
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
from numpy import meshgrid | |
from random import choice, randrange | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser = argparse.ArgumentParser(description='generate abstract ascii patterns') | |
parser.add_argument('width', type=int, nargs='?', default=15); | |
parser.add_argument('height', type=int, nargs='?', default=9); | |
args = parser.parse_args(); | |
def pattern(width=15, height=9): | |
x, y = meshgrid(range(width), range(height)); | |
base = f"(x {choice(['^', '|', '&'])} y)"; | |
tweak = f" {choice(['|', '*', '**'])} {randrange(1, 10)}"; | |
modulo = f" % {randrange(4, 10)}"; | |
eq = base + tweak + modulo; | |
i = (1 == eval(eq)) * ord("."); | |
pixels = [pixel for array in i for pixel in array]; | |
if all(pixel == 0 for pixel in pixels): | |
return pattern(); | |
else: | |
pixels = [chr(x) if x != 0 else " " for x in pixels]; | |
pixels = list("".join(l + "\n" * (n % width == (width - 1)) for n, l in enumerate(pixels))); | |
return(eq + '\n' + "".join(pixels)); | |
print(pattern(args.width, args.height)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment