YBlog.

Fireworks Visualization with Canvas - JavaScript

Yuran
Yuran

Visualize fireworks with pure Javascript from scratch

Prerequisite

  • HTML/CSS: not required
  • Javascrip:t ES6 (class), Array methods (map, ...)

Step 1 - HTML base

  • The folder structure will look like this
fireworks
├── index.html
├── fireworks.js
  • index.html
<style>
  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
</style>
<canvas id="fireworks"></canvas>
<script src="index.js"></script>
  • fireworks.js
const canvas = document.querySelector('#fireworks');
const ctx = canvas.getContext('2d');

Step 2 - Particle Class

  • In fireworks.js
const canvas = document.querySelector('#fireworks');
const ctx = canvas.getContext('2d');

+  class Particle {
+    constructor(x, y, radius, color, velocity) {
+      this.x = x;
+      this.y = y;
+      this.radius = radius;
+      this.color = color;
+      this.velocity = velocity;
+  }
}

More.

Cover Image for Kho game miễn phí (Cập nhật liên tục)

Kho game miễn phí (Cập nhật liên tục)

Yuran
Yuran
Cover Image for Thủ thuật hay khi sử dụng máy tính cá nhân (Cập nhật liên tục)

Thủ thuật hay khi sử dụng máy tính cá nhân (Cập nhật liên tục)

Yuran
Yuran
Cover Image for Xóa ứng dụng hệ thống trên điện thoại (Thành công 100%)

Xóa ứng dụng hệ thống trên điện thoại (Thành công 100%)

Yuran
Yuran
Cover Image for MambaUI - Simple UI Library for your TailwindCSS project

MambaUI - Simple UI Library for your TailwindCSS project

Yuran
Yuran
discover