Created
November 29, 2011 03:57
-
-
Save kijtra/1403336 to your computer and use it in GitHub Desktop.
[PHP] ある色の補色(反対色)を返す関数。計算ではなく単に反対の文字を返すだけなのでRGB値には非対応・・・
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
<?php | |
function complementary($hex){ | |
static $_out; | |
if(!empty($_out[$hex])){ | |
return $_out[$hex]; | |
} | |
$_out=array(); | |
$in=(strpos($hex,'#')===0) ? substr($hex,1) : $hex; | |
$in=strtoupper($in); | |
if(strlen($in)==3){ | |
$r=substr($in,0,1); | |
$g=substr($in,1,1); | |
$b=substr($in,2,1); | |
$in=$r.$r.$g.$g.$b.$b; | |
} | |
$a='0123456789ABCDEF'; | |
$b='FEDCBA9876543210'; | |
$out=NULL; | |
foreach(str_split($in) as $v){ | |
$out.=$b{strpos($a,$v)}; | |
} | |
return $_out[$hex]=$out; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment