Skip to content

Commit 32ea3ba

Browse files
author
meowabyte
committed
better colors
1 parent f4a412c commit 32ea3ba

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/components/bg/matrix.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { birthdayMode, cn, sleep } from "../../helpers/utils";
55
const UPDATE_DELAY = 500 as const
66
const UPDATE_FADE_OPACITY = 0.2 as const
77
const UPDATE_CHARACTERS = ["@", "#", "/", "\\", "&", "%"] as const
8-
const UPDATE_BDAYMODE_COLORS = ["white", "red", "blue", "yellow", "green", "purple", "orange", "pink"]
98

109

1110
const FONT_NAME = "Roboto Mono" as const
@@ -23,6 +22,12 @@ const FONT_JUMP_SIZE = FONT_PX.actualBoundingBoxAscent + 10
2322
const UPDATE_FADE_SIZE = FONT_JUMP_SIZE * (Math.ceil(1 / UPDATE_FADE_OPACITY) * 4)
2423

2524

25+
const randomColor = () => {
26+
const hue = Math.floor(Math.random() * 360);
27+
const lightness = Math.floor(Math.random() * 21) + 40;
28+
return `hsl(${hue}, 100%, ${lightness}%)`;
29+
}
30+
2631
type BMAddToMatrixOptions = {
2732
/** Position of the element. Random by default */
2833
x?: number,
@@ -78,7 +83,7 @@ class BackgroundManager {
7883
const x = o?.x ?? Math.floor(Math.random() * this.target.width)
7984
return x - x % FONT_PX.width
8085
})()
81-
const fillStyle = o?.style ?? birthdayMode ? UPDATE_BDAYMODE_COLORS[Math.floor(Math.random() * UPDATE_BDAYMODE_COLORS.length)] : "white"
86+
const fillStyle = birthdayMode ? randomColor() : (o?.style ?? "white")
8287

8388
for (let y = 0; y < this.target.height + UPDATE_FADE_SIZE; y += FONT_JUMP_SIZE) {
8489
if (x > this.target.width) break; // Resized - disable if outside of area

0 commit comments

Comments
 (0)