The content on this website, including videos and code examples, is for educational purposes only. All demonstrations and designs are fictional and created to illustrate coding techniques. Any resemblance to existing websites or brands is purely coincidental.
The creators and administrators of this website do not claim ownership or affiliation with any existing websites or companies. Users are encouraged to use the information responsibly for learning purposes. Liability for any misuse of the content provided is not accepted.
Below is the html code for this video.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Spectacular Diwali Animation</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<canvas id="canvas"></canvas>
<div class="container">
<h4>happy</h4>
<h1><span>di</span><span>wa</span><span>li</span></h1>
</div>
<script src="index.js"></script>
</body>
</html>
Below is the css code for this video.
style.css
* {
margin: 0;
padding: 0;
}
body {
height: 100vh;
width: 100%;
overflow: hidden;
}
canvas {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.container {
display: flex;
height: 100%;
width: 100%;
background: linear-gradient(to right, #000000bf, #00000080, #000000bf),
radial-gradient(circle, #f0468e80, #7c457a80),
url('https://images.unsplash.com/photo-1635192592106-77a5aacbe1a3?auto=format&fit=crop');
color: #ffffff;
flex-direction: column;
justify-content: center;
align-items: center;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
font-family: sans-serif;
text-align: center;
text-transform: uppercase;
}
h4 {
font-size: 2.4vw;
margin-left: -27vw;
margin-bottom: 0.6vw;
letter-spacing: 6px;
text-shadow: -1.5px 1.5px 0.9px #ffffff80;
}
h1 {
position: relative;
font-size: 9.6vw;
line-height: 6.9vw;
z-index: 1;
animation: textShadowAnim 6s linear infinite;
}
h1 span {
display: block;
}
h1 span:nth-child(1) {
margin-left: -20.57vw;
}
h1 span:nth-child(3) {
margin-left: 19.25vw;
}
@keyframes textShadowAnim {
0%, 100% {
text-shadow: -3.3px 3.3px 1.5px #ffffff80;
}
25% {
text-shadow: -3.3px -3.3px 1.5px #ffffff80;
}
50% {
text-shadow: 3.3px -3.3px 1.5px #ffffff80;
}
75% {
text-shadow: 3.3px 3.3px 1.5px #ffffff80;
}
}
Below is the javascript code for this video.
index.js
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var canvasWidth = document.body.clientWidth;
var canvasHeight = document.body.clientHeight;
canvas.width = canvasWidth;
canvas.height = canvasHeight;
var fireworkNodes = [];
const PI_TWO = Math.PI * 2;
const DEGREE_TO_RADIAN = Math.PI / 180;
function getRandomInt(max, min = 0) { return Math.floor(Math.random() * (max - min) + min); }
function getRandomFloat(max, min = 0) { return Math.random() * (max - min) + min; }
var angleFactor = 0;
function animate() {
requestAnimationFrame(animate);
ctx.globalCompositeOperation = "destination-out";
ctx.fillStyle = "rgba(0, 0, 0, 0.078)";
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
ctx.globalCompositeOperation = "lighter";
var totalNodes = fireworkNodes.length;
while (totalNodes--) {
let node = fireworkNodes[totalNodes];
drawFireworkNode(node);
if (node.isFadedOut) { fireworkNodes.splice(totalNodes, 1); }
}
if (fireworkNodes.length < 10) {
let newNodes = 6;
while (newNodes--) {
fireworkNodes.push(createFireworkNode(
getRandomInt(canvasWidth), getRandomInt(canvasHeight),
40, `hsl(${getRandomInt(300)}, 100%, 50%)`, 100
));
}
}
}
function drawFireworkNode(node) {
var totalParticles = node.particles.length;
while (totalParticles--) {
let particle = node.particles[totalParticles];
ctx.beginPath();
ctx.fillStyle = particle.color;
ctx.arc(particle.x, particle.y, 1, 0, PI_TWO);
ctx.fill();
ctx.closePath();
updateParticlePosition(particle);
if (particle.isFadedOut) {
node.particles.splice(totalParticles, 1);
if (node.particleCount > 20) {
fireworkNodes.push(createFireworkNode(
particle.x, particle.y, node.explosionRadius * 10,
node.color, Math.floor(node.particleCount / 10)
));
}
}
}
if (!node.particles.length) { node.isFadedOut = true; }
}
function updateParticlePosition(particle) {
var dx = particle.x - particle.targetX;
var dy = particle.y - particle.targetY;
var distance = Math.sqrt(dx * dx + dy * dy);
particle.isFadedOut = distance < 1;
particle.x -= dx * particle.velocity;
particle.y -= dy * particle.velocity;
}
function createFireworkNode(x, y, radius, color, particleCount) {
radius = radius || 0;
particleCount = particleCount || 0;
var particles = [];
var count = particleCount;
while (particleCount--) {
let angleModifier = Math.floor(Math.random() * 100);
let distanceFromCenter = Math.floor(radius * Math.random());
particles.push({
x: x, y: y,
targetX: x + distanceFromCenter * Math.cos(angleFactor * angleModifier * DEGREE_TO_RADIAN),
targetY: y + distanceFromCenter * Math.sin(angleFactor * angleModifier * DEGREE_TO_RADIAN),
color: color, velocity: getRandomFloat(1, 0.05), isFadedOut: false
});
angleFactor++;
}
return {
explosionRadius: radius,
particleCount: count,
color: color,
x: x,
y: y,
particles: particles,
isFadedOut: false
};
}
animate();
Thanks for visiting