Source code for wolfgpu.textboard

from pathlib import Path
[docs] class TextBoard: def __init__(self, width=100, height=100): self._width = width self._height = height self.a = [[ "" for i in range(self._width) ] for i in range(self._height) ]
[docs] def set(self, x,y, v, v2 = None): if v2 is None: self.a[y][x] = str(v) else: assert type(v) == str, "If two parameters, first one must be a label" self.a[y][x] = str(v) self.a[y][x+1] = str(v2)
[docs] def copy(self, npa, x, y, title=""): self.a[y][x] = title if len(npa.shape) == 1: nb_cols = 1 else: nb_cols = npa.shape[1] if y + npa.shape[0] + 1 > len(self.a): self.a.extend([[ "" for i in range(self._width) ] for i in range(y + npa.shape[0] + 1 - len(self.a)) ]) for r in range(npa.shape[0]): wolf_r = npa.shape[0] - 1 - r self.a[y+r+1][x] = f"'{wolf_r})'" if len(npa.shape) == 2: for c in range(npa.shape[1]): self.a[y+r+1][x+c+1] = npa[wolf_r,c] else: self.a[y+r+1][x+0+1] = npa[wolf_r]
[docs] def save(self, name="debug_csv.csv"): with open(name, "w") as fout: for row in self.a: fout.write( ",".join([str(x) for x in row])) fout.write('\n')