import React, { useState, useEffect, useRef, useCallback } from "react"; import axios from "axios"; import "./App.css"; /* ═══════════════════════════════════════════ GALAXY STARFIELD — Black & White Deep Space Stars bulge near cursor ═══════════════════════════════════════════ */ function GalaxyCanvas() { const canvasRef = useRef(null); const mouseRef = useRef({ x: -1000, y: -1000 }); const animRef = useRef(null); useEffect(() => { const canvas = canvasRef.current; const ctx = canvas.getContext("2d"); let W, H; const resize = () => { W = canvas.width = window.innerWidth; H = canvas.height = window.innerHeight; }; resize(); window.addEventListener("resize", resize); const STAR_COUNT = 350; const stars = []; class Star { constructor() { this.init(true); } init(initial) { this.x = Math.random() * W; this.y = initial ? Math.random() * H : -5; this.baseSize = Math.random() * 2 + 0.3; this.size = this.baseSize; this.speed = Math.random() * 0.15 + 0.03; this.twinkleSpeed = Math.random() * 0.04 + 0.01; this.twinklePhase = Math.random() * Math.PI * 2; this.brightness = Math.random() * 0.5 + 0.5; const tint = Math.random(); if (tint < 0.7) { this.r = 255; this.g = 255; this.b = 255; } else if (tint < 0.85) { this.r = 200; this.g = 220; this.b = 255; } else { this.r = 255; this.g = 230; this.b = 200; } } } for (let i = 0; i < STAR_COUNT; i++) stars.push(new Star()); const shooters = []; class Shooter { constructor() { this.reset(); } reset() { this.x = Math.random() * W * 0.8; this.y = Math.random() * H * 0.3; this.len = Math.random() * 140 + 80; this.speed = Math.random() * 14 + 10; this.angle = Math.PI / 5 + Math.random() * 0.4; this.life = 1; this.decay = Math.random() * 0.012 + 0.006; this.active = false; this.timer = Math.random() * 400 + 150; } } for (let i = 0; i < 3; i++) shooters.push(new Shooter()); const clouds = []; class Cloud { constructor(i) { this.angle = (Math.PI * 2 / 4) * i + Math.random(); this.radius = Math.random() * 200 + 250; this.cx = W * 0.5; this.cy = H * 0.5; this.orbit = Math.min(W, H) * 0.25 + Math.random() * 150; this.speed = (Math.random() * 0.0008 + 0.0003) * (i % 2 === 0 ? 1 : -1); this.alpha = Math.random() * 0.04 + 0.02; this.pulse = Math.random() * Math.PI * 2; } } for (let i = 0; i < 4; i++) clouds.push(new Cloud(i)); const handleMouse = (e) => { mouseRef.current.x = e.clientX; mouseRef.current.y = e.clientY; }; window.addEventListener("mousemove", handleMouse); const sparkles = []; class Sparkle { constructor(x, y) { this.x = x; this.y = y; const angle = Math.random() * Math.PI * 2; const speed = Math.random() * 2.5 + 1; this.vx = Math.cos(angle) * speed; this.vy = Math.sin(angle) * speed; this.size = Math.random() * 2.5 + 0.8; this.life = 1; this.decay = Math.random() * 0.03 + 0.015; } } const BULGE_RADIUS = 200, BULGE_SCALE = 5; let frame = 0, sparkleTimer = 0; const draw = () => { ctx.fillStyle = "#000000"; ctx.fillRect(0, 0, W, H); frame++; sparkleTimer++; const mx = mouseRef.current.x, my = mouseRef.current.y; for (const c of clouds) { c.angle += c.speed; c.pulse += 0.005; const px = c.cx + Math.cos(c.angle) * c.orbit; const py = c.cy + Math.sin(c.angle) * c.orbit * 0.5; const r = c.radius * (1 + Math.sin(c.pulse) * 0.15); const a = c.alpha * (0.85 + Math.sin(c.pulse) * 0.15); const g = ctx.createRadialGradient(px, py, 0, px, py, r); g.addColorStop(0, `rgba(255,255,255,${a})`); g.addColorStop(0.4, `rgba(200,200,220,${a * 0.5})`); g.addColorStop(1, `rgba(0,0,0,0)`); ctx.fillStyle = g; ctx.fillRect(px - r, py - r, r * 2, r * 2); } if (mx > 0 && my > 0 && sparkleTimer % 2 === 0) { sparkles.push(new Sparkle(mx + (Math.random() - 0.5) * 80, my + (Math.random() - 0.5) * 80)); if (sparkles.length > 80) sparkles.shift(); } for (const s of stars) { s.twinklePhase += s.twinkleSpeed; const twinkle = 0.5 + Math.sin(s.twinklePhase) * 0.5; const alpha = s.brightness * twinkle; const dx = mx - s.x, dy = my - s.y; const dist = Math.sqrt(dx * dx + dy * dy); let sizeMult = 1, extraGlow = 0, isBulged = false; if (dist < BULGE_RADIUS) { const ease = Math.pow(1 - dist / BULGE_RADIUS, 2); sizeMult = 1 + ease * (BULGE_SCALE - 1); extraGlow = ease * 25; isBulged = true; } const drawSize = s.baseSize * sizeMult; if (drawSize > 1.2 || extraGlow > 0) { ctx.beginPath(); ctx.arc(s.x, s.y, drawSize * 4 + extraGlow, 0, Math.PI * 2); ctx.fillStyle = `rgba(255,255,255,${alpha * 0.06 + (isBulged ? 0.08 : 0)})`; ctx.fill(); } ctx.beginPath(); ctx.arc(s.x, s.y, drawSize, 0, Math.PI * 2); ctx.fillStyle = `rgba(${s.r},${s.g},${s.b},${isBulged ? Math.min(1, alpha + 0.5) : alpha})`; ctx.shadowColor = isBulged ? "rgba(255,255,255,0.9)" : ""; ctx.shadowBlur = isBulged ? 15 : 0; ctx.fill(); ctx.shadowBlur = 0; if (isBulged && drawSize > 1.5) { const fa = extraGlow / 25 * 0.6, fl = drawSize * 6; ctx.strokeStyle = `rgba(255,255,255,${fa})`; ctx.lineWidth = 0.8; ctx.beginPath(); ctx.moveTo(s.x - fl, s.y); ctx.lineTo(s.x + fl, s.y); ctx.stroke(); ctx.beginPath(); ctx.moveTo(s.x, s.y - fl); ctx.lineTo(s.x, s.y + fl); ctx.stroke(); const dl = fl * 0.5; ctx.lineWidth = 0.4; ctx.strokeStyle = `rgba(255,255,255,${fa * 0.5})`; ctx.beginPath(); ctx.moveTo(s.x - dl, s.y - dl); ctx.lineTo(s.x + dl, s.y + dl); ctx.stroke(); ctx.beginPath(); ctx.moveTo(s.x + dl, s.y - dl); ctx.lineTo(s.x - dl, s.y + dl); ctx.stroke(); } s.y += s.speed; if (s.y > H + 10) s.init(false); } for (let i = sparkles.length - 1; i >= 0; i--) { const sp = sparkles[i]; sp.x += sp.vx; sp.y += sp.vy; sp.vx *= 0.97; sp.vy *= 0.97; sp.life -= sp.decay; if (sp.life <= 0) { sparkles.splice(i, 1); continue; } ctx.beginPath(); ctx.arc(sp.x, sp.y, sp.size * sp.life, 0, Math.PI * 2); ctx.fillStyle = `rgba(255,255,255,${sp.life * 0.9})`; ctx.shadowColor = "rgba(255,255,255,0.8)"; ctx.shadowBlur = 10; ctx.fill(); ctx.shadowBlur = 0; if (sp.size > 1.5) { const sLen = sp.size * 3 * sp.life; ctx.strokeStyle = `rgba(255,255,255,${sp.life * 0.4})`; ctx.lineWidth = 0.5; ctx.beginPath(); ctx.moveTo(sp.x - sLen, sp.y); ctx.lineTo(sp.x + sLen, sp.y); ctx.stroke(); ctx.beginPath(); ctx.moveTo(sp.x, sp.y - sLen); ctx.lineTo(sp.x, sp.y + sLen); ctx.stroke(); } } if (mx > 0 && my > 0) { const mg = ctx.createRadialGradient(mx, my, 0, mx, my, BULGE_RADIUS); mg.addColorStop(0, "rgba(255,255,255,0.08)"); mg.addColorStop(0.3, "rgba(255,255,255,0.03)"); mg.addColorStop(1, "rgba(0,0,0,0)"); ctx.fillStyle = mg; ctx.beginPath(); ctx.arc(mx, my, BULGE_RADIUS, 0, Math.PI * 2); ctx.fill(); } for (const s of shooters) { if (!s.active) { s.timer--; if (s.timer <= 0) s.active = true; continue; } s.x += Math.cos(s.angle) * s.speed; s.y += Math.sin(s.angle) * s.speed; s.life -= s.decay; if (s.life <= 0 || s.x > W + 100 || s.y > H + 100) { s.reset(); continue; } const tx = s.x - Math.cos(s.angle) * s.len, ty = s.y - Math.sin(s.angle) * s.len; const grad = ctx.createLinearGradient(tx, ty, s.x, s.y); grad.addColorStop(0, `rgba(255,255,255,0)`); grad.addColorStop(0.7, `rgba(255,255,255,${s.life * 0.3})`); grad.addColorStop(1, `rgba(255,255,255,${s.life * 0.9})`); ctx.beginPath(); ctx.moveTo(tx, ty); ctx.lineTo(s.x, s.y); ctx.strokeStyle = grad; ctx.lineWidth = 1.5; ctx.stroke(); ctx.beginPath(); ctx.arc(s.x, s.y, 2, 0, Math.PI * 2); ctx.fillStyle = `rgba(255,255,255,${s.life})`; ctx.shadowColor = "rgba(255,255,255,0.8)"; ctx.shadowBlur = 12; ctx.fill(); ctx.shadowBlur = 0; } animRef.current = requestAnimationFrame(draw); }; draw(); return () => { cancelAnimationFrame(animRef.current); window.removeEventListener("resize", resize); window.removeEventListener("mousemove", handleMouse); }; }, []); return ( ); } /* ═══════════════════════════════════════════ RADIAL GAUGE — SVG Arc Chart ═══════════════════════════════════════════ */ function RadialGauge({ score, size = 90, color = "#64c8ff", label }) { const s = Math.min(10, Math.max(0, isNaN(score) ? 0 : score)); const radius = (size - 12) / 2; const cx = size / 2, cy = size / 2; const circumference = 2 * Math.PI * radius; const arcLength = (s / 10) * circumference; const dashArray = `${arcLength} ${circumference - arcLength}`; return (
{note}
}Average improvement: = 0 ? "#69f0ae" : "#ff8a80" }}> {totalDelta >= 0 ? "+" : ""}{totalDelta.toFixed(1)} points
{data.summary || "Analysis complete."}
UNLEASH YOUR CODE
{message &&{message}
}UNLEASH YOUR CODE
{selectedOption !== "Analyze Code" ? ({outputText || "// Output appears here..."}
{/* ANALYZE button appears after modify output */}
{selectedOption === "Modify Code" && outputText && (
)}
{modifyCode || "// No original code found"}
{outputText || "// No modified code found"}
{message}
}