コード例 #1
0
function inverseHex($color)
{
    $color = TRIM($color);
    $prependHash = FALSE;
    if (STRPOS($color, '#') !== FALSE) {
        $prependHash = TRUE;
        $color = STR_REPLACE('#', NULL, $color);
    }
    switch ($len = STRLEN($color)) {
        case 3:
            $color = PREG_REPLACE("/(.)(.)(.)/", "\\1\\1\\2\\2\\3\\3", $color);
        case 6:
            break;
        default:
            TRIGGER_ERROR("Invalid hex length ({$len}). Must be (3) or (6)", E_USER_ERROR);
    }
    if (!PREG_MATCH('/[a-f0-9]{6}/i', $color)) {
        $color = HTMLENTITIES($color);
        TRIGGER_ERROR("Invalid hex string #{$color}", E_USER_ERROR);
    }
    $r = DECHEX(255 - HEXDEC(SUBSTR($color, 0, 2)));
    $r = STRLEN($r) > 1 ? $r : '0' . $r;
    $g = DECHEX(255 - HEXDEC(SUBSTR($color, 2, 2)));
    $g = STRLEN($g) > 1 ? $g : '0' . $g;
    $b = DECHEX(255 - HEXDEC(SUBSTR($color, 4, 2)));
    $b = STRLEN($b) > 1 ? $b : '0' . $b;
    return ($prependHash ? '#' : NULL) . $r . $g . $b;
}
コード例 #2
0
    array_push($wyniki, $row);
}
shuffle($wyniki);
if (count($wyniki) > 0) {
    $i = 0;
    foreach ($wyniki as $r) {
        if ($i < 8) {
            $i++;
            $rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
            $color = '#' . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)] . $rand[rand(0, 15)];
            $hashlesscolor = STR_REPLACE('#', NULL, $color);
            $rr = DECHEX(255 - HEXDEC(SUBSTR($hashlesscolor, 0, 2)));
            $rr = STRLEN($rr) > 1 ? $rr : '0' . $rr;
            $gg = DECHEX(255 - HEXDEC(SUBSTR($hashlesscolor, 2, 2)));
            $gg = STRLEN($gg) > 1 ? $gg : '0' . $gg;
            $bb = DECHEX(255 - HEXDEC(SUBSTR($hashlesscolor, 4, 2)));
            $bb = STRLEN($bb) > 1 ? $bb : '0' . $bb;
            $invcolor = '#' . $rr . $gg . $bb;
            echo "<div class=\"col-md-3 col-centered\"style=\"text-align:center;padding: 2.5% 2.5% 2.5% 2.5%;\">";
            echo "<div class=\"circle\" style=\"text-shadow: -1px 0 #444444, 0 1px #444444, 1px 0 #444444, 0 -1px #444444; border: 1px solid black;color:" . $invcolor . "; background-color:" . $color . "\">";
            echo "<a href=\"sesja.php?sesja=" . $r['id_sesji'] . "\">";
            echo "<h2>" . $r['lokalizacja'] . "</h2>";
            echo "<p>" . $r['data'] . "</p>";
            echo "</a>";
            echo "</div>";
            echo "</div>";
        } else {
            break;
        }
    }
} else {