zoukankan      html  css  js  c++  java
  • 颜色计算

    //Calculate the color at a given point on a gradient between two color
    double resultRed = color1.red + percent * (color2.red - color1.red);
    double resultGreen = color1.green + percent * (color2.green - color1.green);
    double resultBlue = color1.blue + percent * (color2.blue - color1.blue);
    
    /**
    * Generate gradient color from 2 or 3 colors using JavaScript * You may use this function with both 2 or 3 interval colors for your gradient. * For example, you want to have a gradient between Bootstrap's danger-warning-success colors.
    */ function colorGradient(fadeFraction, rgbColor1, rgbColor2, rgbColor3) { var color1 = rgbColor1; var color2 = rgbColor2; var fade = fadeFraction; // Do we have 3 colors for the gradient? Need to adjust the params. if (rgbColor3) { fade = fade * 2; // Find which interval to use and adjust the fade percentage if (fade >= 1) { fade -= 1; color1 = rgbColor2; color2 = rgbColor3; } } var diffRed = color2.red - color1.red; var diffGreen = color2.green - color1.green; var diffBlue = color2.blue - color1.blue; var gradient = { red: parseInt(Math.floor(color1.red + (diffRed * fade)), 10), green: parseInt(Math.floor(color1.green + (diffGreen * fade)), 10), blue: parseInt(Math.floor(color1.blue + (diffBlue * fade)), 10), }; return 'rgb(' + gradient.red + ',' + gradient.green + ',' + gradient.blue + ')'; } //https://gist.github.com/gskema/2f56dc2e087894ffc756c11e6de1b5ed

      

  • 相关阅读:
    小阳买水果
    单调队列+dp
    最长的合法序列(栈+dp)
    A. 打印收费
    数位dp(K好数)
    Floyd(选地址)
    最短路计数
    线段树维护区间01
    解密(拓展欧几里的)
    树、森林的遍历
  • 原文地址:https://www.cnblogs.com/linr/p/12512961.html
Copyright © 2011-2022 走看看