Mar 29, 2025
Project Folder Contents:
index.html: HTML markup.style.css: Styling for the canvas.script.js: JavaScript functionality.index.html Structure:
canvas1.style.css in the head.script.js before the closing body tag.Canvas Basics:
position: absolute; background: black; width: 100%; height: 100%; top: 0; left: 0;Getting Canvas Element:
script.js:
const canvas = document.getElementById('canvas1');
const ctx = canvas.getContext('2d');
Canvas Drawing Methods:
fillStyle, strokeStyle, etc.arc, fillRect, fillText.Drawing Shapes:
ctx.fillRect(10, 10, 50, 150);ctx.arc(x, y, radius, startAngle, endAngle) and call ctx.fill() after ctx.beginPath().addEventListener for resize to dynamically adjust dimensions.Tracking Mouse Coordinates:
mouse object with x and y properties to store mouse coordinates.Drawing on Click:
drawCircle function to draw a circle at the mouse position.Creating Animation:
animate function to repeatedly call drawing methods.requestAnimationFrame for a smooth animation loop.ctx.clearRect(0, 0, canvas.width, canvas.height);.Adding Particles:
Particle class to manage individual particle properties (position, size, speed).update its position and draw it on canvas.Adding Randomized Particle Movement:
update method based on their speeds.Implementing Constellation Effect:
Dynamic Color and Size: