1

そのため、ヘッダーの色を毎日変更することに取り組んでおり、ランダムな色を使用してこれを作成しようとしていました。ヘッダーには2色あり、補色にしています。最初の色はランダムに生成され、2 番目の色は 150` を介して色相を変更することで変更されます。問題は、特定の色を選択すると、鮮やかすぎたり暗すぎたりする可能性があることです。明るさの値をわずかに制御できるようにチェックを実行していますが、明るすぎる色がまだいくつかあります (極端な黄色など)。以下に私のコードを掲載します。どんな助けや提案も大歓迎です!ありがとう!

// grab a random color on hue 
$h = rand(0,360);

// color values 50-120 tend to be extremely bright, 
// make adjustments to the S and L accordingly
// a better solution is available?
if ($h > 50 && $h < 120) {
    $s = rand(60,80);
    $l = rand(30,50);
} else {
    $s = rand(60,90);
    $l = rand(38,63);
}

// declare string to place as css in file for primary color           
$randomColor = "hsl(". $h .",". $s ."%,". $l ."%)";

// declare degree for secondary color (30 = analogous, 150 = complimentary)
$degree = 150;

// point to secondary color randomly on either side of chart        
$bool = rand(0,1);
if ($bool) {
    $x = $degree;
} else {
    $x = -$degree;
} 

// set value of the new hue
$nh = $h + $degree;

// if the new hue is above 360 or below 0, make adjustments accordingly
if ($nh > 360) {
    $nh -= 360;
}
if ($nh < 0 ) {
    $nh = 360 - $nh;
}

// set the secondary color
$secondaryColor = "hsl(". abs($h + $x) .",". $s ."%,". $l ."%)";

これは非常に簡単に思えますが、もっと良い方法があると確信しています。私は周りを見回しましたが、私が気づいたのは色相などの基本的な式のビア度だけでした. ありがとうございました!

4

1 に答える 1