from PIL import Image 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.img = Image.new( 'RGB', (self.width, self.height), "white") self.pixels = self.img.load() self.drawAxis() def setPoint(self, x, y, v): c = self.x0+x r = self.y0-y if v == "*": color = (0, 0, 0) elif v == ".": color = (255, 0, 0) else: color = v self.pixels[c, r] = color def moveOrigin(self, dx, dy): self.x0 += dx self.y0 -= dy self.img = Image.new( 'RGB', (self.width, self.height), "white") self.pixels = self.img.load() self.drawAxis() def drawAxis(self): r = self.y0 for c in range(self.width): self.pixels[c,r] = (128, 128, 126) c = self.x0 for r in range(self.height): self.pixels[c,r] = (128, 128, 128) def printScreen(self, fileName = None): if fileName is not None: self.img.save(fileName) self.img.show()