MCPcopy Create free account
hub / github.com/botbotrobotics/BotBrain / CameraView

Function CameraView

frontend/src/components/camera-view.tsx:14–123  ·  view source on GitHub ↗
({
  label,
  className,
  width,
  height,
}: CameraViewProps)

Source from the content-addressed store, hash-verified

12}
13
14export default function CameraView({
15 label,
16 className,
17 width,
18 height,
19}: CameraViewProps) {
20 const [isFullscreen, setIsFullscreen] = useState(false);
21 const canvasRef = useRef<HTMLCanvasElement>(null);
22 const requestRef = useRef<number>(0);
23
24 useEffect(() => {
25 const canvas = canvasRef.current;
26 if (!canvas) return;
27
28 const ctx = canvas.getContext('2d');
29 if (!ctx) return;
30
31 const createVideoFrame = () => {
32 ctx.fillStyle = '#000000';
33 ctx.fillRect(0, 0, canvas.width, canvas.height);
34
35 const time = Date.now() / 1000;
36
37 ctx.fillStyle = '#8A2BE2';
38 ctx.beginPath();
39 ctx.arc(
40 canvas.width / 2 + Math.cos(time) * 50,
41 canvas.height / 2 + Math.sin(time) * 50,
42 20,
43 0,
44 Math.PI * 2
45 );
46 ctx.fill();
47
48 ctx.strokeStyle = '#B388FF';
49 ctx.lineWidth = 2;
50 for (let i = 0; i < 3; i++) {
51 const x = Math.sin(time * (i + 1)) * 100 + canvas.width / 2;
52 const y = Math.cos(time * (i + 1)) * 100 + canvas.height / 2;
53 ctx.strokeRect(x - 15, y - 15, 30, 30);
54 }
55
56 ctx.fillStyle = '#ffffff';
57 ctx.font = '12px monospace';
58 ctx.fillText(label, 10, 20);
59 ctx.fillText(new Date().toLocaleTimeString(), 10, canvas.height - 10);
60
61 ctx.fillStyle = '#ff0000';
62 ctx.beginPath();
63 ctx.arc(canvas.width - 20, 20, 5, 0, Math.PI * 2);
64 ctx.fill();
65
66 requestRef.current = requestAnimationFrame(createVideoFrame);
67 };
68
69 createVideoFrame();
70
71 return () => {

Callers

nothing calls this directly

Calls 1

createVideoFrameFunction · 0.85

Tested by

no test coverage detected