Created
August 9, 2025 17:25
-
-
Save kbob/c93e9fcfda836462d2e6f01bcffd294b to your computer and use it in GitHub Desktop.
Cube Edges w/ Hue Quantization
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
| // For Evil Genius Labs 8x8x8 LED cube running PixelBlaze | |
| phi = (sqrt(5) + 1) / 2 // golden ratio | |
| hq = 32 // hue quantization, try integers 3-10 for fun | |
| export function beforeRender(delta) { | |
| t1 = time(.1) | |
| t2 = time(.04) | |
| } | |
| function is_at(v, lo, hi) { | |
| return (v == lo || v == hi) - (v < lo || v > hi) | |
| } | |
| export function render(index) { | |
| x = floor(index / 8) % 8 | |
| y = index % 8 | |
| z = floor(index / 8 / 8) | |
| // fn == 1 if pixel on frame of cube n | |
| f1 = (is_at(x, 0, 7) + is_at(y, 0, 7) + is_at(z, 0, 7)) >= 2 | |
| f2 = (is_at(x, 1, 6) + is_at(y, 1, 6) + is_at(z, 1, 6)) >= 2 | |
| f3 = (is_at(x, 2, 5) + is_at(y, 2, 5) + is_at(z, 2, 5)) >= 2 | |
| v1 = smoothstep(0, .3, wave((x + y + z) / 3 / 8 - t2)) | |
| v2 = smoothstep(0, .4, wave(-(x + y + z) / 2 / 8 - t2)) | |
| v3 = smoothstep(0, .5, wave((x - y + z) / 2 / 8 - t2)) | |
| // d: spatial dither, 2 bits | |
| d = ((x + y + z) & 3) / 4 | |
| h = t1 + phi * f2 + (2 * phi) * f3 | |
| h = floor(hq * h + d) / hq | |
| s = 1 | |
| v = f1 * v1 + f2 * v2 + f3 * v3 | |
| hsv(h, s, v) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment