Overview
Matrix Rain & CharCam is a modern web application built with Next.js 15, featuring two interactive Canvas-based visual experiences: a customizable Matrix digital rain effect and a real-time ASCII art webcam renderer.Tech stack
Core framework
- Next.js 15.3.2 - React framework with App Router
- React 19.0.0 - UI library with hooks and concurrent features
- TypeScript 5 - Type-safe development
Styling
- Tailwind CSS 4 - Utility-first CSS framework
- PostCSS - CSS processing
- Geist Fonts - Optimized fonts (Geist Sans and Geist Mono) from Vercel
Development tools
- ESLint 9 - Code linting with Next.js config
- Turbopack - Fast development bundler (via
next dev --turbopack)
The project uses minimal dependencies, relying primarily on browser-native Canvas API and Web APIs for all visual effects and camera access.
Project structure
The application follows Next.js App Router conventions:Route organization
Each page is a self-contained client component with its own Canvas implementation:/- Matrix digital rain effect/chars- Real-time webcam ASCII art renderer/lorem- Project information and about page
Design decisions
Client-side rendering
Both main features use"use client" directive because they require:
- Browser APIs (Canvas, requestAnimationFrame, MediaDevices)
- React hooks (useRef, useState, useEffect, useCallback)
- Real-time DOM manipulation
- Event listeners (resize, video playback)
State management approach
The application uses a ref-based pattern for performance-critical values:Dual-canvas architecture (CharCam)
CharCam uses two canvases for optimal performance:- Processing canvas (hidden) - Low-resolution frame capture
- Dimensions match grid size (e.g., 100x75 pixels)
- Used for
getImageData()to analyze brightness
- Output canvas (visible) - High-resolution character rendering
- Dimensions:
gridCols * fontSize × gridRows * fontSize - Renders final ASCII art
- Dimensions:
- Fast brightness sampling on small canvas
- High-quality character rendering on large canvas
- Reduced
getImageData()overhead
Responsive canvas sizing
Both implementations handle window resizing dynamically:Character set design
Matrix Rain uses an authentic Matrix-style character set:Color management
Matrix Rain supports three color modes:- Static color - User-selected via color picker
- RGB mode - HSL-based rainbow effect with animation
- Green default - Classic Matrix green (#00FF00)
Performance optimizations
Animation frame management
- Uses
requestAnimationFramefor smooth 60fps rendering - Properly cancels animation frames on unmount
- Skips processing when video is paused or not ready
Canvas context options
CharCam useswillReadFrequently hint for optimized pixel access:
Trail effect technique
Instead of clearing the canvas completely, both effects use semi-transparent fills:Mobile-responsive font sizing
CharCam adjusts character size based on viewport:Styling architecture
Tailwind configuration
The project uses Tailwind CSS 4 with PostCSS for processing. Global styles define theme variables:Layout constraints
The root layout prevents scrolling for immersive full-screen experiences:Component styling patterns
UI controls use responsive Tailwind classes:Browser API usage
Canvas API (page.tsx:60-147)
Core rendering uses 2D context methods:fillRect()- Background clearingfillText()- Character renderinggetImageData()- Pixel brightness analysis (CharCam)
Media Devices API (chars/page.tsx:132-165)
Webcam access with error handling:Window API
window.innerWidth/innerHeight- Viewport dimensionswindow.addEventListener('resize')- Responsive updatesrequestAnimationFrame()- Animation loop timing