This repository has been archived on 2026-08-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
drizzli/src/routes/weather/utils/colour-gradient.ipynb
T
2026-01-07 22:24:02 +01:00

23 KiB

Generating colours

In [36]:
import os
import json
from colour import Color

def flatten(xss):
    return [x for xs in xss for x in xs]

deep_purple = Color("#4F00A3")
dark_blue = Color("#0117DB")
light_blue = Color("#01B1FF")
light_green = Color("#00FFC2")
dark_green = Color("#00D139")
warm_green = Color("#FFFF00")
light_orange = Color("#FFC600")
middle_orange = Color("#FFA200")
dark_orange = Color("#FF640A")
deep_red = Color("#9E1500")

colors = [
    list(deep_purple.range_to(dark_blue,15)),
    list(dark_blue.range_to(light_blue,13)),
    list(light_blue.range_to(light_green,13)),
    list(light_green.range_to(dark_green,8)),
    list(dark_green.range_to(warm_green,14)),
    list(warm_green.range_to(light_orange,8)),
    list(light_orange.range_to(middle_orange,9)),
    list(middle_orange.range_to(dark_orange,10)),
    list(dark_orange.range_to(deep_red,11)),
]

colors = flatten(colors)

color_list = []
rgb_list = []
hsl_list = []
hex_list = []

temp_x= []
temp_height= []

for [ind, color] in enumerate(colors):
    x = -40 + ind
    color_list.append(color.hex)
    hex_list.append(color.hex)
    rgb_list.append(color.rgb)
    hsl_list.append(color.hsl)
    temp_x.append(x)
    temp_height.append(1)

Visualisation

In [37]:
%matplotlib ipympl

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()
ax.axes.get_xaxis().set_visible(False)
ax.barh(temp_x, temp_height, color=list(color_list), align='edge', height=1)
Out [37]:
<BarContainer object of 101 artists>
In [38]:
plt.close()

Exporting

In [39]:
# os.chdir(pwd)

with open("color-scale-rgb.ts", "w+") as f:
    f.write("export default ")
    f.write(json.dumps(hsl_list))

with open("color-scale-hsl.ts", "w+") as f:
    f.write("export default ")
    f.write(json.dumps(rgb_list))
    
with open("color-scale-hex.ts", "w+") as f:
    f.write("export default ")
    f.write(json.dumps(hex_list))