I have two colors for example color_1 = qtgui.qolor ('# 0000FF')
and color_2 = qtgui.qcolor ('# FF0000')
I want to drive a variable value Val
and get the average between two colors
For example
if val = 10
then color = '# 0000FF'
if val = 0
then color = '# FF0000'
If Val = 3
then color = color_1.30% + color_2.70%
If Val = 5
then color = color_1.50% + color_2.50%
How can I do it?
Answer 1, Authority 100%
c1 = '# 0000FF'
C2 = '# FF0000'
C1B = bytes.Fromhex (C1 [1:])
C2B = bytes.Fromhex (C2 [1:])
Color3 = Bytes (Map (Lambda Chan: Int (Chan [0] * 0.3 + Chan [1] * 0.7), Zip (C1B, C2B)))
Print (# "+ Color3.Hex ())
Answer 2, Authority 150%
https://docs.python.org/2/library/colorsys.html
If simply meaning the translation into the RGB
model and the average channel value.
If you do a tarnzishche in the model HSL
hue
tone (need to be considered likeDELTA ANGLE
Since this is a looped circle)Saturation
SaturationLight
Brightness
Answer 3
Not sure what I understand you, since you did not indicate what colors you expect to get.
Looking at your formulas I propose to try this:
c1 = '# 0000FF'
C2 = '# FF0000'
Color1 = F "# {HEX (INT (C1 [1:], 16)) [2:]: & gt; 06}"
Color2 = F "# {HEX (INT (C2 [1:], 16)) [2:]: & gt; 06}"
Color3 = F "# {HEX (INT (C1 [1:], 16) // 3 + int (C2 [1:], 16) // 7) [2:]: & gt; 06}"
Color4 = F "# {HEX (INT (C1 [1:], 16) // 5 + int (C2 [1:], 16) // 5) [2:]: & gt; 06}"
Print (F '{Color1} \ N {Color2} \ N {Color3} \ N {Color4}')
Result:
# 0000FF
# FF0000.
# 246E0B.
# 330033.