Created
January 4, 2020 20:05
-
-
Save tildebyte/1a9e593bf7eb687e37fc27a31f3d27fd to your computer and use it in GitHub Desktop.
Very ugly Jupyter Python notebook for color conversions, specifically for Launchpad Pro RGB LEDs
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 56, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from colormath.color_objects import LabColor, AdobeRGBColor\n", | |
"from colormath.color_conversions import convert_color\n", | |
"import re" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 48, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def remap_mul(val):\n", | |
" four = 0x04\n", | |
" return hex(round(val*four) - 1)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 49, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def remap_div(val):\n", | |
" four = 0x04\n", | |
" return hex(round(val/four) - 1)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 123, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"nums = [0x3d,0x11,0x21]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 124, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"#f34383\n" | |
] | |
} | |
], | |
"source": [ | |
"out = ''\n", | |
"for i in nums:\n", | |
" out += str(remap_mul(i))\n", | |
"rgb_hex = '#' + str.replace(out, '0x', '')\n", | |
"rgb_hex = str.replace(rgb_hex, '-', '0')\n", | |
"print(rgb_hex)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 125, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"LabColor (lab_l:63.1758 lab_a:80.8536 lab_b:12.9054)\n" | |
] | |
} | |
], | |
"source": [ | |
"a_rgb = AdobeRGBColor.new_from_rgb_hex(rgb_hex)\n", | |
"lab = convert_color(a_rgb, LabColor)\n", | |
"print(lab)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 126, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"#d4116a\n" | |
] | |
} | |
], | |
"source": [ | |
"new_lab = LabColor(lab_l=53, lab_a=80.8536, lab_b=12.9054, illuminant='d65')\n", | |
"new_a_rgb = convert_color(new_lab, AdobeRGBColor)\n", | |
"print(new_a_rgb.get_rgb_hex())" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 127, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"nums = [0xd4,0x11,0x6a]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 128, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'#34319'" | |
] | |
}, | |
"execution_count": 128, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"out = ''\n", | |
"for i in nums:\n", | |
" out += str(remap_div(i))\n", | |
"'#' + str.replace(out, '0x', '')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment