首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Stylus色光的调节亮度

Stylus色光的调节亮度
EN

Stack Overflow用户
提问于 2016-08-02 21:08:12
回答 1查看 200关注 0票数 0

我正在与Stylus合作,CSS的预处理器,我想要一个功能来调整颜色的“感知亮度”,比如说,20%或-10%。

我发现了“亮度”这个术语,看起来Stylus有一个函数可以让得到颜色的亮度,但是不能调节颜色的亮度。

如何创建这样的函数呢?

EN

回答 1

Stack Overflow用户

发布于 2016-08-02 22:30:23

经过一番修修补补后,这个似乎行得通。但我不确定它是否100%正确。

代码语言:javascript
复制
adjust-luminance($color, $amount = 10%)
    $scale = unit($amount, '') / 100 * 255

    //green is the lightest component, followed by red, then blue.
    $redWeight = 0.2126
    $greenWeight = 0.7152
    $blueWeight = 0.0722

    // get the individual components of the color
    $red = red($color)
    $green = green($color)
    $blue = blue($color)

    //get percent
    $percentRed = $red / 255
    $percentGreen = $green / 255
    $percentBlue = $blue / 255

    $lumRed = $percentRed * $redWeight
    $lumGreen = $percentGreen * $greenWeight
    $lumBlue = $percentBlue * $blueWeight

    $lumTotal = 1 + ($lumRed + $lumGreen + $lumBlue)

    $red += $scale * (1 - $redWeight) * $lumTotal
    $green += $scale * (1 - $greenWeight) * $lumTotal
    $blue += $scale * (1 - $blueWeight) * $lumTotal

    $adjusted = rgb($red, $green, $blue)
    $adjusted = saturation($adjusted, saturation($color))
    return $adjusted
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38730484

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档