class Screen: width = None height = None x0 = None y0 = None def __init__(self, width, height): self.width = width self.height = height self.x0 = int(width/2) self.y0 = int(height/2) self.screen = [[' ' for x in range(width)] for y in range(height)] def setPoint(self, x, y, v): self.screen[self.x0+x][self.y0-y] = v def moveOrigin(self, dx, dy): self.x0 += dx self.y0 -= dy def printScreen(self, fileName = None): s = "" for y in range(self.height): l = "" for x in range(self.width): v = self.screen[x][y] if x-self.x0 == 0 and y-self.y0 == 0: c = "+" if v == " " else v elif x-self.x0 == 0: c = "|" if v == " " else v elif y-self.y0 == 0: c = "-" if v == " " else v else: c = v l += c s += l + "\n" if fileName is None: print(s) else: with open(fileName, "wt") as f: f.write(s)