def loads(self): result = Utils.array2d(self.cols, self.rows) blocks = Utils.array2d(self.cols, self.rows, list) for i in range(self.cols): for j in range(self.rows): sx, ex = i * self.block_size, (i + 1) * self.block_size sy, ey = j * self.block_size, (j + 1) * self.block_size for x in range(sx, ex): for y in range(sy, ey): blocks[i][j].append(self.pixels[x, y]) result[i][j] = getattr(Methods, Const.PA_method)(blocks[i][j]) if self.save is not None or self.show: om = Image.new( "RGB", [self.cols * self.block_size, self.rows * self.block_size], (255, 255, 255)) draw = ImageDraw.Draw(om) for i in range(self.cols): for j in range(self.rows): sx, ex = i * self.block_size, (i + 1) * self.block_size sy, ey = j * self.block_size, (j + 1) * self.block_size pos = [sx, sy, ex - 1, ey - 1] cur_color = Const.PA_colors[result[i][j]] outline = (0, 0, 0) if self.outline else None draw.rectangle(pos, fill=cur_color, outline=outline) if self.save is not None: om.save(self.save) if self.show: om.show() return {"cols": self.cols, "rows": self.rows, "data": result}
def __init__(self): pygame.init() self.width = Const.BOARD_size[0] * Const.UI_scale self.height = Const.BOARD_size[1] * Const.UI_scale self.size = [self.width, self.height] self.screen = pygame.display.set_mode(self.size, 0, 32) pygame.display.set_caption("Lonely observer") self.surf_old = pygame.Surface(self.size, flags=SRCALPHA) self.surf_mid = pygame.Surface(self.size, flags=SRCALPHA) self.surf_new = pygame.Surface(self.size, flags=SRCALPHA) self.board = Board(self.update_new) self.cur_map = Utils.array2d(*Const.BOARD_size, -1) self.anchor = [0, 0] self.mag = 1 self.disp_shadow = True threading.Thread(target=self.check_loop, daemon=True).start() self.ui_loop()