MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _encode_glyph

Method _encode_glyph

examples/space_invaders/space_invaders.py:77–103  ·  view source on GitHub ↗

Receive a textual description of the glyph and encode into a format understood by GlyphCoordinate.render().

(self, img)

Source from the content-addressed store, hash-verified

75 self.alt_data, alt_w, alt_h = self._encode_glyph(alt)
76
77 def _encode_glyph(self, img):
78 """Receive a textual description of the glyph and
79 encode into a format understood by
80 GlyphCoordinate.render().
81
82 """
83 img = re.sub(r"^\n", "", textwrap.dedent(img))
84 color = "W"
85 lines = [line.rstrip() for line in img.split("\n")]
86 data = []
87 for line in lines:
88 render_line = []
89 line = list(line)
90 while line:
91 char = line.pop(0)
92 if char == "#":
93 color = line.pop(0)
94 continue
95 render_line.append((color, char))
96 data.append(render_line)
97 width = max([len(rl) for rl in data])
98 data = "".join(
99 "".join("%s%s" % (color, char) for color, char in render_line)
100 + ("W " * (width - len(render_line)))
101 for render_line in data
102 )
103 return data, width, len(lines)
104
105 def glyph_for_state(self, coord, state):
106 """Return the appropriate data representation

Callers 1

__init__Method · 0.95

Calls 7

maxClass · 0.85
subMethod · 0.80
rstripMethod · 0.80
splitMethod · 0.80
popMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected