gpt4 book ai didi

JAVASCRIPT亮度功能-降低

转载 作者:行者123 更新时间:2023-11-28 02:40:54 27 4
gpt4 key购买 nike

我在堆栈上创建了这段代码:

function increase_brightness(hex, percent){
var r = parseInt(hex.substr(1, 2), 16),
g = parseInt(hex.substr(3, 2), 16),
b = parseInt(hex.substr(5, 2), 16);

return '#' +
((0|(1<<8) + r + (256 - r) * percent / 100).toString(16)).substr(1) +
((0|(1<<8) + g + (256 - g) * percent / 100).toString(16)).substr(1) +
((0|(1<<8) + b + (256 - b) * percent / 100).toString(16)).substr(1);
}

有谁知道如何精确求逆吗?

函数 decreas_brightness(){} 我的意思是

最佳答案

您的代码来自JavaScript Calculate brighter colour 。根据评论,以下更改应该会降低亮度:

function decrease_brightness(hex, percent){
var r = parseInt(hex.substr(1, 2), 16),
g = parseInt(hex.substr(3, 2), 16),
b = parseInt(hex.substr(5, 2), 16);

return '#' +
((0|(1<<8) + r * (100 - percent) / 100).toString(16)).substr(1) +
((0|(1<<8) + g * (100 - percent) / 100).toString(16)).substr(1) +
((0|(1<<8) + b * (100 - percent) / 100).toString(16)).substr(1);
}

关于JAVASCRIPT亮度功能-降低,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12660919/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com