js,php CSS Color deepening, Dodge, CSS color progressive method

Source: Internet
Author: User

1, JS

varColor =function () {    //Convert hex color value str to RGB array     This. Hextorgb =function(str) {varr =/^\#? [0-9a-f] {6}$/; //The test method checks if there is a pattern in the string and returns True if it exists, otherwise false    if(!r.test (str))returnWindow.alert ("Input incorrect hex color value"); //Replace replaces the lookup to the stringstr = str.replace ("#", "" "); //match gets query array    varHxS = Str.match (/..) /g); Alert (' BF ' +hxs) for(vari = 0; I < 3; i++) Hxs[i] = parseint (Hxs[i], 16); Alert (parseint (80, 16))    returnHxS;}//Convert RGB color values to A,b,c to hex color values This. Rgbtohex =function(A, B, c) {varr =/^\d{1,3}$/; if(!r.test (a) | | |!r.test (b) | |!r.test (c))returnWindow.alert ("Input incorrect RGB color value"); varHexs = [A.tostring (+), b.tostring (+), c.tostring (16)];  for(vari = 0; I < 3; i++)if(Hexs[i].length = = 1) hexs[i] = "0" +Hexs[i]; return"#" + Hexs.join ("" ");}//Gets the hex color value of the darker color value, level is the degree of deepening, limited to 0-1 between This. Getdarkcolor =function(color, level) {varr =/^\#? [0-9a-f] {6}$/; if(!r.test (color))returnWindow.alert ("Input incorrect hex color value"); varRGBC = This.    Hextorgb (color); //Floor down rounding     for(vari = 0; I < 3; i++) Rgbc[i] = Math.floor (rgbc[i] * (1-Level )); return  This. Rgbtohex (Rgbc[0], rgbc[1], rgbc[2]);}//Gets the hex color value of the Dodge color value, level is the degree of Dodge, limit between 0-1 This. Getlightcolor =function(color, level) {varr =/^\#? [0-9a-f] {6}$/; if(!r.test (color))returnWindow.alert ("Input incorrect hex color value"); varRGBC = This.    Hextorgb (color);  for(vari = 0; I < 3; i++) Rgbc[i] = Math.floor ((255-rgbc[i]) * level +Rgbc[i]); return  This. Rgbtohex (Rgbc[0], rgbc[1], rgbc[2]);}//get a Web-safe color with hex color value This. Getwebsafecolor =function(color) {varr =/^\#? [0-9a-f] {6}$/; if(!r.test (color))returnWindow.alert ("Input incorrect hex color value"); varRGBC = This.    Hextorgb (color);  for(vari = 0; I < 3; i++) {        varQ1 = Math.floor (Rgbc[i]/51) * 51; //Ceil rounding up        varQ2 = Math.ceil (Rgbc[i]/51) * 51; //ABS Absolute        if(Math.Abs (Q1-rgbc[i]) <= Math.Abs (Q2-rgbc[i])) rgbc[i] =Q1; ElseRgbc[i] =Q2; }    return  This. Rgbtohex (Rgbc[0], rgbc[1], rgbc[2]); }}//How to useInsetpane ("Drakcolor", Test.getdarkcolor (V, 0.2));

2. php

//hex Color Deepening DodgefunctionChangeColor ($hex,$type= ' No '){    if($hex< 0 | |Hexdec($hex) >Hexdec(' FFFFFF '))    {        $hex=Diy_color; }    $rgb= Hextorgb ($hex); if($type= = ' + '){         for($i= 0;$i< 3;$i++)         {            $re[$i] = Floor(255-$rgb[$i]) * Diy_color_level +$rgb[$i]); }        $re= Rgbtohex ($re); }ElseIf($type= = '-'){         for($i= 0;$i< 3;$i++)         {            $re[$i] = Floor($rgb[$i] * (1-diy_color_level)); }        $re= Rgbtohex ($re); }    Else{        $re=$hex; }    return $re;}//hex color Turn RGBfunctionHextorgb ($hex){    $hex=Str_replace(‘#‘, ‘‘,$hex); $rgb[0] =Hexdec($hex[0].$hex[1]); $rgb[1] =Hexdec($hex[2].$hex[3]); $rgb[2] =Hexdec($hex[4].$hex[5]); return $rgb;}//RGB color Turn hexfunctionRgbtohex ($rgb){    return sprintf('%02x ',$rgb[0]).sprintf('%02x ',$rgb[1]).sprintf('%02x ',$rgb[2]);}

js,php CSS Color deepening, Dodge, CSS color progressive method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.