Skip to content

Commit

Permalink
Merge pull request #2 from Meetesh-Saini/main
Browse files Browse the repository at this point in the history
added color change feature
  • Loading branch information
lpm0073 authored Sep 25, 2023
2 parents c4256b2 + 020a45f commit 33668eb
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/matrixRainingLetters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useEffect } from "react";

import "./styles.css";

const renderMatrix = (ref) => {
const renderMatrix = (ref, color) => {
let canvas = ref.current;
let context = canvas.getContext("2d");

Expand All @@ -38,7 +38,7 @@ const renderMatrix = (ref) => {
context.fillStyle = "rgba(0, 0, 0, 0.05)"; // black w a tiny bit of alpha
context.fillRect(0, 0, canvas.width, canvas.height);

context.fillStyle = "#0F0"; // pure green
context.fillStyle = color ? color : "#0F0";
context.font = fontSize + "px monospace";

for (let i = 0; i < rainDrops.length; i++) {
Expand All @@ -57,17 +57,18 @@ const renderMatrix = (ref) => {
rainDrops[i]++;
}
};

return () => {
setInterval(render, 30);
};
return render;
};

const MatrixRainingLetters = (props) => {
const ref = useRef();
const keyName = "mrl-" + props.key;
const thisClassName = "mrl-container " + props.custom_class;
useEffect(() => renderMatrix(ref));
useEffect(() => {
const render = renderMatrix(ref, props.color);
const intervalId = setInterval(render, 30);
return () => clearInterval(intervalId);
}, [props.color]);

return (
<React.Fragment>
Expand Down

0 comments on commit 33668eb

Please sign in to comment.