Skip to content

Commit

Permalink
add option text shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
syxanash committed Dec 2, 2024
1 parent 92fe4d5 commit 6cef8d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ Bluesky firehose visualized in a Matrix-style rain
<kbd>P</kbd> change rain color to pink<br>

<kbd>E</kbd> toggle show/hide emojis<br>
<kbd>F</kbd> change rain font
<kbd>F</kbd> change rain font<br>
<kbd>S</kbd> toggle text shadow (⚠ might slow down your browser!)
16 changes: 14 additions & 2 deletions assets/js/bluerain.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const keyToSpeed = {
const rainFonts = ["monospace", "Chicago Plain", "Matrix Code NFI", "Courier New"];
let rainFontNumber = 0;
let showEmojis = true;
let showTextShadow = false;

const canvas = document.querySelector("canvas"),
ctx = canvas.getContext("2d");
Expand All @@ -48,8 +49,16 @@ const sanitizeForEmojis = (string) => [...new Intl.Segmenter().segment(string)].
const stripEmojis = (str) => str.replace(/\p{Emoji}/gu, '');

const writeCharacter = (color, character, x, y) => {
ctx.fillStyle = color;
ctx.fillText(character, x, y);
if (showTextShadow) {
ctx.shadowBlur = 15;
ctx.shadowColor = color;
ctx.fillStyle = color;
ctx.fillText(character, x, y);
ctx.shadowBlur = 0;
} else {
ctx.fillStyle = color;
ctx.fillText(character, x, y);
}
};

function loop() {
Expand Down Expand Up @@ -140,6 +149,8 @@ addEventListener("keydown", (event) => {

if (event.code === "KeyE") showEmojis = !showEmojis;

if (event.code === "KeyS") showTextShadow = !showTextShadow;

if (event.code === "KeyF") {
rainFontNumber = (rainFontNumber + 1) % rainFonts.length;
ctx.font = `${fontSize}px ${rainFonts[rainFontNumber]}`;
Expand All @@ -157,6 +168,7 @@ SPACE - pause/play animation
G, R, B, Y, P - change rain color (green, red, blue, yellow, pink)
E - toggle show/hide emojis
F - change rain font
S - toggle text shadow (might slow down your browser!)
`;

console.log(helpText, "font-size: small");
Expand Down

0 comments on commit 6cef8d2

Please sign in to comment.