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 on(self, value): r, g, b = to_rgb(value, self.intensity) if is_white(value): self.leds['white'].start(100 * self.intensity) self.leds['red'].start(0) self.leds['green'].start(0) self.leds['blue'].start(0) else: self.leds['white'].start(0) self.leds['red'].start(r) self.leds['green'].start(g) self.leds['blue'].start(b)
def color(self, value): r, g, b = to_rgb(value, self.intensity) if is_white(value): self.leds['white'].ChangeDutyCycle(100 * self.intensity) self.leds['red'].ChangeDutyCycle(0) self.leds['green'].ChangeDutyCycle(0) self.leds['blue'].ChangeDutyCycle(0) else: self.leds['white'].ChangeDutyCycle(0) self.leds['red'].ChangeDutyCycle(r) self.leds['green'].ChangeDutyCycle(g) self.leds['blue'].ChangeDutyCycle(b) self._color = value
def move_within_white(self): """Slides through a white block until an obstruction or a new color block is found""" next_pixel = self.pixels[self.get_next_pixel_coords()] while colors.is_white(next_pixel): self.current_pixel_coords = self.get_next_pixel_coords() x,y = self.get_next_pixel_coords() if (x<0 or y<0 or x>=self.width or y>=self.height): self.hit_obstruction() return next_pixel = self.pixels[(x,y)]
def move_within_white(self): """Slides through a white block until an obstruction or a new color block is found""" next_pixel = self.pixels[self.get_next_pixel_coords()] while colors.is_white(next_pixel): self.current_pixel_coords = self.get_next_pixel_coords() x, y = self.get_next_pixel_coords() if (x < 0 or y < 0 or x >= self.width or y >= self.height): self.hit_obstruction() return next_pixel = self.pixels[(x, y)]
def move_within_white(self): """Slides through a white block until an obstruction or a new color block is found.""" x,y = self.next_pixel_coords() if not self.is_pixel_obstruction(x,y): return next_pixel = self.pixels[x][y] while colors.is_white(next_pixel.color): self.current_pixel = next_pixel x,y = self.next_pixel_coords() if not self.is_pixel_obstruction(x,y): return next_pixel = self.pixels[x][y]
def move_within_white(self): """Slides through a white block until an obstruction or a new color block is found.""" x, y = self.next_pixel_coords() if not self.is_pixel_obstruction(x, y): return next_pixel = self.pixels[x][y] while colors.is_white(next_pixel.color): self.current_pixel = next_pixel x, y = self.next_pixel_coords() if not self.is_pixel_obstruction(x, y): return next_pixel = self.pixels[x][y]
def move_within_block(self): """Moves to the border pixel within the current color block""" if colors.is_white(self.pixels[self.current_pixel_coords]): self.move_within_white() else: self.move_within_color()
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