本文整理汇总了Python中colormath.color_objects.RGBColor.set_from_rgb_hex方法的典型用法代码示例。如果您正苦于以下问题:Python RGBColor.set_from_rgb_hex方法的具体用法?Python RGBColor.set_from_rgb_hex怎么用?Python RGBColor.set_from_rgb_hex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类colormath.color_objects.RGBColor
的用法示例。
在下文中一共展示了RGBColor.set_from_rgb_hex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: contrast_text
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import set_from_rgb_hex [as 别名]
def contrast_text(self):
"""Returns hex code of a color that contrasts with this one, for
overlaying text. Includes the #."""
# get rgb and hsv values
rgbcolor = RGBColor()
rgbcolor.set_from_rgb_hex(self.color_hex)
hsvcolor = rgbcolor.convert_to('hsv')
new_v = hsvcolor.hsv_v;
if new_v <= .55:
new_v = 1.0;
elif new_v > .55:
new_v = 0.0;
new_h = hsvcolor.hsv_h
new_s = 0
contrast = HSVColor(hsv_h = new_h, hsv_s = new_s, hsv_v = new_v)
contrast_rgb = contrast.convert_to('rgb')
return contrast_rgb.get_rgb_hex()
示例2: get_rgb
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import set_from_rgb_hex [as 别名]
def get_rgb(self):
""" return the color as a list """
if not hasattr(self, '_rgb'):
c = RGBColor()
c.set_from_rgb_hex(self.sRGB)
self._rgb = (c.rgb_r / 255.0, c.rgb_g / 255.0, c.rgb_b / 255.0)
return self._rgb
示例3: get_lab
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import set_from_rgb_hex [as 别名]
def get_lab(self):
""" returns the current point in L*a*b* """
if not hasattr(self, '_lab'):
c = RGBColor()
c.set_from_rgb_hex(self.sRGB)
self._lab = c.convert_to('lab').get_value_tuple()
return self._lab
示例4: extract_bsdf
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import set_from_rgb_hex [as 别名]
def extract_bsdf(wd):
color=RGBColor()
color.set_from_rgb_hex(wd.color)
lab=color.convert_to('lab')
c=wd.contrast
d=wd.d()
return lab,(c,d)
示例5: save
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import set_from_rgb_hex [as 别名]
def save(self, *args, **kwargs):
if (self.color_L is None) or (self.color_a is None) or (self.color_b is None):
c = RGBColor()
c.set_from_rgb_hex(self.color)
c = c.convert_to('lab')
self.color_L = c.lab_l
self.color_a = c.lab_a
self.color_b = c.lab_b
super(ShapeBsdfLabel_wd, self).save(*args, **kwargs)
示例6: scaled_rgb
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import set_from_rgb_hex [as 别名]
def scaled_rgb(hex_color, component=None, factor=1.0):
rgb_color = RGBColor()
rgb_color.set_from_rgb_hex(hex_color)
values = list(map(lambda x: factor * (x / 255), rgb_color.get_value_tuple()))
if component is None:
return '{} {} {}'.format(*rgb_color.get_value_tuple())
else:
comp_idx = ('R', 'G', 'B').index(component)
return '{}'.format(values[comp_idx])
示例7: find_color_opeds
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import set_from_rgb_hex [as 别名]
def find_color_opeds(rgb_hex):
'Returns matching opeds for a given color'
color = RGBColor()
color.set_from_rgb_hex('#' + rgb_hex)
cursor = db_find(color)
colors = mongo_to_colors(cursor)
results = find_closest(color, colors)[:MAX_COLOR_RESULTS]
opeds = [result[0] for result in results]
return opeds
示例8: alter_lch
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import set_from_rgb_hex [as 别名]
def alter_lch(hex_color, value, component='L', relative=True):
rgb_color = RGBColor()
rgb_color.set_from_rgb_hex(hex_color)
lch_color = rgb_color.convert_to('lchab')
lch_lst = list(lch_color.get_value_tuple())
comp_idx = ('L', 'C', 'H').index(component)
lch_lst[comp_idx] = lch_lst[comp_idx] + value if relative else value
L, C, H = lch_lst
lch_res = LCHabColor(L, C, H)
return lch_to_hex(lch_res)
示例9: fromRGBAHex
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import set_from_rgb_hex [as 别名]
def fromRGBAHex(self, rgba_hex, background_hex):
self.fromRGBHex(rgba_hex[:7])
if len(rgba_hex) > 7:
opacity = int(100 * (int(rgba_hex[7:], 16) / 255))
background = RGBColor()
if len(background_hex) > 7:
background_hex = "#ffffff"
background.set_from_rgb_hex(background_hex)
self.mix(background, opacity)
示例10: update_shape_dominant_delta
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import set_from_rgb_hex [as 别名]
def update_shape_dominant_delta(shape, save=True):
""" Update shape dominant_delta """
if not shape.dominant_rgb0 or not shape.dominant_rgb1:
return
c0 = RGBColor()
c1 = RGBColor()
c0.set_from_rgb_hex(shape.dominant_rgb0)
c1.set_from_rgb_hex(shape.dominant_rgb1)
shape.dominant_delta = c0.delta_e(c1)
if save:
shape.save()
示例11: handle
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import set_from_rgb_hex [as 别名]
def handle(self, *args, **options):
comparisons = []
comparisons += IntrinsicPointComparison.objects.all() \
.filter(point1_image_darker__isnull=True) \
.values_list('id', 'point1__sRGB', 'point2__sRGB')
comparisons += IntrinsicPointComparisonResponse.objects.all() \
.filter(reflectance_eq=False, reflectance_dd__isnull=True) \
.order_by().distinct('comparison') \
.values_list('comparison__id', 'comparison__point1__sRGB', 'comparison__point2__sRGB')
comparisons = list(set(comparisons))
for (id, sRGB1, sRGB2) in progress_bar(comparisons):
c1 = RGBColor()
c1.set_from_rgb_hex(sRGB1)
l1 = c1.convert_to('lab').lab_l
c2 = RGBColor()
c2.set_from_rgb_hex(sRGB2)
l2 = c2.convert_to('lab').lab_l
if l1 < l2:
IntrinsicPointComparison.objects \
.filter(id=id).update(point1_image_darker=True)
IntrinsicPointComparisonResponse.objects \
.filter(comparison_id=id, darker="1") \
.update(reflectance_eq=False, reflectance_dd=True)
IntrinsicPointComparisonResponse.objects \
.filter(comparison_id=id, darker="2") \
.update(reflectance_eq=False, reflectance_dd=False)
else:
IntrinsicPointComparison.objects \
.filter(id=id).update(point1_image_darker=False)
IntrinsicPointComparisonResponse.objects \
.filter(comparison_id=id, darker="1") \
.update(reflectance_eq=False, reflectance_dd=False)
IntrinsicPointComparisonResponse.objects \
.filter(comparison_id=id, darker="2") \
.update(reflectance_eq=False, reflectance_dd=True)
IntrinsicPointComparisonResponse.objects \
.filter(comparison_id=id, darker="E") \
.update(reflectance_eq=True, reflectance_dd=None)
示例12: set_light
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import set_from_rgb_hex [as 别名]
def set_light(self, light, hex, brightness=0, on=True):
rgb = RGBColor()
rgb.set_from_rgb_hex(hex)
color = rgb.convert_to('hsv')
bri = int(color.hsv_v * 254)
hue = int(color.hsv_h * 200)
sat = int(color.hsv_s * 254)
if brightness > 0:
bri = brightness
params = {
"on": on,
"bri": bri,
"hue": hue,
"sat": sat,
}
params = json.dumps(params)
self.send_data(light, params)
示例13: refresh_values
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import set_from_rgb_hex [as 别名]
def refresh_values(self):
if not self.color_hex.islower():
self.color_hex = self.color_hex.lower()
# get rgb and hsv values
rgbcolor = RGBColor()
rgbcolor.set_from_rgb_hex(self.color_hex)
hsvcolor = rgbcolor.convert_to('hsv')
self.R = rgbcolor.rgb_r
self.G = rgbcolor.rgb_g
self.B = rgbcolor.rgb_b
self.H = round(hsvcolor.hsv_h)
# need to multiply by 100 to get the percent
self.S = round(hsvcolor.hsv_s * 100.0)
self.V = round(hsvcolor.hsv_v * 100.0)
# make rounded values
self.rR = round_rgb_colorvalue(self.R)
self.rG = round_rgb_colorvalue(self.G)
self.rB = round_rgb_colorvalue(self.B)
round_rgb = RGBColor(rgb_r = self.rR, rgb_g = self.rG, rgb_b = self.rB)
round_hsv = round_rgb.convert_to('hsv')
self.rounded_hex = round_rgb.get_rgb_hex()[1:7]
self.rH = round_hsv.hsv_h
self.rS = round_hsv.hsv_s
self.rV = round_hsv.hsv_v
# check to see if this is a round color
if self.R == self.rR and self.G == self.rG and self.B == self.rB:
self.is_round = True
else:
self.is_round = False
示例14: E2
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import set_from_rgb_hex [as 别名]
def E2(shape):
if shape.substance_entropy>2.0:
yield 10000.0
yield 10000.0
yield 10000.0
yield 10000.0
return
color=RGBColor()
color.set_from_rgb_hex(shape.dominant_rgb0)
lab2=color.convert_to('lab')
yield lab.delta_e(lab2) # cie2000 delta e
color.set_from_rgb_hex(shape.dominant_rgb1)
lab2=color.convert_to('lab')
yield lab.delta_e(lab2) # cie2000 delta e
color.set_from_rgb_hex(shape.dominant_rgb2)
lab2=color.convert_to('lab')
yield lab.delta_e(lab2) # cie2000 delta e
color.set_from_rgb_hex(shape.dominant_rgb3)
lab2=color.convert_to('lab')
yield lab.delta_e(lab2) # cie2000 delta e
示例15: fromRGBHex
# 需要导入模块: from colormath.color_objects import RGBColor [as 别名]
# 或者: from colormath.color_objects.RGBColor import set_from_rgb_hex [as 别名]
def fromRGBHex(self, rgb_hex):
rgb = RGBColor()
rgb.set_from_rgb_hex(rgb_hex)
self._fromRGBColor(rgb)