Created
August 12, 2025 00:03
-
-
Save Frontear/f0f3cc2c0f49b7b0b4232e660048d04b to your computer and use it in GitHub Desktop.
A quick python script I wrote to transform the base16 colors of the onedark theme
This file contains hidden or 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
#!/usr/bin/env python3 | |
import yaml | |
import colorsys | |
def hex2rgb(hex: str) -> tuple[int]: | |
return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4)) | |
def rgb2hex(rgb: tuple[int]): | |
return "%x%x%x" % rgb | |
if __name__ == "__main__": | |
with open("onedark.yaml", "r") as f: | |
theme = yaml.safe_load(f) | |
for k, v1 in theme["palette"].items(): | |
old = colorsys.rgb_to_hls(*hex2rgb(v1.lstrip('#'))) | |
new = colorsys.hls_to_rgb(old[0], old[1] - 10, old[2]) | |
theme["palette"][k] = '#' + rgb2hex(tuple([round(x) for x in new])) | |
with open("base16.yaml", "w") as f: | |
yaml.dump(theme, f) | |
# 282c34 ===> 1f2329 | |
# abb2bf ===> a0a8b7 | |
""" | |
bg1, bg2 = hex2rgb("282c34"), hex2rgb("1f2329") | |
fg1, fg2 = hex2rgb("abb2bf"), hex2rgb("a0a8b7") | |
bg1_hls, bg2_hls = colorsys.rgb_to_hls(*bg1), colorsys.rgb_to_hls(*bg2) | |
fg1_hls, fg2_hls = colorsys.rgb_to_hls(*fg1), colorsys.rgb_to_hls(*fg2) | |
print(bg1_hls); print(bg2_hls); print("\n") | |
print(fg1_hls); print(fg2_hls); print("\n") | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original theme came from: https://github.com/tinted-theming/schemes/blob/spec-0.11/base16/onedark.yaml
The colors that I wanted came from: https://github.com/navarasu/onedark.nvim/blob/master/lua/onedark/palette.lua
Using Python, I converted the colors from Hex to RGB, then RGB to HLS. I saw a pattern in how the colors transformed between the two themes, and replicated that transformation across all colors.
It's good to note that this isn't a 100% accurate conversion. Small rounding flaws, slight color variants in the magnitude of
0.5–4
in any/all RGB values were present when testing with a small handful of sample values from the two themes. The difference is extremely negligible, so it was ignored.I actually think it might be a really cool exercise to right a machine learning program to find the transformation as well. Not a project that I'm interested in right now though.