Skip to content

Instantly share code, notes, and snippets.

@christopherdebeer
Forked from 140bytes/LICENSE.txt
Created June 1, 2011 13:40
Show Gist options
  • Save christopherdebeer/1002308 to your computer and use it in GitHub Desktop.
Save christopherdebeer/1002308 to your computer and use it in GitHub Desktop.
RGB to Luminosity (140byt.es)
function(
r, // red, as a number from 0 to 255
g, // green, as a number from 0 to 255
b, // blue, as a number from 0 to 255
p // as goog a place as any to declare p
){
p = Math.pow; // alias for "Math.pow"
return // return a luminosity value madeup of
0.2126 * p(r/255, 2.2) + // the red value plus
0.7152 * p(g/255, 2.2) + // the green value plus
0.0722 * p(b/255, 2.2) // the blue value
}
function(r,g,b,p){p=Math.pow;return 0.2126*p(r/255,2.2)+0.7152*p(g/255,2.2)+0.0722*p(b/255,2.2)}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "RGBtoLum",
"description": "Calculate the luminosity of a colour based on its RGB values",
"keywords": [
"RGB",
"colour",
"color",
"Luminosity",
"Calculation"
]
}
@christopherdebeer
Copy link
Author

thanks :)

@Kambfhase
Copy link

looks cool! by omitting the leading 0 on floats .34 you can save some more bytes! Plus that makes it possible to save another byte if you leave out the space after return!

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