本文整理汇总了TypeScript中csx.ColorHelper.lightness方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ColorHelper.lightness方法的具体用法?TypeScript ColorHelper.lightness怎么用?TypeScript ColorHelper.lightness使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类csx.ColorHelper
的用法示例。
在下文中一共展示了ColorHelper.lightness方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
export const emphasizeLightness = (color: ColorHelper, weight: number, flipIfMax: boolean = true) => {
const colorLightness = color.lightness();
let weightOffset = 1;
if (colorLightness < 0.4) {
weightOffset = Math.abs(colorLightness - 0.5) * 20;
}
const weightCurved = weight * weightOffset;
const colorDarker = color.darken(weightCurved) as ColorHelper;
const colorLighter = color.lighten(weightCurved) as ColorHelper;
if (isLightColor(color)) {
if (colorLightness + weightCurved > 1 && flipIfMax) {
return colorDarker;
} else {
return colorLighter;
}
} else {
if (colorLightness - weightCurved > 0 && flipIfMax) {
return colorDarker;
} else {
return colorLighter;
}
}
};
示例2: Error
export const modifyColorSaturationBasedOnLightness = (color: ColorHelper, weight: number, flip: boolean = false) => {
if (weight > 1 || weight < 0) {
throw new Error("mixAmount must be a value between 0 and 1 inclusively.");
}
const isSaturated = color.lightness() >= 0.5;
if ((isSaturated && !flip) || (!isSaturated && flip)) {
// Desaturate
return color.desaturate(weight) as ColorHelper;
} else {
// Saturate
return color.saturate(weight) as ColorHelper;
}
};