def _reflect_image(image, in_x=True): new = Image(5, 5) for y in range(5): for x in range(5): if in_x: new.set_pixel(x, 4 - y, image.get_pixel(x, y)) else: new.set_pixel(4 - x, y, image.get_pixel(x, y)) return new
def _rotate_image(image, clockwise=True): new = Image(5, 5) for y in range(5): for x in range(5): if clockwise: new.set_pixel(4 - y, x, image.get_pixel(x, y)) else: new.set_pixel(y, 4 - x, image.get_pixel(x, y)) return new
def render_cells(coff, poff): global g_w global g_h screen = Image(5, 5) def render_cell(x, y, b): i = Image(3, 3) for i_x in range(3): for i_y in range(3): i.set_pixel(i_x, i_y, 6) dirs = get_passages(x, y) if len(dirs) > 0: i.set_pixel(1, 1, 9 if b else 0) if DIR_UP in dirs: i.set_pixel(1, 0, 0) if DIR_LEFT in dirs: i.set_pixel(0, 1, 0) if DIR_DOWN in dirs: i.set_pixel(1, 2, 0) if DIR_RIGHT in dirs: i.set_pixel(2, 1, 0) return i for cbx in range(3): for cby in range(3): cx = cbx + coff[0] cy = cby + coff[1] cimage = render_cell(cx, cy, cx == g_w - 1 and cy == g_h - 1) for scx in range(3): for scy in range(3): sx = cbx * 2 + scx - 1 + poff[0] sy = cby * 2 + scy - 1 + poff[1] x_oob = sx < 0 or sx >= 5 y_oob = sy < 0 or sy >= 5 if x_oob or y_oob: continue pixel = cimage.get_pixel(scx, scy) screen.set_pixel(sx, sy, pixel) return screen
def generate_difficulty_img(diff): img = Image(5, 5) for i in range(diff + 1): for j in range(i + 1): img.set_pixel(i, 4 - j, 8) return img
def render_cell(x, y, b): i = Image(3, 3) for i_x in range(3): for i_y in range(3): i.set_pixel(i_x, i_y, 6) dirs = get_passages(x, y) if len(dirs) > 0: i.set_pixel(1, 1, 9 if b else 0) if DIR_UP in dirs: i.set_pixel(1, 0, 0) if DIR_LEFT in dirs: i.set_pixel(0, 1, 0) if DIR_DOWN in dirs: i.set_pixel(1, 2, 0) if DIR_RIGHT in dirs: i.set_pixel(2, 1, 0) return i