import { useState, useEffect, useRef } from 'react'; import { Terminal, Cpu, Power, Maximize, MessageSquare, Hexagon, Box, Circle, Brain, Robot } from 'lucide-react'; export default function CyberpunkInterface() { const [messages, setMessages] = useState([]); const [input, setInput] = useState(''); const [isProcessing, setIsProcessing] = useState(false); const [systemStatus, setSystemStatus] = useState('ONLINE'); const [neuralStatus, setNeuralStatus] = useState('CALIBRATING'); const [pointer, setPointer] = useState({ x: 0, y: 0 }); const [robotPosition, setRobotPosition] = useState({ x: 50, y: 50 }); const [isCalibrating, setIsCalibrating] = useState(true); const canvasRef = useRef(null); const messagesEndRef = useRef(null); const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); }; useEffect(() => { scrollToBottom(); }, [messages]); const handleClick = async (e) => { const rect = e.currentTarget.getBoundingClientRect(); const x = ((e.clientX - rect.left) / rect.width * 100).toFixed(2); const y = ((e.clientY - rect.top) / rect.height * 100).toFixed(2); setPointer({ x, y }); const clickMessage = `Interface accessed at coordinates: X:${x}% Y:${y}%`; await processMessage(clickMessage); }; const processMessage = async (text) => { setIsProcessing(true); setMessages(prev => [...prev, { role: 'user', content: text }]); try { const response = await fetch('https://www.sitebrew.ai/api/genai', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ messages: [ { role: 'system', content: 'You are a cyberpunk AI system. Respond in a cryptic, technological manner with references to cyber culture. Keep responses brief and mysterious.' }, { role: 'user', content: text } ] }) }); const data = await response.json(); setMessages(prev => [...prev, data.message]); } catch (error) { setMessages(prev => [...prev, { role: 'assistant', content: 'ERROR: Neural connection interrupted. Retry sequence initiated.' }]); } setIsProcessing(false); }; const handleSubmit = async (e) => { e.preventDefault(); if (!input.trim()) return; const userInput = input; setInput(''); await processMessage(userInput); }; // Neural Network Visualization useEffect(() => { const canvas = canvasRef.current; const ctx = canvas.getContext('2d'); let animationFrameId; const neurons = Array.from({ length: 50 }, () => ({ x: Math.random() * canvas.width, y: Math.random() * canvas.height, connections: [], })); // Create neural connections neurons.forEach(neuron => { const connectionCount = Math.floor(Math.random() * 3) + 1; for (let i = 0; i < connectionCount; i++) { const target = neurons[Math.floor(Math.random() * neurons.length)]; neuron.connections.push(target); } }); const drawNeuralNetwork = () => { ctx.clearRect(0, 0, canvas.width, canvas.height); // Draw connections neurons.forEach(neuron => { neuron.connections.forEach(target => { ctx.beginPath(); ctx.moveTo(neuron.x, neuron.y); ctx.lineTo(target.x, target.y); ctx.strokeStyle = 'rgba(6, 182, 212, 0.2)'; ctx.lineWidth = 1; ctx.stroke(); }); }); // Draw neurons neurons.forEach(neuron => { ctx.beginPath(); ctx.arc(neuron.x, neuron.y, 2, 0, Math.PI * 2); ctx.fillStyle = 'rgba(6, 182, 212, 0.5)'; ctx.fill(); }); // Animate neurons neurons.forEach(neuron => { neuron.x += (Math.random() - 0.5) * 0.5; neuron.y += (Math.random() - 0.5) * 0.5; }); animationFrameId = requestAnimationFrame(drawNeuralNetwork); }; drawNeuralNetwork(); return () => { cancelAnimationFrame(animationFrameId); }; }, []); // Gesture tracking useEffect(() => { let videoElement; let gestureInterval; const setupGestureTracking = async () => { try { const stream = await navigator.mediaDevices.getUserMedia({ video: true }); videoElement = document.createElement('video'); videoElement.srcObject = stream; await videoElement.play(); setIsCalibrating(false); setNeuralStatus('CONNECTED'); gestureInterval = setInterval(() => { // Simulate gesture detection const movement = { x: pointer.x + (Math.random() - 0.5) * 10, y: pointer.y + (Math.random() - 0.5) * 10 }; setPointer(movement); // Move robot towards pointer with smooth interpolation setRobotPosition(prev => ({ x: prev.x + (movement.x - prev.x) * 0.1, y: prev.y + (movement.y - prev.y) * 0.1 })); }, 50); } catch (error) { setNeuralStatus('ERROR'); console.error('Failed to initialize gesture tracking:', error); } }; setupGestureTracking(); return () => { if (videoElement?.srcObject) { videoElement.srcObject.getTracks().forEach(track => track.stop()); } clearInterval(gestureInterval); }; }, [pointer]); return (
Please wait while we establish the neural connection...