def create_random_image(self, dims, rgb_color): """ :param dims: Image dimensions :param rgb_color: A color in RGB format. :return: """ image = { "background": helpers.rgb_str_to_tuple(self.args.background), "pixels": [] } if not self.args.rainbow: cmyk_color = helpers.rgb_to_cmyk( *helpers.rgb_str_to_tuple(rgb_color)) contrasts = self.get_contrasts(cmyk_color) for x in range(0, dims["x"], dims["pixel_size"]): if self.args.rainbow: cmyk_color = helpers.rgb_to_cmyk( *helpers.hsv_to_rgb(360.0 / dims["x"] * x, 0.75, 0.9)) contrasts = self.get_contrasts(cmyk_color) for y in range(0, dims["y"], dims["pixel_size"]): image["pixels"].extend( self.get_pixel(cmyk_color, contrasts, x, y, dims["pixel_size"])) return image
def apply_brightness(self, colorArray, brightness=None): """Apply brightness modification to the colors Args: colorArray (ndarray): input array Returns: ndarray: output array with colors modified with brightness """ hsv = rgb_to_hsv(colorArray) hsv[:, 2] *= brightness if brightness is not None else self.brightness rgb = hsv_to_rgb(hsv) return rgb.astype(np.int32)
def get_color_rgb(self): hsv = self.get_color_hsv() return helpers.hsv_to_rgb(*hsv)
def append_hsv(self, *hsvvals): h,s,v = hsvvals self.append(map(lambda x: int(x * 255), hsv_to_rgb(h,s,v)))