2022-01-27 12:20:55 +00:00
|
|
|
{ writers }:
|
|
|
|
writers.writePython3Bin "krebsdance" {} ''
|
|
|
|
import argparse
|
|
|
|
import random
|
2022-01-28 15:35:17 +00:00
|
|
|
import itertools
|
2022-01-27 12:20:55 +00:00
|
|
|
|
|
|
|
claws = [
|
|
|
|
dict(
|
2022-01-28 15:35:17 +00:00
|
|
|
up="(\\/)",
|
|
|
|
down="(/\\)",
|
|
|
|
left="(\\\\)",
|
|
|
|
right="(//)",
|
2022-01-27 12:20:55 +00:00
|
|
|
),
|
|
|
|
dict(
|
2022-01-28 15:35:17 +00:00
|
|
|
up="(V)",
|
|
|
|
down="(A)",
|
|
|
|
left=">)=",
|
|
|
|
right="=(<",
|
2022-01-27 12:20:55 +00:00
|
|
|
),
|
|
|
|
dict(
|
2022-01-28 15:35:17 +00:00
|
|
|
up="(U)",
|
|
|
|
down="(n)",
|
|
|
|
left=")==",
|
|
|
|
right="==(",
|
2022-01-27 12:20:55 +00:00
|
|
|
),
|
|
|
|
]
|
|
|
|
|
|
|
|
eyes = [
|
2022-01-28 15:35:17 +00:00
|
|
|
"°",
|
|
|
|
"*",
|
|
|
|
"^",
|
|
|
|
"ö",
|
|
|
|
"o",
|
|
|
|
"O",
|
|
|
|
"X",
|
|
|
|
"x",
|
|
|
|
"U",
|
|
|
|
"u",
|
2022-01-27 12:20:55 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
bodies = [
|
|
|
|
dict(
|
2022-01-28 15:35:17 +00:00
|
|
|
left="(",
|
|
|
|
right=")",
|
2022-01-27 12:20:55 +00:00
|
|
|
),
|
|
|
|
dict(
|
2022-01-28 15:35:17 +00:00
|
|
|
left="{",
|
|
|
|
right="}",
|
2022-01-27 12:20:55 +00:00
|
|
|
),
|
|
|
|
dict(
|
2022-01-28 15:35:17 +00:00
|
|
|
left="[",
|
|
|
|
right="]",
|
2022-01-27 12:20:55 +00:00
|
|
|
),
|
|
|
|
dict(
|
2022-01-28 15:35:17 +00:00
|
|
|
left="<",
|
|
|
|
right=">",
|
2022-01-27 12:20:55 +00:00
|
|
|
),
|
|
|
|
dict(
|
2022-01-28 15:35:17 +00:00
|
|
|
left="|",
|
|
|
|
right="|",
|
2022-01-27 12:20:55 +00:00
|
|
|
),
|
|
|
|
]
|
|
|
|
|
|
|
|
mouths = [
|
2022-01-28 15:35:17 +00:00
|
|
|
",,,,",
|
|
|
|
",mm,",
|
|
|
|
"_mm_",
|
|
|
|
"-mm-",
|
|
|
|
";;;;",
|
|
|
|
";mm;",
|
|
|
|
":mm:",
|
|
|
|
"::::",
|
|
|
|
":ww:",
|
|
|
|
":<>:",
|
2022-01-27 12:20:55 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-01-28 15:35:17 +00:00
|
|
|
def all_krebses():
|
|
|
|
for mouth, body, eye, claw in itertools.product(mouths, bodies, eyes, claws):
|
|
|
|
yield f'{claw["up"]} {body["left"]}{eye}{mouth}{eye}{body["right"]} {claw["up"]}'
|
|
|
|
|
|
|
|
|
|
|
|
def krebs_graph() -> str:
|
|
|
|
return "\n".join(
|
|
|
|
["digraph {"]
|
|
|
|
+ [f'"{krebs}"->"{generate(seed=krebs)}"' for krebs in all_krebses()]
|
|
|
|
+ ["}"]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def generate(*, seed: str, dancing: bool = False) -> str:
|
|
|
|
if seed:
|
|
|
|
random.seed(seed)
|
|
|
|
clawstyle = random.choice(claws)
|
|
|
|
body = random.choice(bodies)
|
|
|
|
eye = random.choice(eyes)
|
|
|
|
mouth = random.choice(mouths)
|
|
|
|
if dancing:
|
|
|
|
return "\n".join(
|
|
|
|
[
|
|
|
|
f'{clawstyle["down"]} {body["left"]}{eye}{mouth}{eye}{body["right"]}{clawstyle["up"]}',
|
|
|
|
f'{clawstyle["left"]}{body["left"]}{eye}{mouth}{eye}{body["right"]} {clawstyle["right"]}',
|
|
|
|
f'{clawstyle["right"]} {body["left"]}{eye}{mouth}{eye}{body["right"]} {clawstyle["left"]}',
|
|
|
|
f'{clawstyle["down"]}{body["left"]}{eye}{mouth}{eye}{body["right"]}{clawstyle["down"]}',
|
|
|
|
]
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
return f'{clawstyle["up"]} {body["left"]}{eye}{mouth}{eye}{body["right"]} {clawstyle["up"]}'
|
|
|
|
|
|
|
|
|
|
|
|
def fixpoints():
|
|
|
|
for krebs in all_krebses():
|
|
|
|
if generate(seed=krebs) == krebs:
|
|
|
|
yield krebs
|
|
|
|
|
|
|
|
|
2022-01-27 12:20:55 +00:00
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
|
|
|
parser.add_argument(
|
2022-01-28 15:35:17 +00:00
|
|
|
"seed",
|
|
|
|
nargs="?",
|
|
|
|
help="random seed to use for generating the krebs variant",
|
2022-01-27 12:20:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
parser.add_argument(
|
2022-01-28 15:35:17 +00:00
|
|
|
"--dance",
|
|
|
|
"-d",
|
|
|
|
dest="dance",
|
|
|
|
help="if the krebs should dance",
|
2022-01-27 12:20:55 +00:00
|
|
|
default=False,
|
2022-01-28 15:35:17 +00:00
|
|
|
action="store_true",
|
2022-01-27 12:20:55 +00:00
|
|
|
)
|
|
|
|
|
2022-01-28 15:35:17 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--mode",
|
|
|
|
"-m",
|
|
|
|
dest="mode",
|
|
|
|
choices=["graphviz", "plain"],
|
|
|
|
default="plain",
|
|
|
|
)
|
2022-01-27 12:20:55 +00:00
|
|
|
|
2022-01-28 15:35:17 +00:00
|
|
|
args = parser.parse_args()
|
2022-01-27 12:20:55 +00:00
|
|
|
|
2022-01-28 15:35:17 +00:00
|
|
|
if args.mode == "plain":
|
|
|
|
print(generate(seed=args.seed, dancing=args.dance))
|
|
|
|
elif args.mode == "graphviz":
|
|
|
|
print(krebs_graph())
|
2022-01-27 12:20:55 +00:00
|
|
|
|
|
|
|
|
2022-01-28 15:35:17 +00:00
|
|
|
if __name__ == "__main__":
|
2022-01-27 12:20:55 +00:00
|
|
|
main()
|
|
|
|
''
|