import random from botclient.botclient import Bot GRAWLIX = [ "angle", "ball1", "ball2", "brick", "bullseye", "bun", "claw", "cloud", "crosses", "crumple", "drop", "dust1", "dust2", "feather", "flower", "fruit", "fungus", "fur", "gadget", "globule", "glyph1", "glyph10", "glyph2", "glyph3", "glyph4", "glyph5", "glyph6", "glyph7", "glyph8", "glyph9", "growth", "hatch", "helm", "horizon", "joint", "knothole", "link", "lump", "mountain", "null", "orbit", "popup", "rects", "rough", "scales", "scrawl", "scribble", "shatter", "signal", "slump", "spark1", "spark2", "sprout", "strata", "vertical", "wreck", ] GRID_TYPES = [ "latin_square", "concentric", "sator", "random", "vertical", "horizontal" ] class Grawlix(Bot): def latin_square(self): return [ [ 2, 1, 0, 4, 3 ], [ 0, 4, 3, 2, 1 ], [ 3, 2, 1, 0, 4 ], [ 1, 0, 4, 3, 2 ], [ 4, 3, 2, 1, 0 ], ] def concentric(self): return [ [ 0, 1, 2, 1, 0 ], [ 1, 2, 3, 2, 1 ], [ 2, 3, 4, 3, 2 ], [ 1, 2, 3, 2, 1 ], [ 0, 1, 2, 1, 0 ], ] def sator(self): return [ [ 0, 1, 2, 3, 4 ], [ 1, 5, 6, 7, 3 ], [ 2, 6, 8, 6, 2 ], [ 3, 7, 6, 5, 1 ], [ 4, 3, 2, 1, 0 ], ] def random(self): s = [ 0, 1, 2, 3, 4 ] return [ [ random.choice(s) for i in range(5) ], [ random.choice(s) for i in range(5) ], [ random.choice(s) for i in range(5) ], [ random.choice(s) for i in range(5) ], [ random.choice(s) for i in range(5) ], ] def vertical(self): return [ [ 0, 1, 2, 3, 4 ] for i in range(5) ] def horizontal(self): return [ [ i, i, i, i, i ] for i in range(5) ] def make_grid(self): type = random.choice(GRID_TYPES) if type == "latin_square": return self.latin_square() if type == "concentric": return self.concentric() if type == "sator": return self.sator() if type == "random": return self.random() if type == "vertical": return self.vertical() if type == "horizontal": return self.horizontal() def grid_glyphs(self, grid): return max([max(row) for row in grid]) + 1 def make_glyphset(self, n): names = random.sample(GRAWLIX, n) return [ f":grawlix_{name}:" for name in names ] def render_row(self, row, glyphs): return " ".join([glyphs[c] for c in row]) def render(self): grid = self.make_grid() n = self.grid_glyphs(grid) glyphs = self.make_glyphset(n) rows = [ self.render_row(r, glyphs) for r in grid ] return "\n".join(rows) if __name__ == '__main__': g = Grawlix() g.configure() post = g.render() g.wait() g.post(post) print(post)