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>Joyful Cake & Balloon Animation</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="cake">
<div class="layer candle"></div>
<div class="layer top-layer"></div>
<div class="layer layer-1"></div>
<div class="layer layer-2"></div>
<div class="layer layer-3"></div>
<div class="layer layer-4"></div>
</div>
<div class="wish-text"><span>HAPPY</span><span>BIRTHDAY</span><span>!!!</span></div>
<canvas id="canvas"></canvas>
<script src="index.js"></script>
</body>
</html>
Below is the css code for this video.
style.css
@import url('https://fonts.googleapis.com/css2?family=Monoton&display=swap');
* {
margin: 0;
padding: 0;
}
body {
height: 100vh;
width: 100%;
background: radial-gradient(circle, #9ba77380, #dfd2bf80), linear-gradient(to bottom, #ff696180, #aec6cfbf), #402f1d;
overflow: hidden;
}
.cake {
position: absolute;
top: 45%;
left: 50%;
height: 350px;
width: 300px;
transform: translate(-50%, -45%);
margin: 0 auto;
z-index: -1;
}
.layer {
position: absolute;
height: 200px;
width: 300px;
border-radius: 150px / 75px;
margin: 0 auto;
}
.top-layer {
top: 0;
height: 150px;
background: #f1d2b7;
z-index: 6;
}
.layer-1 {
top: 0;
background: #d1696f;
z-index: 5;
}
.layer-2 {
top: 50px;
background: #baba74;
z-index: 4;
}
.layer-3 {
top: 100px;
background: #d1696f;
z-index: 3;
}
.layer-4 {
top: 150px;
background: #dc9944;
z-index: 2;
}
.candle {
top: -20px;
left: 135px;
height: 100px;
width: 30px;
background: #284004;
z-index: 7;
}
.candle::before {
content: "";
position: absolute;
top: -50px;
left: calc(50% - 15px);
height: 50px;
width: 30px;
background: #fede17;
border-radius: 80% / 70%;
animation: flameAnim 4s ease-in-out infinite;
}
@keyframes flameAnim {
0%, 100% {
transform: skewX(5deg);
box-shadow: 0 0 40px #ffffff, 0 0 75px #ffffff, 0 0 90px #ffffff, 0 0 100px #ffffff;
}
25% {
transform: skewX(-10deg);
box-shadow: 0 0 40px #ffffff, 0 0 75px #fede17, 0 0 90px #fede17, 0 0 100px #ffffff;
}
50% {
transform: skewX(15deg);
box-shadow: 0 0 40px #fede17, 0 0 75px #fede17, 0 0 90px #000000, 0 0 100px #ffffff;
}
75% {
transform: skewX(-2deg);
box-shadow: 0 0 40px #ffffff, 0 0 75px #ffffff, 0 0 90px #ffffff, 0 0 100px #000000;
}
}
.wish-text {
position: absolute;
top: 90%;
width: 100%;
color: #402f1d;
transform: translateY(-90%);
font-size: 5vw;
font-family: 'Monoton', sans-serif;
text-align: center;
animation: textAnim 4s alternate infinite;
}
@keyframes textAnim {
0% {
text-shadow: 0 1px 1px #ea0d0180, 0 -1px 1px #600fff;
text-indent: 0.75vw;
letter-spacing: 0.75vw;
z-index: 1;
}
50% {
text-shadow: 0 0 1px #402f1d;
}
100% {
text-shadow: 1px 0 1px #600fff80, -1px 0 1px #ea0d01;
text-indent: 0.25vw;
letter-spacing: 0.25vw;
z-index: -1;
}
}
.wish-text span:first-of-type {
margin-right: 2.5vw;
}
.wish-text span:last-of-type {
margin-left: 2.5vw;
}
Below is the javascript code for this video.
index.js
var canvas = document.getElementById("canvas"), canvasCtx = canvas.getContext("2d"),
newcanvas = document.createElement("canvas"), newcanvasCtx = newcanvas.getContext("2d"),
canvaswidth, canvasheight, cx, cy, frames = 0, requestId = null, rad = (Math.PI / 180), kappa = 0.5,
x, y, balloons = [];
newcanvasCtx.strokeStyle = "#abcdef";
newcanvasCtx.lineWidth = 1;
function Balloon() {
this.r = randomIntFromInterval(20, 70);
this.R = 1.4 * this.r;
this.x = randomIntFromInterval(this.r, canvaswidth - this.r);
this.y = canvasheight + 2 * this.r;
this.a = this.r * 4.5;
this.pm = Math.random() < 0.5 ? -1 : 1;
this.speed = randomIntFromInterval(1.5, 4);
this.k = this.speed / 5;
this.hue = this.pm > 0 ? "210" : "10";
}
function draw() {
updateBalloons(newcanvasCtx);
canvasCtx.clearRect(0, 0, canvaswidth, canvasheight);
var img = newcanvas;
canvasCtx.drawImage(img, 0, 0);
requestId = window.requestAnimationFrame(draw);
}
function init() {
if (requestId) {
window.cancelAnimationFrame(requestId);
requestId = null;
}
canvaswidth = canvas.width = newcanvas.width = window.innerWidth;
cx = canvaswidth / 2;
canvasheight = canvas.height = newcanvas.height = window.innerHeight + 100;
cy = canvasheight;
newcanvasCtx.strokeStyle = "#abcdef";
newcanvasCtx.lineWidth = 1;
draw();
}
setTimeout(function () {
init();
window.addEventListener("resize", init, false);
}, 15);
function updateBalloons(ctx) {
frames += 1;
if (frames % 28 == 0 && balloons.length < 28) {
var balloon = new Balloon();
balloons.push(balloon);
}
ctx.clearRect(0, 0, canvaswidth, canvasheight);
for (let i = 0; i < balloons.length; i++) {
var b = balloons[i];
if (b.y > -b.a) { b.y -= b.speed; } else { b.y = parseInt(canvasheight + b.r + b.R); }
var p = thread(b, ctx);
b.cx = p.x;
b.cy = p.y - b.R;
ctx.fillStyle = gradient(p.x, p.y, b.r, b.hue);
drawBalloon(b, ctx);
}
}
function drawBalloon(b, ctx) {
var or = b.r * kappa,
p1 = { x: b.cx - b.r, y: b.cy }, pc11 = { x: p1.x, y: p1.y + or }, pc12 = { x: p1.x, y: p1.y - or },
p2 = { x: b.cx, y: b.cy - b.r }, pc21 = { x: b.cx - or, y: p2.y }, pc22 = { x: b.cx + or, y: p2.y },
p3 = { x: b.cx + b.r, y: b.cy }, pc31 = { x: p3.x, y: p3.y - or }, pc32 = { x: p3.x, y: p3.y + or },
p4 = { x: b.cx, y: b.cy + b.R }, pc41 = { x: p4.x + or, y: p4.y }, pc42 = { x: p4.x - or, y: p4.y },
t1 = { x: p4.x + 0.2 * b.r * Math.cos(70 * rad), y: p4.y + 0.2 * b.r * Math.sin(70 * rad) },
t2 = { x: p4.x + 0.2 * b.r * Math.cos(110 * rad), y: p4.y + 0.2 * b.r * Math.sin(110 * rad) };
ctx.beginPath();
ctx.moveTo(p4.x, p4.y);
ctx.bezierCurveTo(pc42.x, pc42.y, pc11.x, pc11.y, p1.x, p1.y);
ctx.bezierCurveTo(pc12.x, pc12.y, pc21.x, pc21.y, p2.x, p2.y);
ctx.bezierCurveTo(pc22.x, pc22.y, pc31.x, pc31.y, p3.x, p3.y);
ctx.bezierCurveTo(pc32.x, pc32.y, pc41.x, pc41.y, p4.x, p4.y);
ctx.lineTo(t1.x, t1.y);
ctx.lineTo(t2.x, t2.y);
ctx.closePath();
ctx.fill();
}
function thread(b, ctx) {
ctx.beginPath();
for (let i = b.a; i > 0; i -= 1) {
var t = i * rad;
x = b.x + b.pm * 50 * Math.cos(b.k * t - frames * rad);
y = b.y + b.pm * 25 * Math.sin(b.k * t - frames * rad) + 50 * t;
ctx.lineTo(x, y);
}
ctx.stroke();
return { x, y };
}
function gradient(x, y, r, hue) {
grd = canvasCtx.createRadialGradient(x - 0.5 * r, y - 1.7 * r, 0, x - 0.5 * r, y - 1.7 * r, r);
grd.addColorStop(0, 'hsla(' + hue + ', 100%, 75%, 0.9)');
grd.addColorStop(0.5, 'hsla(' + hue + ', 100%, 50%, 0.8)');
grd.addColorStop(1, 'hsla(' + hue + ', 100%, 25%, 0.7)');
return grd;
}
function randomIntFromInterval(min, max) { return ~~(Math.random() * (max - min + 1) + min); }
Thanks for visiting