Skip to content

Instantly share code, notes, and snippets.

@paigeadelethompson
Last active January 6, 2023 11:13
Show Gist options
  • Save paigeadelethompson/7ecbf0222122408b9250612a38f434f6 to your computer and use it in GitHub Desktop.
Save paigeadelethompson/7ecbf0222122408b9250612a38f434f6 to your computer and use it in GitHub Desktop.
phillips hue x, y color changer
import itertools
from phue import Bridge
[setattr(Bridge().groups[-4].lights[0], 'xy', [x, y]) for x, y, brightness, xyz, gamma, original in (lambda gamma,
to_x, to_y, to_z, to_xy, rgb_ranges: ((to_xy(x, y, z), to_xy(y, x, z), y, (x, y, z), gamma_corrected_rgb_values,
orig_rgb_values) for x, y, z, gamma_corrected_rgb_values, orig_rgb_values in ((to_x(r, g, b), to_y(r, g, b),
to_z(r, g, b), (r, g, b), orig_rgb_values) for r, g, b, orig_rgb_values in ((gamma(r), gamma(g), gamma(b),
(r, g, b)) for r, g, b in rgb_ranges))))(gamma = lambda c: (c > 0.04045) and pow((c + 0.055) / (1.0 + 0.055),
2.4) or (c / 12.92), to_x = lambda r, g, b: (r * 0.649926) + (g * 0.103455) + (b * 0.197109),
to_y = lambda r, g, b: (r * 0.234327) + (g * 0.743075) + (b * 0.022598), to_z = lambda r, g,
b: (r * 0.0000000) + (g * 0.053077) + (b * 1.035763), to_xy = lambda a, b, c: ((a + b + c) != 0)
and (a / (a + b + c)) or a, rgb_ranges = itertools.chain.from_iterable(itertools.chain.from_iterable(((((x,
y, z) for z in range(0, 256, 8)) for y in range(0, 256, 32)) for x in range(0, 256, 16)))))]
@paigeadelethompson
Copy link
Author

chatGPT rewrite

gamma = lambda c: (c > 0.04045) and pow((c + 0.055) / (1.0 + 0.055), 2.4) or (c / 12.92)
to_x = lambda r, g, b: (r * 0.649926) + (g * 0.103455) + (b * 0.197109)
to_y = lambda r, g, b: (r * 0.234327) + (g * 0.743075) + (b * 0.022598)
to_z = lambda r, g, b: (r * 0.0000000) + (g * 0.053077) + (b * 1.035763)
to_xy = lambda a, b, c: ((a + b + c) != 0) and (a / (a + b + c)) or a
rgb_ranges = itertools.chain.from_iterable(itertools.chain.from_iterable(((((x, y, z) for z in range(0, 256, 8)) 
                                                                            for y in range(0, 256, 32)) 
                                                                           for x in range(0, 256, 16))))

for r, g, b, orig_rgb_values in ((gamma(r), gamma(g), gamma(b), (r, g, b)) for r, g, b in rgb_ranges):
    x, y, z = to_x(r, g, b), to_y(r, g, b), to_z(r, g, b)
    xy, yx, brightness, xyz, gamma_corrected_rgb_values, original = to_xy(x, y, z), to_xy(y, x, z), y, (x, y, z), (r, g, b), orig_rgb_values
    Bridge().groups[-4].lights[0].xy = xy
    ```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment