matrix-rain
componentry/matrix-rainFreeComponent
componentry publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by componentry on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://componentry.dev/r/matrix-rain.jsonSource
1"use client"23import { cn } from "@/lib/utils"4import { useEffect, useRef } from "react"56interface MatrixRainProps {7 className?: string8 variant?: "default" | "cyan" | "rainbow"9 width?: number10 height?: number11 fontSize?: number12 speed?: number13 fixedColor?: string14}1516export function MatrixRain({17 className,18 variant = "default",19 width,20 height,21 fontSize = 16,22 speed = 50,23 fixedColor,24}: MatrixRainProps) {25 const canvasRef = useRef<HTMLCanvasElement>(null)2627 useEffect(() => {28 const canvas = canvasRef.current29 if (!canvas) return3031 const ctx = canvas.getContext("2d")32 if (!ctx) return3334 // If specific dimensions are provided, use them. Otherwise observe parent.35 const resizeObserver = new ResizeObserver(() => {36 if (!width && !height) {37 canvas.width = canvas.offsetWidth38 canvas.height = canvas.offsetHeight39 }40 })41 resizeObserver.observe(canvas)4243 // Initial size setup44 if (width) canvas.width = width45 if (height) canvas.height = height46 if (!width && !height) {47 canvas.width = canvas.offsetWidth48 canvas.height = canvas.offsetHeight49 }5051 const w = canvas.width52 const h = canvas.height5354 // Columns config55 const columns = Math.floor(w / fontSize)56 const drops = new Array(columns).fill(1)5758 // Character set: Katakana + Numbers59 const chars = "ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン1234567890"6061 let isDark = document.documentElement.classList.contains("dark")6263 // Set default background based on theme immediately to avoid delay64 const bg = isDark ? "#000000" : "#ffffff"6566 ctx.fillStyle = bg67 ctx.fillRect(0, 0, w, h)6869 const draw = () => {70 // Check theme state on every frame71 const currentIsDark = document.documentElement.classList.contains("dark")7273 // If theme changed, reset the background immediately74 if (currentIsDark !== isDark) {75 isDark = currentIsDark76 ctx.fillStyle = isDark ? "#000000" : "#ffffff"77 ctx.fillRect(0, 0, canvas.width, canvas.height)78 }7980 // Semi-transparent color for trail effect81// … truncated
More from componentry
All 59 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Gradientanimated-gradient | componentry | Components | Free | no deps | |
| ASCII Effectascii-effect | componentry | Components | Free | no deps | |
| Aurora Flowaurora-flow | componentry | Components | Free | no deps | |
| auth-modalauth-modal | componentry | Components | Free | no deps | |
| border-beamborder-beam | componentry | Components | Free | no deps | |
| circuit-boardcircuit-board | componentry | Components | Free | no deps | |
| closing-plasmaclosing-plasma | componentry | Components | Free | no deps | |
| collection-surfercollection-surfer | componentry | Components | Free | no deps |
