SwooleʵÏÖ¸ßÐÔÄܵÄÑÕÉ«ÌìÉúÆ÷µÄÉè¼ÆÓëʵÏÖ
½üЩÄêÀ´£¬Ëæ×Å»¥ÁªÍøÓ¦ÓõĿìËÙÉú³¤£¬ÈËÃǹØÓÚÍøÒ³Éè¼Æ¼°Óû§ÌåÑéµÄÒªÇóÒ²Ô½À´Ô½¸ß¡£ÆäÖУ¬ÑÕÉ«µÄÔËÓÃÊǺÜÊÇÖ÷ÒªµÄÒ»²¿·Ö¡£ÔÚÍøÒ³Éè¼ÆÖУ¬ÑÕÉ«Äܹ»¼«´óµØÓ°ÏìÓû§µÄ¸Ð¹ÙÌåÑéºÍÊÓ¾õЧ¹û¡£Òò´Ë£¬ÔõÑù¿ìËÙ¡¢¸ßЧµØÌìÉúÑŹ۵ÄÑÕÉ«³ÉΪÁËÍøÒ³Éè¼Æʦ²»µÃ²»ÃæÁÙµÄÎÊÌâ¡£
ÔÚÕâ¸öÅä¾°Ï£¬SwooleµÄ·ºÆðΪÎÒÃÇÌṩÁËÒ»ÖÖȫеÄ˼Ð÷£¬Äܹ»×ÊÖúÎÒÃǸü¿ìËٵؽâ¾öÕâ¸öÎÊÌâ¡£SwooleÊÇÒ»¿î¿ªÔ´µÄ¸ßÐÔÄÜÍøÂçͨѶ¿ò¼Ü£¬Äܹ»ÌṩÒì²½±à³ÌµÄÖ§³Ö£¬ÒÔ¼°Ð³ÌµÄʵÏֵȶàÖÖ¹¦Ð§¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«½èÖúSwoole¿ò¼ÜʵÏÖÒ»¸ö¸ßÐÔÄܵÄÑÕÉ«ÌìÉúÆ÷£¬ÒÔ±ã¸üºÃµØÓ¦¶ÔÍøÒ³Éè¼ÆÖжÔÑÕÉ«µÄÐèÇó¡£
Ò»¡¢Éè¼Æ˼Ð÷
ÔÚÉè¼ÆÑÕÉ«ÌìÉúÆ÷֮ǰ£¬ÎÒÃÇÐèҪȷ¶¨Ò»Ð©ÐèÇóºÍÉè¼Æ˼Ð÷¡£
1.¹¦Ð§ÐèÇó
ÑÕÉ«ÌìÉúÆ÷ÐèÒªÖ§³ÖÒÔϹ¦Ð§£º
£¨1£©ÌìÉúËæ»úÑÕÉ«
£¨2£©ÌìÉú¸ß±ÈÕնȵÄÑÕÉ«
£¨3£©ÌìÉú½¥±äÑÕÉ«
£¨4£©ÌìÉú¾ßÓл¥²¹É«Ð§¹ûµÄÑÕÉ«
2.ʵÏÖ˼Ð÷
ÎÒÃÇÑ¡ÓÃSwoole¿ò¼Ü×÷ΪʵÏÖ¹¤¾ß£¬ÐèҪ˼Á¿ÒÔϵÄʵÏÖ˼Ð÷£º
£¨1£©Ê¹ÓÃSwooleÌṩµÄг̹¦Ð§ÊµÏÖ¶àгÌÒì²½±à³Ì£¬ÒÔ±ã¸ü¿ìËÙµØÏìÓ¦Óû§ÇëÇó¡£
£¨2£©½¨ÉèÑÕÉ«ÌìÉúÆ÷µÄÊý¾Ý¿â£¬´æ´¢ÖÖÖÖÑÕÉ«µÄÐÅÏ¢¡£
£¨3£©ÊµÏÖËæ»úÊýÌìÉúÆ÷¼°ÖÖÖÖÑÕÉ«Ëã·¨¡£
£¨4£©ÔöÌíºǫ́½çÃ棬±ãÓÚÖÎÀíÔ±¶ÔÑÕÉ«¿â¾ÙÐÐÖÎÀí¼°Ìí¼Ó¡£
¶þ¡¢ÊµÏÖ°ì·¨
1.½¨ÉèÊý¾Ý¿â
ÎÒÃÇƾ֤¹¦Ð§ÐèÇó£¬ÔÚÊý¾Ý¿âÖн¨ÉèÒÔÏÂÈý¸ö±í¸ñ£º
£¨1£©config£º´æ·ÅÑÕÉ«ÌìÉúÆ÷µÄÉèÖü°ÉèÖÃÐÅÏ¢¡£
£¨2£©colors£º´æ·ÅËùÓÐÑÕÉ«µÄÐÅÏ¢¡£
£¨3£©logs: ´æ´¢ÑÕÉ«ÌìÉúÆ÷µÄÈÕÖ¾ÐÅÏ¢¡£
ÆäÖУ¬ÑÕÉ«µÄÐÅÏ¢ÈçÏÂͼËùʾ£º
{ id: 1, // ÑÕÉ«µÄid hex: "#F06D06", // ÑÕÉ«µÄ16½øÖÆÌåÏÖ rgb: "240,109,6"£¬//ÑÕÉ«µÄRGBÌåÏÖ hsv: "20,97,94"£¬// ÑÕÉ«µÄHSVÌåÏÖ hsl: "20,96,47"£¬// ÑÕÉ«µÄHSLÌåÏÖ contrast: "#ffffff"£¬// ÑÕÉ«µÄ¸ß±ÈÕÕ¶ÈÉ«Öµ triadic: ["#06F0B9", "#B906F0"]£¬// ÑÕÉ«µÄÈýºÏһɫֵÊý×é splitComplementary: ["#F006AA", "#06F092"],// ÑÕÉ«µÄÊèÉ¢»¥²¹É«ÖµÊý×é analogous: ["#F00695", "#F06D06", "#F0A406"]// ÑÕÉ«µÄÀà±ÈÉ«ÖµÊý×é }
µÇ¼ºó¸´ÖÆ
2.ʹÓÃSwooleʵÏÖ¶àгÌÒì²½±à³Ì
ÎÒÃÇ¿ÉÒÔͨ¹ýSwooleÌṩµÄгÌÊÖÒÕʵÏָ߲¢·¢µÄÒì²½±à³Ì£¬×èÖ¹¹Å°åµÄ¶àÏ̻߳ò¶àÀú³Ì¿ª·¢·½·¨ÖзºÆðµÄһЩÎÊÌâ¡£ÎÒÃÇÑ¡ÓÃPHPÓïÑÔÀ´ÊµÏÖÕâ¸ö¸ßÐÔÄܵÄÑÕÉ«ÌìÉúÆ÷£¬²¢ÇÒÑ¡ÔñSwoole×÷ΪÒì²½±à³Ì¿ò¼Ü¡£SwooleÊÇÒ»¸ö¸ßÐÔÄÜ¡¢Òì²½µÄÍøÂçͨѶ¿ò¼Ü£¬Äܹ»Ìṩг̵ÄÖ§³Ö£¬²¢ÇÒÓµÓÐÍêÉƵÄAPIÎĵµºÍ¸»ºñµÄʾÀý´úÂë¡£
ÎÒÃÇ¿ÉÒÔ½«Ã¿Ò»¸ö¹¦Ð§·â×°³ÉÒ»¸öг̣¬ÀýÈ磬Ëæ»úÑÕÉ«µÄÌìÉú¡¢¸ß±ÈÕÕ¶ÈÑÕÉ«µÄÌìÉú¡¢½¥±äÑÕÉ«µÄÌìÉúÒÔ¼°»¥²¹É«ÑÕÉ«µÄÌìÉú£¬ÕâЩ¶¼¿ÉÒÔͨ¹ýгÌÀ´ÊµÏÖ¡£
3.±àдËæ»úÊýÌìÉúÆ÷¼°ÑÕÉ«Ëã·¨
£¨1£©Ëæ»úÊýÌìÉúÆ÷
ÓÉÓÚËæ»úÊýµÄÉ趨¹ØÓÚÑÕÉ«µÄÌìÉúºÜÊÇÖ÷Òª£¬Òò´ËÎÒÃÇÐèÒª±àдһ¸ö¸ßÖÊÁ¿µÄËæ»úÊýÌìÉúÆ÷¡£ÔÚÕâÀÎÒÃÇÑ¡ÓûùÓÚʱ¼äµÄËæ»úÊýÖÖ×ÓÀ´Ä£ÄâËæ»úÊýµÄÌìÉú£¬´úÂëÈçÏ£º
function random_generator($min, $max) { $decimals = strlen(strstr($min, ".")); $diff = (float)$max - (float)$min; $rand = (float)$min + mt_rand(0, mt_getrandmax() - 1) / mt_getrandmax() * $diff; return round($rand, $decimals); }
µÇ¼ºó¸´ÖÆ
£¨2£©ÑÕÉ«Ëã·¨
ÔÚÌìÉúÑÕɫʱ£¬ÎÒÃÇÐèÒª½èÖúÖÖÖÖËã·¨À´ÊµÏÖ£¬ÕâÀïÎÒÃǽö¼òÒªÏÈÈÝһϳ£Óõļ¸ÖÖËã·¨¡£
¢Ù¸ß±ÈÕÕ¶ÈÑÕÉ«Ëã·¨
ʵÏÖ´úÂëÈçÏ£º
function get_contrast_color($color) { $rgb = css2rgb($color); $contrast_color = "#"; for ($i = 0; $i < 3; $i++) { $c = hexdec(substr($rgb, 2 * $i, 2)); $contrast_color .= str_pad(dechex(255 - $c), 2, '0', STR_PAD_LEFT); } return $contrast_color; }
µÇ¼ºó¸´ÖÆ
¢Ú½¥±äÉ«Ëã·¨£¨ÏßÐÔ½¥±ä£©
ʵÏÖ´úÂëÈçÏ£º
function get_gradient_colors($start, $end, $steps) { $colors = array(); $start_rgb = css2rgb($start); $end_rgb = css2rgb($end); $step_size = 1.0 / ($steps - 1); for ($i = 0; $i < $steps; $i++) { $p = $i * $step_size; $color = array(); for ($j = 0; $j < 3; $j++) { $color[$j] = (int)round((1 - $p) * $start_rgb[$j] + $p * $end_rgb[$j]); } $colors[] = rgb2css($color); } return $colors; }
µÇ¼ºó¸´ÖÆ
¢Û»¥²¹É«Ëã·¨
ʵÏÖ´úÂëÈçÏ£º
function get_complementary_colors($color) { $rgb = css2rgb($color); $r = 255 - $rgb[0]; $g = 255 - $rgb[1]; $b = 255 - $rgb[2]; return array(rgb2css(array($r, $g, $b))); }
µÇ¼ºó¸´ÖÆ
¢ÜÀà±ÈÉ«Ëã·¨
ʵÏÖ´úÂëÈçÏ£º
function get_analogous_colors($color) { $rgb = css2rgb($color); $hsl = rgb2hsl($rgb); $low = [($hsl[0] - 30) / 360, $hsl[1], $hsl[2]]; $mid = [($hsl[0] - 20) / 360, $hsl[1], $hsl[2]]; $high = [($hsl[0] + 20) / 360, $hsl[1], $hsl[2]]; return array(rgb2css(hsl2rgb($low)), rgb2css(hsl2rgb($mid)), rgb2css(hsl2rgb($high))); }
µÇ¼ºó¸´ÖÆ
4.ÔöÌíºǫ́½çÃæ
ͨ¹ýÔöÌíºǫ́½çÃ棬ÎÒÃÇ¿ÉÒÔÀû±ãµØÖÎÀíÑÕÉ«¿â£¬Ìí¼ÓеÄÑÕÉ«¡£ÕâÀïÎÒÃǽÓÄÉÁËBootstrapÀ´ÊµÏÖºǫ́½çÃæµÄÉè¼Æ¡£
ÔÚÖÎÀí½çÃæÖУ¬ÎÒÃÇ¿ÉÒÔÖ±½Óͨ¹ýËÑË÷¹¦Ð§À´²éÕÒÐèÒªµÄÑÕÉ«£¬²¢ÇÒ¹ØÓÚÑÕÉ«¾ÙÐб༺Íɾ³ý²Ù×÷¡£
Èý¡¢×ܽá
±¾ÎÄÖ÷ÒªÏÈÈÝÁËʹÓÃSwoole¿ò¼ÜÀ´ÊµÏÖ¸ßÐÔÄÜÑÕÉ«ÌìÉúÆ÷µÄÉè¼ÆºÍʵÏÖ¡£Í¨¹ýʹÓÃSwooleÌØÓеÄг̺ÍÒì²½±à³ÌÊÖÒÕ£¬ÎÒÃÇ¿ÉÒÔ¸ü¿ìËÙµØÌìÉúÖÖÖÖÑÕÉ«£¬Ìá¸ßÓû§µÄʹÓÃÌåÑéºÍÍøÒ³µÄÊÓ¾õЧ¹û¡£Í¬Ê±£¬ÎÒÃÇ»¹ÏÈÈÝÁ˼¸¸ö³£ÓõÄÑÕÉ«Ëã·¨£¬²¢ÇÒÔÚËã·¨µÄ»ù´¡ÉÏʵÏÖÁËÑÕÉ«ÌìÉúÆ÷µÄÖÖÖÖ¹¦Ð§¡£
ͨ¹ýÕâ´Îʵ¼ù£¬ÎÒÃÇÉî¿ÌÊìϤµ½ÁËSwoole¿ò¼ÜµÄÇ¿Ê¢¹¦Ð§ºÍÓÅÒìÐÔÄÜ£¬ÐÅÍÐÔÚδÀ´µÄ»¥ÁªÍøÓ¦ÓÃÖУ¬Ëü»áÔ½À´Ô½Êܵ½ÆÕ±éµÄÓ¦ÓúÍÖØÊÓ¡£
ÒÔÉϾÍÊÇSwooleʵÏÖ¸ßÐÔÄܵÄÑÕÉ«ÌìÉúÆ÷µÄÉè¼ÆÓëʵÏÖµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡