Change the saturation and brightness of color specifications like # ff000 in python 2.5

import colorsys
import struct
## e.g. gradient_color("#ff0000", 0.66, 0.91) #=> "#e84e4e"
def gradient_color(color, saturation_ratio, brightness_ratio):
    rgb0 = struct.unpack('BBB', color[1:].decode('hex'))
    h, s, v = colorsys.rgb_to_hsv(*[x / 255.0 for x in rgb0])
    rgb1 = colorsys.hsv_to_rgb(h, s * saturation_ratio, v * brightness_ratio)
    return "#" + struct.pack('BBB', *[x * 255 for x in rgb1]).encode('hex')

Recommended Posts

Change the saturation and brightness of color specifications like # ff000 in python 2.5
[Python] Change the text color and background color of a specific keyword in print output
Change the color of Fabric errors and warnings
Open an Excel file in Python and color the map of Japan
[Machine learning] "Abnormality detection and change detection" Let's draw the figure of Chapter 1 in Python.
[Tips] Problems and solutions in the development of python + kivy
The story of Python and the story of NaN
Change the Python version of Homebrew
How to change the color of just the button pressed in Tkinter
Feel free to change the label of the legend in Seaborn in python
Get the title and delivery date of Yahoo! News in Python
Change the length of Python csv strings
Check the behavior of destructor in Python
The result of installing python in Anaconda
The basics of running NoxPlayer in Python
In search of the fastest FizzBuzz in Python
Project Euler # 1 "Multiples of 3 and 5" in Python
Graph of the history of the number of layers of deep learning and the change in accuracy
Comparing the basic grammar of Python and Go in an easy-to-understand manner
Output the number of CPU cores in Python
plot the coordinates of the processing (python) list and specify the number of times in draw ()
[Python] Sort the list of pathlib.Path in natural sort
Summary of the differences between PHP and Python
Change the font size of the legend in df.plot
I compared the speed of regular expressions in Ruby, Python, and Perl (2013 version)
Get the caller of a function in Python
The answer of "1/2" is different between python2 and 3
View the result of geometry processing in Python
Extract the color of the object in the image with Mask R-CNN and K-Means clustering
Divides the character string by the specified number of characters. In Ruby and Python.
Specifying the range of ruby and python arrays
In Python, change the behavior of the method depending on how it is called
Make a copy of the list in Python
About the difference between "==" and "is" in python
Find the divisor of the value entered in python
Compare the speed of Python append and map
Find the solution of the nth-order equation in python
The story of reading HSPICE data in Python
[Note] About the role of underscore "_" in Python
About the behavior of Model.get_or_create () of peewee in Python
Solving the equation of motion in Python (odeint)
Output in the form of a python array
About the * (asterisk) argument of python (and itertools.starmap)
A discussion of the strengths and weaknesses of Python
Explanation of edit distance and implementation in Python
Get the last element of the array by splitting the string in Python and PHP
I compared the speed of the reference of the python in list and the reference of the dictionary comprehension made from the in list.
Check the processing time and the number of calls for each process in python (cProfile)
"Linear regression" and "Probabilistic version of linear regression" in Python "Bayesian linear regression"
Experience the good calculation efficiency of vectorization in Python
The simplest Python memo in Japan (classes and objects)
Full-width and half-width processing of CSV data in Python
Receive the form in Python and do various things
The story of Python without increment and decrement operators.
How to get the number of digits in Python
Calculation of standard deviation and correlation coefficient in Python
The process of installing Atom and getting Python running
Existence check of external command in Python (like `which`)
Python --Explanation and usage summary of the top 24 packages
[python] Get the list of classes defined in the module
Carefully understand the exponential distribution and draw in Python