def randomize_hue(bg_hex): color_obj = Color(bg_hex) randomized = random.random() color_obj.hue = randomized sat = color_obj.saturation color_obj.saturation = sat+randomized if (sat+randomized) <= 0.5 else 0.5 return color_obj.get_hex()
def generate_palette(_color, _hue_variance, _saturation_variance, _luminance_variance): base_color = Color(_color) palette = [base_color.hex_l] for i in range(1, 4): new_color = Color(base_color) new_color.hue = rotate_hue(base_color.hue, -(_hue_variance * i)) new_color.saturation = max( 0.0, base_color.saturation - (_saturation_variance * i)) new_color.luminance = max( 0.0, base_color.luminance - (_luminance_variance * i)) palette.append(new_color.hex_l) for i in range(1, 4): new_color = Color(base_color) new_color.hue = rotate_hue(base_color.hue, (_hue_variance * i)) new_color.saturation = min( 1.0, base_color.saturation + (_saturation_variance * i)) new_color.luminance = min( 1.0, base_color.luminance + (_luminance_variance * i)) palette.insert(0, new_color.hex_l) lighter_palette = [] for color in palette: new_color = Color(color) new_color.hue = rotate_hue(new_color.hue, -_hue_variance / 2) new_color.saturation = max( 0.0, base_color.saturation - (_saturation_variance * i)) new_color.luminance = min( 1.0, base_color.luminance + (_luminance_variance * i)) lighter_palette.append(new_color.hex_l) darker_palette = [] for color in palette: new_color = Color(color) new_color.hue = rotate_hue(new_color.hue, _hue_variance / 2) new_color.saturation = min( 1.0, base_color.saturation + (_saturation_variance * i)) new_color.luminance = max( 0.0, base_color.luminance - (_luminance_variance * i)) darker_palette.append(new_color.hex_l) palettes = [lighter_palette, palette, darker_palette] return palettes
def color_for_count(count: int) -> ColorStr: if not count: return Color('white').get_hex() c = Color('green') max = 10 count_real = min(max, count) c.hue = (max - count_real) / max * 0.33 c.saturation = 1.0 c.luminance = 0.7 return c.get_hex()
def poster(): # randon backgorund color rand_rgb = tuple([(randrange(97, 160) / 255.0) for i in range(3)]) bg = Color(rgb=rand_rgb) # get foreground fg = Color(bg.hex) variation = randrange(15, 60) fg.hue = choice([variation, variation * -1]) # random alpha alpha = randrange(4, 7) / 10.0 # create image svg = render_template('poster.svg', bg=bg.hex, fg=fg.hex, alpha=alpha) return Response(svg2png(bytestring=svg), mimetype='image/png')
def generate_background(self): hue_offset = promap(int(self.hash[14:][:3], 16), 0, 4095, 0, 359) sat_offset = int(self.hash[17:][:1], 16) base_color = Color(hsl=(0, .42, .41)) base_color.hue = base_color.hue - hue_offset if sat_offset % 2: base_color.saturation = base_color.saturation + sat_offset / 100 else: base_color.saturation = base_color.saturation - sat_offset / 100 rgb = base_color.rgb r = int(round(rgb[0] * 255)) g = int(round(rgb[1] * 255)) b = int(round(rgb[2] * 255)) return self.svg.rect(0, 0, '100%', '100%', **{'fill': 'rgb({}, {}, {})'.format(r, g, b)})
def poster(): # randon backgorund color rand_rgb = tuple([(randrange(97, 160) / 255.0) for i in range(3)]) bg = Color(rgb=rand_rgb) # get foreground fg = Color(bg.hex) variation = randrange(15, 60) fg.hue = choice([variation, variation * -1]) # random alpha alpha = randrange(4, 7) / 10.0 # create image svg = render_template('poster.svg', bg=bg.hex, fg=fg.hex, alpha=alpha) return Response(svg2png(bytestring=svg), mimetype='image/png')
def generate_background(self): hue_offset = promap(int(self.hash[14:][:3], 16), 0, 4095, 0, 359) sat_offset = int(self.hash[17:][:1], 16) base_color = Color(hsl=(0, .42, .41)) base_color.hue = base_color.hue - hue_offset if sat_offset % 2: base_color.saturation = base_color.saturation + sat_offset / 100 else: base_color.saturation = base_color.saturation - sat_offset / 100 rgb = base_color.rgb r = int(round(rgb[0] * 255)) g = int(round(rgb[1] * 255)) b = int(round(rgb[2] * 255)) return self.svg.rect(0, 0, '100%', '100%', **{ 'fill': 'rgb({}, {}, {})'.format(r, g, b) })
def changecolour(colourcode, action, amount=100): c = Color(colourcode) if action == 'red': c.red = amount / 100 return c elif action == 'blue': c.blue = amount / 100 return c elif action == 'green': c.green = amount / 100 return c elif action == 'hue': c.hue = amount / 100 return c elif action == 'sat': c.saturation = amount / 100 return c elif action == 'lum': c.luminance = amount / 100 return c