def main(): #pi = pigpio.pi() realtime = False pi = None print("Starting up...") while True: penalty = 0 try: if not realtime: data = getData() #print(data) if (data["realtime"]): realtime = True continue if (data["on"]): color = colour.hex2rgb('#' + data["color"]) setColor(pi, color) else: penalty = 1000 setColor(pi, colour.hex2rgb("#000000")) sleep((penalty + POLLING_TIME) / 1000) else: socket = create_connection(REALTIME_URL) realtime_loop(socket, pi) realtime = False except Exception as e: pi.stop() pi = pigpio.pi() print(e) sleep(5000)
def test_pattern_to_check_color_value_is_hexadecimal(): value = '#fff' try: hex2rgb(value) except ValueError: # show error message here pytest.fail('color is not valid %s'.format(value))
def StringToValue(self, s, flags): s = remove_double_quote(s).strip() # For emtpy value. if s == '': return True, None # Try to parse hex string. if s[0] == '#': try: if len(s) == 7: # RGB. r, g, b = colour.hex2rgb(s) return True, (255*r,255*g,255*b) elif len(s) == 9: # RGBA. r, g, b = colour.hex2rgb(s[:-2]) a = int(s[-2:], 16) return True, (255*r,255*g,255*b,a) else: return False except: return False # Try to parse HSV string. elif s[0].isdigit() or s[0] == '.': # Try to parse numbers try: # If get single int value. if s.isdigit(): return True, int(s) else: h,s,v = map(float, s.split(' ')) rgb = wx.Image.HSVtoRGB(wx.Image_HSVValue(h,s,v)) return True, (rgb.red, rgb.green, rgb.blue) except: return False # Color in string. else: scheme = self.__get_current_scheme() if scheme is None: return True, s colors = get_colors_in_scheme(scheme).keys() if s.strip() not in colors: return False return True, get_colors_in_scheme(scheme)[s]
def __init__(self, shape_type, shape_coords): self.play = True self.shape_type = shape_type self.shape_coords = shape_coords self.radius_slider = Slider("Radius", 0.6, 1.0, 0.0, 0) self.cook_time_slider = Slider("Time", 200, 200, 10, 100) self.slides = [self.radius_slider, self.cook_time_slider] self.color_grades = 8 self.colors = list( Color("blue").range_to(Color("red"), self.color_grades)) print(self.colors) self.rgb_colors = [colour.hex2rgb(i.hex) for i in self.colors] temp = [int(255 * i) for j in self.rgb_colors for i in j] it = iter(temp) self.rgb_colors = list(zip(it, it, it)) print(self.rgb_colors) self.diffusing = False self.current_diffuse_time = 0 self.cook_time = self.cook_time_slider.val self.max_diffuse_time = self.cook_time self.cleanup = True self.forward = True self.shape = None for s in self.slides: s.draw() self.draw_text() pygame.display.update()
def realtime_loop(socket, pi): while True: data = socket.recv() data = json.loads(data) if not data["realtime"]: return setColor(pi, colour.hex2rgb(data["color"]))
def main(): #pi = pigpio.pi() pi = None while True: data = getData() color = colour.hex2rgb('#' + data["color"]) setColor(pi, color) sleep(POLLING_TIME / 1000)
def stroke(self, color: str, alpha=1, width=5): stroke_color = resolve(color) alpha = resolve(alpha) stroke_width = resolve(width) color: colour.Color = colour.hex2rgb(stroke_color) self.style['stroke'] = Color4f(color[0], color[1], color[2], alpha) self.style['stroke_width'] = stroke_width if stroke_width else None return self
def StringToValue(self, s, flags): s = remove_double_quote(s).strip() # For emtpy value. if s == '': return True, None # Try to parse hex string. if s[0] == '#': try: if len(s) == 7: # RGB. r, g, b = colour.hex2rgb(s) return True, (255*r,255*g,255*b) elif len(s) == 9: # RGBA. r, g, b = colour.hex2rgb(s[:-2]) a = int(s[-2:], 16) return True, (255*r,255*g,255*b,a) else: return False except: return False # Try to parse HSV string. elif s[0].isdigit() or s[0] == '.': # Try to parse numbers try: # If get single int value. if s.isdigit(): return True, int(s) else: h,s,v = map(float, s.split(' ')) rgb = wx.Image.HSVtoRGB(wx.Image_HSVValue(h,s,v)) return True, (rgb.red, rgb.green, rgb.blue) except: return False # Color in string. else: scheme = self.__get_current_scheme() if scheme is None: return True, s colors = get_colors_in_schcme(scheme).keys() if s.lower() not in colors: return False return True, s
def hex2rgb255(color): """ cv2 requires rgb color encoded on 255 values instead of rgb encoded as a float value between 0 and 1 :see https://docs.opencv.org/3.1.0/dc/da5/tutorial_py_drawing_functions.html :param color: :return: """ red, green, blue = hex2rgb(color) rgb255_color = (int(red * 255), int(green * 255), int(blue * 255)) return rgb255_color
def cb4( self, color, dontconvert=False ): if isinstance( color, str ): regex = re.compile( r'^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$', re.IGNORECASE ) if regex.match( color ): if dontconvert is False: rgb = colour.hex2rgb( color ) color = colour.rgb2hsv( rgb ) else: print("pass") return color else: return "hexidecimal:", color, "isn't a hexidecimal" elif isinstance( color, list ): rgb = colour.hsv2rgb( tuple( color[:3] ) ) color = colour.rgb2hex( rgb, force_long=True ) else: return False return color
# Copyright Naveen M K, 2021 import cairo import colour # outer_color = [0.3, 0.4, 0.9, 1.0] # orig 0.4, 0.2, 0.4 outer_color = list(colour.hex2rgb("#5FA172")) + [1] inner_color = list(colour.hex2rgb("#2F3954")) + [1] width, height = 500, 500 with cairo.SVGSurface("logo.svg", width, height) as surface: context = cairo.Context(surface) context.scale(width, height) context.set_line_width(0.01) context.move_to(0, 0) context.curve_to(0, 0, 0.5, 1, 1, 0) context.set_source_rgba(*inner_color) context.stroke() context.move_to(0, 1) context.curve_to(0, 1, 0.5, 0, 1, 1) context.set_source_rgba(*inner_color) context.stroke() context.move_to(0, 0) context.curve_to(0, 0, 1, 0.5, 0, 1) context.set_source_rgba(*inner_color) context.stroke() context.move_to(1, 0) context.curve_to(1, 0, 0, 0.5, 1, 1)
def fill(self, fill: str, alpha=1): fill = resolve(fill) alpha = resolve(alpha) color: colour.Color = colour.hex2rgb(fill) self.style['fill'] = Color4f(color[0], color[1], color[2], alpha) return self
def test_hex2rgb_raise_an_error_when_color_value_is_not_hexadecimal(): with pytest.raises(ValueError, match="Invalid value '#ff' provided for rgb color."): hex2rgb('#ff')
def hex_to_rgb(hex_code: str) -> np.ndarray: return np.array(hex2rgb(hex_code))
def convert_hex_to_rgb(self, hex_code): return colour.hex2rgb(hex_code)
def convert_hex_to_hsv(self, hex_code): rgb_code = colour.hex2rgb(hex_code) return colorsys.rgb_to_hsv(float(rgb_code[0]), float(rgb_code[1]), float(rgb_code[2]))
def test_hex2rgb_convert_white_color_into_rgb_tuple(): rgb = hex2rgb('#ffffff') assert rgb == (1.0, 1.0, 1.0)
def get(self): colours = [] for colList in self.colGrid: for box in colList: colours.append(hex2rgb(self.itemcget(box, 'fill'))) return colours
def get(self): return hex2rgb(self['bg'])
red = Color("red") blue = Color("blue") colors = list(red.range_to(blue, 200)) rads = 100 holdF = 0 rads = 0 inc = 0 for colorNow in colors: colorNow = str(colorNow.hex_l) print('tttt', colorNow) colorNow = hex2rgb(colorNow) print(colorNow) colors[inc] = colorNow inc = inc + 1 print() scene.forward = vector(-0.4,-0.3,-1) scene.ambient = color.gray(0.2) front = box(pos=vector(0,0,6), size=vector(12,12,12), color=color.white, shininess=0.3) def Save(save): root = tkinter.Tk() root.withdraw() radians = "radians: " + str(rads) + '\n'