gpt4 book ai didi

javascript - 有人知道如何根据 javascript 中的颜色生成具有新亮度的 4 种颜色吗?

转载 作者:行者123 更新时间:2023-11-30 08:16:50 32 4
gpt4 key购买 nike

嘿,我想知道是否有人知道根据以十六进制输入到 javascript 函数中的单一颜色来生成一些单色的方法。

最佳答案

如果您希望将颜色转换为某种程度的灰度,请尝试计算发光,如下所示:

function toGrayScale(color) /* color is an integer */ {

// Extract the red, green, and blue portions of the color
var red = (color >> 16) & 0xff;
var green = (color >> 8) & 0xff;
var blue = color & 0xff;

// Calculate the luminescence
var luminescence = red * 0.3 + green * 0.59 + blue * 0.11;
var lumInt = Math.floor(luminescence);

// Combine into a grayscale color
return (lumInt << 16) + (lumInt << 8) + lumInt;
}

关于javascript - 有人知道如何根据 javascript 中的颜色生成具有新亮度的 4 种颜色吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2269855/

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