Skip to content

Commit 33668eb

Browse files
authored
Merge pull request #2 from Meetesh-Saini/main
added color change feature
2 parents c4256b2 + 020a45f commit 33668eb

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/matrixRainingLetters.jsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { useEffect } from "react";
1212

1313
import "./styles.css";
1414

15-
const renderMatrix = (ref) => {
15+
const renderMatrix = (ref, color) => {
1616
let canvas = ref.current;
1717
let context = canvas.getContext("2d");
1818

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

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

4444
for (let i = 0; i < rainDrops.length; i++) {
@@ -57,17 +57,18 @@ const renderMatrix = (ref) => {
5757
rainDrops[i]++;
5858
}
5959
};
60-
61-
return () => {
62-
setInterval(render, 30);
63-
};
60+
return render;
6461
};
6562

6663
const MatrixRainingLetters = (props) => {
6764
const ref = useRef();
6865
const keyName = "mrl-" + props.key;
6966
const thisClassName = "mrl-container " + props.custom_class;
70-
useEffect(() => renderMatrix(ref));
67+
useEffect(() => {
68+
const render = renderMatrix(ref, props.color);
69+
const intervalId = setInterval(render, 30);
70+
return () => clearInterval(intervalId);
71+
}, [props.color]);
7172

7273
return (
7374
<React.Fragment>

0 commit comments

Comments
 (0)