Canvas from Scratch: Frame Animation, a Vibe-Coded Shooter, and the Declarative Power of ECharts
Canvas remains the foundation for any browser-based game, interactive visualization, or high-performance graphics. Understanding its frame loop and how libraries like ECharts build on it separates developers who can only style divs from those who can build real-time experiences. The Vibe Coding workflow shown here — AI-assisted ideation, code generation, and human review — is becoming a practical skill for shipping projects faster.
Canvas is not a DOM replacement — it's a bitmap drawing surface that excels at dynamic graphics, games, and data visualization. This practical guide starts with the Canvas tag, the 2D context, and the core drawing APIs (fillRect, strokeRect, clearRect), then builds up to frame animation using requestAnimationFrame instead of setInterval for smooth, performance-friendly loops.
The centerpiece is a complete airplane shooter game developed with a Vibe Coding workflow: an AI Agent helps brainstorm features, generate code, and iterate. The game implements a full game loop — clear, update, draw — with player movement, enemy spawning with difficulty scaling, AABB collision detection, and explosion effects. The code is modular and production-ready.
Finally, the guide shifts to ECharts, showing how declarative configuration (option objects) replaces manual Canvas calls for data dashboards. An AI Agent generates a complete multi-chart dashboard with KPI animations, illustrating the contrast between imperative drawing and declarative visualization. The takeaway: Canvas gives you raw power; ECharts gives you speed and abstraction.
The contrast between imperative Canvas drawing and declarative ECharts configuration is a microcosm of the broader shift from manual DOM manipulation to framework abstractions.
Using requestAnimationFrame for KPI number animations in ECharts dashboards shows how the same low-level API powers both games and data visualization.
The Vibe Coding approach — AI generates the skeleton, human reviews and debugs — mirrors how experienced developers use Copilot today, but applied to a complete project lifecycle.
Canvas games are a natural teaching tool for the render loop concept, which transfers directly to understanding React's reconciliation, game engines, and animation frameworks.
The enemy spawn logic (20% elite enemies with 2 HP) demonstrates how small probabilistic design decisions create emergent difficulty without complex AI.