hacker-background
eldoraui/hacker-backgroundFreeComponent
A hacker background component.
Live preview
live · rendered by the registry
Rendered by eldoraui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://eldoraui.site/r/hacker-background.jsonSource
1"use client"23import React, { useEffect, useRef } from "react"45interface HackerBackgroundProps {6 color?: string7 fontSize?: number8 className?: string9 speed?: number10}1112export const HackerBackground: React.FC<HackerBackgroundProps> = ({13 color = "#0F0",14 fontSize = 14,15 className = "",16 speed = 1,17}) => {18 const canvasRef = useRef<HTMLCanvasElement>(null)1920 useEffect(() => {21 const canvas = canvasRef.current22 if (!canvas) return2324 const ctx = canvas.getContext("2d")25 if (!ctx) return2627 const resizeCanvas = () => {28 canvas.width = window.innerWidth29 canvas.height = window.innerHeight30 }3132 resizeCanvas()33 window.addEventListener("resize", resizeCanvas)3435 let animationFrameId: number3637 const columns = Math.floor(canvas.width / fontSize)38 const drops: number[] = new Array(columns).fill(1)3940 const chars =41 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@#$%^&*()_+"4243 let lastTime = 044 const interval = 33 // ~30 fps4546 const draw = (currentTime: number) => {47 animationFrameId = requestAnimationFrame(draw)4849 if (currentTime - lastTime < interval) return50 lastTime = currentTime5152 ctx.fillStyle = "rgba(0, 0, 0, 0.05)"53 ctx.fillRect(0, 0, canvas.width, canvas.height)5455 ctx.fillStyle = color56 ctx.font = `${fontSize}px monospace`5758 for (let i = 0; i < drops.length; i++) {59 const text = chars[Math.floor(Math.random() * chars.length)]60 ctx.fillText(text, i * fontSize, drops[i] * fontSize)6162 if (drops[i] * fontSize > canvas.height && Math.random() > 0.975) {63 drops[i] = 064 }65 drops[i] += speed // Use the speed prop to control fall rate66 }67 }6869 animationFrameId = requestAnimationFrame(draw)7071 return () => {72 window.removeEventListener("resize", resizeCanvas)73 cancelAnimationFrame(animationFrameId)74 }75 }, [color, fontSize, speed])7677 return (78 <canvas79 ref={canvasRef}80 className={`pointer-events-none ${className}`}81 style={{82 position: "absolute",83 top: 0,84 left: 0,85 width: "100%",86 height: "100%",87 }}88 />89 )90}
What it pulls in
npm packages
Files it writes
More from eldoraui
All 115 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| animated-badgeanimated-badge | eldoraui | Components | Free | 2 deps | |
| animated-frameworksanimated-frameworks | eldoraui | Components | Free | 2 deps | |
| animated-grid-patternanimated-grid-pattern | eldoraui | Components | Free | 3 deps | |
| animated-listanimated-list | eldoraui | Components | Free | 1 dep | |
| animated-shiny-buttonanimated-shiny-button | eldoraui | Components | Free | 1 dep | |
| blur-in-textblur-in-text | eldoraui | Components | Free | 3 deps | |
| browserbrowser | eldoraui | Components | Free | 2 deps | |
| card-flip-hovercard-flip-hover | eldoraui | Components | Free | 1 dep |
