Glyph
By Ben Nitkin on
Glyph is a small Python library that simplifies text-based GUI's and games. Its fundamental class, the Glyph (surprise!) consists of some number of ASCII images and a few other attributes (including position and layer). Glyphs relate to each other in a parent-child context. When a glyph is rendered, it renders each of its children, at the position they specify. The glyph inserts itself under any children with a positive layer number.
Each Glyph saves its image in a dictionary, where keys are [x, y] positions and values are the characters in those locales. When rendered, each Glyph's image is composited with all its children, then converted into a string for printing.
It doesn't sound so useful yet, does it? I'll present a few examples of its utility.
- Simple games. The background acts as the root parent, and its children include the character and any interactive elements.
- Status screens. Glyph simplifies building even a complicated status screen, full of both text and ASCII images. It's easy to place text within a frame, or organize data in rows and columns. If each piece of data is a Glyph, then they can be updated independently with the setImage function.