This method converts color values from hue-saturation-lightness (HSL) to it's red-green-blue representation.
Check out the demo!
Special thanks to tsaniel, Alex Kloss, subzey, Jed Schmidt, and maettig for there unbelievable magic and effort!
See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.
To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to the wiki.
140byt.es is brought to you by Jed Schmidt, with help from Alex Kloss. It was inspired by work from Thomas Fuchs and Dustin Diaz.
@subzey, what the ...? This is crazy. Why does this work? Lets see.
(a + 2) % 6
(a + 2 + 6) % 6
Adding 6 does nothing because of the modulo operator.(a + 8) % 6
Result must be 2^n (e.g. 1, 2, 4, 8, 16 and so on).(a | 8) % 6
Replacing+
with|
only works ifa
is lower than the 2^n used.This looks strange but works. Speaking binary, this sets the bit 1000b and truncates decimal places at the same time. But the number must be in the 000b to 111b range. Good work. Down at 114 bytes.
@LeverOne (you edited your comment so I will edit mine), now I see. This applies to my version with error checking. Turning
b*(a%1)
toa%1*b
was also mentioned by @subzey. Clipping withc=c>1||c
is very cool. Ifc
is greater than 1 it returnstrue
which becomes 1. Now this version is 133 bytes (without the approach from @subzey so hue accepts all positive values).