Real-time webcam feed converted to ASCII character art
CharCam transforms your webcam feed into real-time ASCII art using brightness-based character mapping. The feature creates a Matrix-style representation of your camera input.
The ideal resolution of 320x240 is intentionally low to optimize performance. Higher resolutions would require more processing power for the character conversion.
// Set dimensions to actual display sizeoutputCanvas.width = gridCols * charFontSize;outputCanvas.height = gridRows * charFontSize;// Configure character renderingoutputCtx.fillStyle = "#00FF00";outputCtx.font = `${charFontSize}px monospace`;outputCtx.textAlign = "center";outputCtx.textBaseline = "middle";
The processing canvas is 1 pixel per character, while the output canvas is sized based on font dimensions. This separation optimizes performance by reducing the number of pixels to analyze.
const getCharFontSize = () => { if (typeof window !== "undefined") { if (window.innerWidth < 768) return 10; // Smaller font for mobile } return 14; // Default font size};
Desktop
Mobile
Uses 14px monospace font for optimal character density and readability.
Uses 10px monospace font to fit more characters on smaller screens.
CharCam properly cleans up resources when unmounting:
return () => { if (animationFrameIdRef.current) { cancelAnimationFrame(animationFrameIdRef.current); } if (videoRef.current && videoRef.current.srcObject) { const stream = videoRef.current.srcObject as MediaStream; stream.getTracks().forEach((track) => track.stop()); }};
Failing to stop media tracks can cause the camera indicator to remain active even after leaving the page. This cleanup ensures proper resource management.