Radial Pattern Background: Beter colors
This commit is contained in:
parent
3fd03fbe61
commit
930b36fa78
@ -38,7 +38,6 @@ const GiftTransferPreview = ({
|
|||||||
<RadialPatternBackground
|
<RadialPatternBackground
|
||||||
className={styles.backdrop}
|
className={styles.backdrop}
|
||||||
backgroundColors={[giftAttributes.backdrop!.centerColor, giftAttributes.backdrop!.edgeColor]}
|
backgroundColors={[giftAttributes.backdrop!.centerColor, giftAttributes.backdrop!.edgeColor]}
|
||||||
patternColor={giftAttributes.backdrop?.patternColor}
|
|
||||||
patternIcon={giftAttributes.pattern?.sticker}
|
patternIcon={giftAttributes.pattern?.sticker}
|
||||||
/>
|
/>
|
||||||
<AnimatedIconFromSticker
|
<AnimatedIconFromSticker
|
||||||
|
|||||||
@ -132,13 +132,11 @@ const SavedGift = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const backdropColors = [backdrop.centerColor, backdrop.edgeColor];
|
const backdropColors = [backdrop.centerColor, backdrop.edgeColor];
|
||||||
const patternColor = backdrop.patternColor;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RadialPatternBackground
|
<RadialPatternBackground
|
||||||
className={styles.radialPattern}
|
className={styles.radialPattern}
|
||||||
backgroundColors={backdropColors}
|
backgroundColors={backdropColors}
|
||||||
patternColor={patternColor}
|
|
||||||
patternIcon={pattern.sticker}
|
patternIcon={pattern.sticker}
|
||||||
patternSize={14}
|
patternSize={14}
|
||||||
ringsCount={1}
|
ringsCount={1}
|
||||||
|
|||||||
@ -492,7 +492,6 @@ const ProfileInfo = ({
|
|||||||
<RadialPatternBackground
|
<RadialPatternBackground
|
||||||
backgroundColors={profileColorSet.bgColors}
|
backgroundColors={profileColorSet.bgColors}
|
||||||
patternIcon={backgroundEmoji}
|
patternIcon={backgroundEmoji}
|
||||||
patternColor={collectibleEmojiStatus?.patternColor}
|
|
||||||
patternSize={16}
|
patternSize={16}
|
||||||
withLinearGradient={!collectibleEmojiStatus}
|
withLinearGradient={!collectibleEmojiStatus}
|
||||||
className={styles.radialPatternBackground}
|
className={styles.radialPatternBackground}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import { requestMutation } from '../../../lib/fasterdom/fasterdom';
|
|||||||
import { getStickerMediaHash } from '../../../global/helpers';
|
import { getStickerMediaHash } from '../../../global/helpers';
|
||||||
import buildClassName from '../../../util/buildClassName';
|
import buildClassName from '../../../util/buildClassName';
|
||||||
import buildStyle from '../../../util/buildStyle';
|
import buildStyle from '../../../util/buildStyle';
|
||||||
import { hex2rgba, rgba2hex } from '../../../util/colors.ts';
|
import { adjustHsv, getColorLuma, hex2rgb } from '../../../util/colors.ts';
|
||||||
import { preloadImage } from '../../../util/files';
|
import { preloadImage } from '../../../util/files';
|
||||||
import { REM } from '../helpers/mediaDimensions';
|
import { REM } from '../helpers/mediaDimensions';
|
||||||
|
|
||||||
@ -20,8 +20,9 @@ import styles from './RadialPatternBackground.module.scss';
|
|||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
backgroundColors: string[];
|
backgroundColors: string[];
|
||||||
patternIcon?: ApiSticker;
|
patternIcon?: ApiSticker;
|
||||||
patternColor?: string;
|
patternColor?: number;
|
||||||
patternSize?: number;
|
patternSize?: number;
|
||||||
|
centerEmptiness?: number;
|
||||||
ringsCount?: number;
|
ringsCount?: number;
|
||||||
ovalFactor?: number;
|
ovalFactor?: number;
|
||||||
withLinearGradient?: boolean;
|
withLinearGradient?: boolean;
|
||||||
@ -32,9 +33,10 @@ type OwnProps = {
|
|||||||
|
|
||||||
const BASE_RING_ITEM_COUNT = 8;
|
const BASE_RING_ITEM_COUNT = 8;
|
||||||
const RING_INCREMENT = 0.5;
|
const RING_INCREMENT = 0.5;
|
||||||
const CENTER_EMPTINESS = 0.1;
|
const DEFAULT_CENTER_EMPTINESS = 0.1;
|
||||||
const MAX_RADIUS = 0.42;
|
const MAX_RADIUS = 0.42;
|
||||||
const MIN_SIZE = 4 * REM;
|
const MIN_SIZE = 4 * REM;
|
||||||
|
const DARK_LUMA_THRESHOLD = 255 * 0.2;
|
||||||
|
|
||||||
const DEFAULT_PATTERN_SIZE = 20;
|
const DEFAULT_PATTERN_SIZE = 20;
|
||||||
const DEFAULT_RINGS_COUNT = 3;
|
const DEFAULT_RINGS_COUNT = 3;
|
||||||
@ -43,8 +45,8 @@ const DEFAULT_OVAL_FACTOR = 1.4;
|
|||||||
const RadialPatternBackground = ({
|
const RadialPatternBackground = ({
|
||||||
backgroundColors,
|
backgroundColors,
|
||||||
patternIcon,
|
patternIcon,
|
||||||
patternColor,
|
|
||||||
patternSize = DEFAULT_PATTERN_SIZE,
|
patternSize = DEFAULT_PATTERN_SIZE,
|
||||||
|
centerEmptiness = DEFAULT_CENTER_EMPTINESS,
|
||||||
ringsCount = DEFAULT_RINGS_COUNT,
|
ringsCount = DEFAULT_RINGS_COUNT,
|
||||||
ovalFactor = DEFAULT_OVAL_FACTOR,
|
ovalFactor = DEFAULT_OVAL_FACTOR,
|
||||||
withLinearGradient,
|
withLinearGradient,
|
||||||
@ -74,7 +76,7 @@ const RadialPatternBackground = ({
|
|||||||
for (let ring = 1; ring <= ringsCount; ring++) {
|
for (let ring = 1; ring <= ringsCount; ring++) {
|
||||||
const ringItemCount = Math.floor(BASE_RING_ITEM_COUNT * (1 + (ring - 1) * RING_INCREMENT));
|
const ringItemCount = Math.floor(BASE_RING_ITEM_COUNT * (1 + (ring - 1) * RING_INCREMENT));
|
||||||
const ringProgress = ring / ringsCount;
|
const ringProgress = ring / ringsCount;
|
||||||
const ringRadius = CENTER_EMPTINESS + (MAX_RADIUS - CENTER_EMPTINESS) * ringProgress;
|
const ringRadius = centerEmptiness + (MAX_RADIUS - centerEmptiness) * ringProgress;
|
||||||
const angleShift = ring % 2 === 0 ? Math.PI / ringItemCount : 0;
|
const angleShift = ring % 2 === 0 ? Math.PI / ringItemCount : 0;
|
||||||
|
|
||||||
for (let i = 0; i < ringItemCount; i++) {
|
for (let i = 0; i < ringItemCount; i++) {
|
||||||
@ -96,7 +98,7 @@ const RadialPatternBackground = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return coordinates;
|
return coordinates;
|
||||||
}, [clearBottomSector, ovalFactor, ringsCount]);
|
}, [centerEmptiness, clearBottomSector, ovalFactor, ringsCount]);
|
||||||
|
|
||||||
useResizeObserver(containerRef, (entry) => {
|
useResizeObserver(containerRef, (entry) => {
|
||||||
setContainerSize({
|
setContainerSize({
|
||||||
@ -138,13 +140,15 @@ const RadialPatternBackground = ({
|
|||||||
ctx.drawImage(emojiImage, renderX - size / 2, renderY - size / 2, size, size);
|
ctx.drawImage(emojiImage, renderX - size / 2, renderY - size / 2, size, size);
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx.fillStyle = adjustBrightness(backgroundColors[1] ?? backgroundColors[0], -0.075);
|
const patternColor = backgroundColors[1] ?? backgroundColors[0];
|
||||||
|
const isDark = getColorLuma(hex2rgb(patternColor)) < DARK_LUMA_THRESHOLD;
|
||||||
|
ctx.fillStyle = adjustHsv(patternColor, 0.5, isDark ? 0.28 : -0.28);
|
||||||
ctx.globalCompositeOperation = 'source-in';
|
ctx.globalCompositeOperation = 'source-in';
|
||||||
ctx.fillRect(0, 0, width, height);
|
ctx.fillRect(0, 0, width, height);
|
||||||
|
|
||||||
const radialGradient = ctx.createRadialGradient(centerX, centerY, 0, centerX, centerY, width / 2);
|
const radialGradient = ctx.createRadialGradient(centerX, centerY, 0, centerX, centerY, width / 2);
|
||||||
radialGradient.addColorStop(0.75, 'rgb(255 255 255 / 0)');
|
radialGradient.addColorStop(0, 'rgb(255 255 255 / 0.4)');
|
||||||
radialGradient.addColorStop(1, 'rgb(255 255 255 / 0.75)');
|
radialGradient.addColorStop(1, 'rgb(255 255 255 / 0.9)');
|
||||||
|
|
||||||
// Scale around the gradient center
|
// Scale around the gradient center
|
||||||
ctx.translate(centerX, centerY);
|
ctx.translate(centerX, centerY);
|
||||||
@ -161,7 +165,7 @@ const RadialPatternBackground = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
draw();
|
draw();
|
||||||
}, [emojiImage, patternColor, patternPositions, yPosition, ovalFactor]);
|
}, [emojiImage, patternPositions, yPosition, ovalFactor]);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
const { width, height } = getContainerSize();
|
const { width, height } = getContainerSize();
|
||||||
@ -198,15 +202,3 @@ const RadialPatternBackground = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default memo(RadialPatternBackground);
|
export default memo(RadialPatternBackground);
|
||||||
|
|
||||||
function adjustBrightness(hex: string, delta: number) {
|
|
||||||
const factor = 1 + delta;
|
|
||||||
const [r, g, b, a] = hex2rgba(hex);
|
|
||||||
|
|
||||||
return rgba2hex([
|
|
||||||
Math.min(255, Math.round(r * factor)),
|
|
||||||
Math.min(255, Math.round(g * factor)),
|
|
||||||
Math.min(255, Math.round(b * factor)),
|
|
||||||
a ?? 255,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|||||||
@ -49,8 +49,10 @@ const WebPageUniqueGift = ({
|
|||||||
<RadialPatternBackground
|
<RadialPatternBackground
|
||||||
className={styles.background}
|
className={styles.background}
|
||||||
backgroundColors={backgroundColors}
|
backgroundColors={backgroundColors}
|
||||||
patternColor={backdrop!.patternColor}
|
|
||||||
patternIcon={pattern!.sticker}
|
patternIcon={pattern!.sticker}
|
||||||
|
centerEmptiness={0.15}
|
||||||
|
ringsCount={2}
|
||||||
|
ovalFactor={1.2}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div ref={stickerRef} className={styles.stickerWrapper}>
|
<div ref={stickerRef} className={styles.stickerWrapper}>
|
||||||
|
|||||||
@ -97,7 +97,6 @@ const StarGiftAction = ({
|
|||||||
<RadialPatternBackground
|
<RadialPatternBackground
|
||||||
className={styles.uniqueBackground}
|
className={styles.uniqueBackground}
|
||||||
backgroundColors={backgroundColors}
|
backgroundColors={backgroundColors}
|
||||||
patternColor={backdrop.patternColor}
|
|
||||||
patternIcon={pattern.sticker}
|
patternIcon={pattern.sticker}
|
||||||
patternSize={14}
|
patternSize={14}
|
||||||
yPosition={9.5 * REM}
|
yPosition={9.5 * REM}
|
||||||
|
|||||||
@ -126,13 +126,11 @@ function GiftItemStar({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const backdropColors = [backdrop.centerColor, backdrop.edgeColor];
|
const backdropColors = [backdrop.centerColor, backdrop.edgeColor];
|
||||||
const patternColor = backdrop.patternColor;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RadialPatternBackground
|
<RadialPatternBackground
|
||||||
className={styles.radialPattern}
|
className={styles.radialPattern}
|
||||||
backgroundColors={backdropColors}
|
backgroundColors={backdropColors}
|
||||||
patternColor={patternColor}
|
|
||||||
patternIcon={pattern.sticker}
|
patternIcon={pattern.sticker}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -512,7 +512,6 @@ const GiftResaleFilters: FC<StateProps & OwnProps> = ({
|
|||||||
<RadialPatternBackground
|
<RadialPatternBackground
|
||||||
className={styles.backdrop}
|
className={styles.backdrop}
|
||||||
backgroundColors={[backdrop.centerColor, backdrop.edgeColor]}
|
backgroundColors={[backdrop.centerColor, backdrop.edgeColor]}
|
||||||
patternColor={backdrop.patternColor}
|
|
||||||
/>
|
/>
|
||||||
<div className={styles.backdropAttributeMenuItemText}>
|
<div className={styles.backdropAttributeMenuItemText}>
|
||||||
{backdrop.name}
|
{backdrop.name}
|
||||||
|
|||||||
@ -66,13 +66,11 @@ const UniqueGiftHeader = ({
|
|||||||
|
|
||||||
const radialPatternBackdrop = useMemo(() => {
|
const radialPatternBackdrop = useMemo(() => {
|
||||||
const backdropColors = [backdropAttribute.centerColor, backdropAttribute.edgeColor];
|
const backdropColors = [backdropAttribute.centerColor, backdropAttribute.edgeColor];
|
||||||
const patternColor = backdropAttribute.patternColor;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RadialPatternBackground
|
<RadialPatternBackground
|
||||||
className={styles.radialPattern}
|
className={styles.radialPattern}
|
||||||
backgroundColors={backdropColors}
|
backgroundColors={backdropColors}
|
||||||
patternColor={patternColor}
|
|
||||||
patternIcon={patternAttribute.sticker}
|
patternIcon={patternAttribute.sticker}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -67,13 +67,11 @@ const GiftStatusInfoModal = ({
|
|||||||
if (!emojiStatus || !isOpen) return undefined;
|
if (!emojiStatus || !isOpen) return undefined;
|
||||||
|
|
||||||
const backdropColors = [emojiStatus.centerColor, emojiStatus.edgeColor];
|
const backdropColors = [emojiStatus.centerColor, emojiStatus.edgeColor];
|
||||||
const patternColor = emojiStatus.patternColor;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RadialPatternBackground
|
<RadialPatternBackground
|
||||||
className={styles.radialPattern}
|
className={styles.radialPattern}
|
||||||
backgroundColors={backdropColors}
|
backgroundColors={backdropColors}
|
||||||
patternColor={patternColor}
|
|
||||||
patternIcon={patternIcon.customEmoji}
|
patternIcon={patternIcon.customEmoji}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -98,7 +98,6 @@ const GiftWithdrawModal = ({ modal, hasPassword, passwordHint }: OwnProps & Stat
|
|||||||
<RadialPatternBackground
|
<RadialPatternBackground
|
||||||
className={styles.backdrop}
|
className={styles.backdrop}
|
||||||
backgroundColors={[giftAttributes.backdrop!.centerColor, giftAttributes.backdrop!.edgeColor]}
|
backgroundColors={[giftAttributes.backdrop!.centerColor, giftAttributes.backdrop!.edgeColor]}
|
||||||
patternColor={giftAttributes.backdrop?.patternColor}
|
|
||||||
patternIcon={giftAttributes.pattern?.sticker}
|
patternIcon={giftAttributes.pattern?.sticker}
|
||||||
/>
|
/>
|
||||||
<AnimatedIconFromSticker
|
<AnimatedIconFromSticker
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { preloadImage } from './files';
|
import { preloadImage } from './files';
|
||||||
import { lerp } from './math.ts';
|
import { clamp, lerp } from './math.ts';
|
||||||
|
|
||||||
const LUMA_THRESHOLD = 128;
|
const LUMA_THRESHOLD = 128;
|
||||||
|
|
||||||
@ -272,3 +272,14 @@ export function lerpRgbaObj(start: Rgba, end: Rgba, interpolationRatio: number):
|
|||||||
|
|
||||||
return { r, g, b, a };
|
return { r, g, b, a };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function adjustHsv(hex: string, satDelta: number, valDelta: number) {
|
||||||
|
const hsva = rgba2hsva(hex2rgba(hex));
|
||||||
|
const [h, , , a] = hsva;
|
||||||
|
let [, s, v] = hsva;
|
||||||
|
|
||||||
|
if (s > 0.1 && s < 0.9) s = clamp(s + satDelta, 0, 1);
|
||||||
|
v = clamp(v + valDelta, 0, 1);
|
||||||
|
|
||||||
|
return rgba2hex(hsva2rgba([h, s, v, a]));
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user