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

      

  • 相关阅读:
    飞跃平野(sdut1124)
    背包
    sdut2193救基友记3(三维)
    hdu1542 Atlantis(矩阵面积的并)
    hdu1505City Game(扫描线)
    poj3468A Simple Problem with Integers(线段树的区域更新)
    hdu1166敌兵布阵&&hdu1754I Hate It(线段树入门)
    Biorhythms(中国剩余定理)
    Sequence(priority_queue)
    Message Flood(map)
  • 原文地址:https://www.cnblogs.com/linr/p/12512961.html
Copyright © 2011-2022 走看看