Created
January 8, 2023 15:32
-
-
Save konverner/0cc0659a516252f1b6465d53c18f9ece to your computer and use it in GitHub Desktop.
it creates a color gradient of two colors, i.e. a list of hex-color strings from c1 to c2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib | |
def colorGrdient(c1: str, c2: str, n: int): | |
""" | |
c1 : color FROM (e.g. '#FFCDD2') | |
c2 : color TO (e.g. '#BBDEFB') | |
""" | |
c1=np.array(matplotlib.colors.to_rgb(c1)) | |
c2=np.array(matplotlib.colors.to_rgb(c2)) | |
return [matplotlib.colors.to_hex((1-(i/n))*c1 + (i/n)*c2) for i in range(n)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment