this curve looks better
This commit is contained in:
19
gamma.py
19
gamma.py
@@ -1,14 +1,23 @@
|
||||
#!/usr/bin/python3
|
||||
"""Calculates a gamma correction curve to store
|
||||
in PROGMEM for a NeoPixel"""
|
||||
|
||||
GAMMA = 2.8 # correction factor
|
||||
FACTOR = 2.8 # correction factor
|
||||
MAX_IN = 255 # top end of INPUT range
|
||||
MAX_OUT = 255 # top end of OUTPUT range
|
||||
|
||||
print('{ \\')
|
||||
for index in range(MAX_IN):
|
||||
print('{', end='')
|
||||
for index in range(MAX_IN + 1):
|
||||
if index > 0:
|
||||
print(',', end='')
|
||||
if index & 15 == 0:
|
||||
print()
|
||||
print('%3d' % ((index / MAX_IN) ** GAMMA * MAX_OUT + 0.5), end='')
|
||||
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('}')
|
||||
|
||||
Reference in New Issue
Block a user