Skip to content

Instantly share code, notes, and snippets.

@bombless
Created December 14, 2012 15:13
Show Gist options
  • Save bombless/4286145 to your computer and use it in GitHub Desktop.
Save bombless/4286145 to your computer and use it in GitHub Desktop.
Generate YUV color !!!
<!DOCTYPE html>
<html><body>
<script type="text/javascript">
(function(){
function genYUVColor(input){
var Y,U,V;
var R,G,B;
Y = Math.floor(input / 65536);
U = Math.floor(input % 65536 / 256);
V = Math.floor(input % 256);
document.write('<div>YUV(' + Y + ',' + U + ',' + V + ')</div>');
R = Math.floor(Y + 1.14 * V);
G = Math.floor(Y - 0.39 * U - 0.58 * V);
B = Math.floor(Y + 2.03 * U);
return 'rgb(' + R + ',' + G + ',' + B + ')';
}
var i,j,color = 0,div,myColor;
for(i = 0; i < 3; ++i){
for(j = 0; j < 256; ++j, ++color){
if(color % 42 == 0,true){
(function(div){
div.style.width = '100%';
div.style.height = '1px';
myColor = genYUVColor(color);
div.style.background = myColor;
div.style.color = div.style.background;
//div.innerHTML = div.style.color;
document.body.appendChild(div);
document.write('color ' + myColor + ';');
})(document.createElement('div'));
}
}
}
})();
</script></body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment