def trace_back(x, y, vx, vy, clr): x0 = x - vx y0 = y - vy if x0 < 0 or x0 >= pic.size[0]: return None if y0 < 0 or y0 >= pic.size[1]: return None a, b, c = get_abc(x0, y0) return x0, y0, vx^a, vy^b, clr^c
def char_applies(x0, y0, char): x = x0 y = y0 prev_dx = prev_dy = None for dx, dy, clr in char: if x < 0 or y < 0 or x >= pic.size[0] or y >= pic.size[1]: return None if prev_dx is not None: a, b, c = get_abc(x, y) if dx ^ prev_dx != a or dy ^ prev_dy != b: return None x += dx y += dy prev_dx = dx prev_dy = dy vx, vy, clr = char[0] a, b, c = get_abc(x0, y0) return (x0, y0, vx^a, vy^b, 0)