Created
July 6, 2014 03:05
-
-
Save MeilCli/4cc04cce77d9ce8df56b to your computer and use it in GitHub Desktop.
カラーコードを虹色みたいに表示するあれ
This file contains 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
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | |
<!-- jquery.min.jsが必要 --> | |
<script src="jquery.min.js"></script> | |
<script type="text/javascript"> | |
//関数名はループするRGBの順+飛ばす数 | |
function rgb16(){ | |
rgb(16,1); | |
} | |
function rgb32(){ | |
rgb(32,1); | |
} | |
function rbg16(){ | |
rgb(16,2); | |
} | |
function rbg32(){ | |
rgb(32,2); | |
} | |
function grb16(){ | |
rgb(16,3); | |
} | |
function grb32(){ | |
rgb(32,3); | |
} | |
function gbr16(){ | |
rgb(16,4); | |
} | |
function gbr32(){ | |
rgb(32,4); | |
} | |
function brg16(){ | |
rgb(16,5); | |
} | |
function brg32(){ | |
rgb(32,5); | |
} | |
function bgr16(){ | |
rgb(16,6); | |
} | |
function bgr32(){ | |
rgb(32,6); | |
} | |
//汎用性あげたからものすごく汚い | |
function rgb(i,type){ | |
var R,G,B; | |
var i1,i2,i3; | |
var data = ''; | |
for(i1=0;i1<256;i1+=i){ | |
for(i2=0;i2<256;i2+=i){ | |
for(i3=0;i3<256;i3+=i){ | |
if(type==1){ | |
R=i1; | |
G=i2; | |
B=i3; | |
}else if(type==2){ | |
R=i1; | |
G=i3; | |
B=i2; | |
}else if(type==3){ | |
R=i2; | |
G=i1; | |
B=i3; | |
}else if(type==4){ | |
R=i3; | |
G=i1; | |
B=i2; | |
}else if(type==5){ | |
R=i2; | |
G=i3; | |
B=i1; | |
}else if(type==6){ | |
R=i3; | |
G=i2; | |
B=i1; | |
} | |
data = data+makeDiv(toColorCode(R,G,B)); | |
} | |
} | |
} | |
replace(data); | |
} | |
function makeDiv(colorCode){ | |
return '<div style="height: 1px;background: '+colorCode+'" />\n' | |
} | |
function toColorCode(R,G,B){ | |
var code = '#'+toHexString(R)+toHexString(G)+toHexString(B); | |
return code; | |
} | |
function toHexString(i){ | |
if(i>15){ | |
return i.toString(16); | |
}else{//R=0,G=0,B=0などの場合#000になる | |
return '0'+i.toString(16); | |
} | |
} | |
function replace(data){ | |
$('#color').html(data); | |
} | |
</script> | |
</head> | |
<body> | |
<button onclick="rgb16()">rgb16</button> | |
<button onclick="rgb32()">rgb32</button> | |
<button onclick="rbg16()">rbg16</button> | |
<button onclick="rbg32()">rbg32</button> | |
<button onclick="grb16()">grb16</button> | |
<button onclick="grb32()">grb32</button> | |
<button onclick="gbr16()">gbr16</button> | |
<button onclick="gbr32()">gbr32</button> | |
<button onclick="brg16()">brg16</button> | |
<button onclick="brg32()">brg32</button> | |
<button onclick="bgr16()">bgr16</button> | |
<button onclick="bgr32()">bgr32</button> | |
<br> | |
<div id="color"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jquery.min.jsが同階層に必要だよ
あと文字コードはutf-8