Files
gamma-correction/gamma.py
Keiran 9280413b35 factor 2.7
2.6 looks best with solid colors but makes rainbow derp
2.7 a good trade-off
2019-03-28 21:49:54 -04:00

24 lines
596 B
Python
Executable File

#!/usr/bin/python3
"""Calculates a gamma correction curve to store
in PROGMEM for a NeoPixel"""
FACTOR = 2.7 # correction factor
MAX_IN = 255 # top end of INPUT range
MAX_OUT = 255 # top end of OUTPUT range
print('{', end='')
for index in range(MAX_IN + 1):
if index > 0:
print(',', end='')
if index & 15 == 0:
print(' \\')
if index == 0:
val = 0
elif index == MAX_IN:
val = MAX_IN
else:
val = (index / MAX_IN) ** FACTOR * MAX_OUT + 0.5
val = - (- val // 1) # round up
print('{0:>3d}'.format(int(val)), end='')
print('}')