def move_out_of_block(self): """Moves out of a color block and into the next color block, performing the operation if necessary""" #If we're at a wall x,y = self.current_pixel_coords if (self.dp == 0 and x >= self.width-1)\ or (self.dp == 1 and y >= self.height-1)\ or (self.dp == 2 and x <= 0)\ or (self.dp == 3 and y <= 0): self.hit_obstruction() return current_pixel = self.pixels[(x,y)] next_pixel_coords = self.get_next_pixel_coords() next_pixel = self.pixels[next_pixel_coords] #If we're at a black pixel if colors.is_black(next_pixel): self.hit_obstruction() return if colors.is_white(current_pixel)\ or colors.is_white(next_pixel): pass else: #Get the operation to do hue_light_diff = colors.hue_light_diff(current_pixel,next_pixel) op_name, op = self.operations[hue_light_diff] #print op_name op() self.current_pixel_coords = next_pixel_coords self.times_stopped = 0 self.switch_cc = True
def move_out_of_block(self): """Moves out of a color block and into the next color block, performing the operation if necessary""" #If we're at a wall x, y = self.current_pixel_coords if (self.dp == 0 and x >= self.width-1)\ or (self.dp == 1 and y >= self.height-1)\ or (self.dp == 2 and x <= 0)\ or (self.dp == 3 and y <= 0): self.hit_obstruction() return current_pixel = self.pixels[(x, y)] next_pixel_coords = self.get_next_pixel_coords() next_pixel = self.pixels[next_pixel_coords] #If we're at a black pixel if colors.is_black(next_pixel): self.hit_obstruction() return if colors.is_white(current_pixel)\ or colors.is_white(next_pixel): pass else: #Get the operation to do hue_light_diff = colors.hue_light_diff(current_pixel, next_pixel) op_name, op = self.operations[hue_light_diff] #print op_name op() self.current_pixel_coords = next_pixel_coords self.times_stopped = 0 self.switch_cc = True
def move_out_of_block(self): """Moves out of a color block and into the next color block, performing the operation if necessary.""" x, y = self.current_pixel.x, self.current_pixel.y n_x, n_y = self.next_pixel_coords() self.debug.writeln(" -> Trying to cross from (%s,%s) to (%s,%s)"\ %(x,y,n_x,n_y)) #If we're at a wall if (self.dp == 0 and x >= self.width-1)\ or (self.dp == 1 and y >= self.height-1)\ or (self.dp == 2 and x <= 0)\ or (self.dp == 3 and y <= 0): self.hit_obstruction() return current_pixel = self.current_pixel next_pixel = self.pixels[n_x][n_y] #If we're at a black pixel if colors.is_black(next_pixel.color): self.hit_obstruction() return if colors.is_white(current_pixel.color)\ or colors.is_white(next_pixel.color): pass else: #Get the operation to do hue_light_diff = colors.hue_light_diff(current_pixel.color, next_pixel.color) op_name, op = self.operations[hue_light_diff] self.debug.writeln(" -> Crossing from (%s,%s), color=%s to (%s,%s), color=%s"\ % (current_pixel.x, current_pixel.y, current_pixel.color,\ next_pixel.x, next_pixel.y, next_pixel.color)) self.debug.writeln(" -> Stack before %s = %s" % (op_name.upper(), self.stack)) self.debug.writeln(" -> Performing %s" % (op_name.upper())) op() self.debug.writeln(" -> Stack after %s = %s" % (op_name.upper(), self.stack)) self.current_pixel = next_pixel self.times_stopped = 0 self.switch_cc = True
def move_out_of_block(self): """Moves out of a color block and into the next color block, performing the operation if necessary.""" x,y = self.current_pixel.x, self.current_pixel.y n_x,n_y = self.next_pixel_coords() self.debug.writeln(" -> Trying to cross from (%s,%s) to (%s,%s)"\ %(x,y,n_x,n_y)) #If we're at a wall if (self.dp == 0 and x >= self.width-1)\ or (self.dp == 1 and y >= self.height-1)\ or (self.dp == 2 and x <= 0)\ or (self.dp == 3 and y <= 0): self.hit_obstruction() return current_pixel = self.current_pixel next_pixel = self.pixels[n_x][n_y] #If we're at a black pixel if colors.is_black(next_pixel.color): self.hit_obstruction() return if colors.is_white(current_pixel.color)\ or colors.is_white(next_pixel.color): pass else: #Get the operation to do hue_light_diff = colors.hue_light_diff(current_pixel.color,next_pixel.color) op_name, op = self.operations[hue_light_diff] self.debug.writeln(" -> Crossing from (%s,%s), color=%s to (%s,%s), color=%s"\ % (current_pixel.x, current_pixel.y, current_pixel.color,\ next_pixel.x, next_pixel.y, next_pixel.color)) self.debug.writeln(" -> Stack before %s = %s" % (op_name.upper(),self.stack)) self.debug.writeln(" -> Performing %s" % (op_name.upper())) op() self.debug.writeln(" -> Stack after %s = %s" % (op_name.upper(),self.stack)) self.current_pixel = next_pixel self.times_stopped = 0 self.switch_cc = True
def is_background(self,color): """Tells us if the given color is black or white.""" if colors.is_white(color) or colors.is_black(color): return True else: return False
def is_background(self, color): """Tells us if the given color is black or white.""" if colors.is_white(color) or colors.is_black(color): return True else: return False