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>Valentine Art Love Pixels</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Happy Valentine's Day</h1>
<canvas id="canvas" height="300" width="400"></canvas>
<h2>∞ Forever & Always ∞</h2>
<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=Love+Light&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
height: 100vh;
width: 100%;
overflow: hidden;
}
h1, h2 {
position: absolute;
width: 100%;
color: #bc204b;
text-align: center;
font-family: 'Love Light', cursive;
font-size: 5vw;
letter-spacing: 5px;
text-indent: 5px;
text-shadow: 0 0 1px #e0628740;
animation: textAnim 1s ease infinite;
}
@keyframes textAnim {
0%, 100% {
text-shadow: 0 0 1px #e0628740;
}
50% {
text-shadow: 0 0 10px #e06287;
}
}
h1 {
top: 10%;
transform: translateY(-10%);
}
h2 {
top: 90%;
transform: translateY(-90%);
}
#canvas {
display: block;
}
Below is the javascript code for this video.
index.js
window.requestAnimationFrame = (function () { return window.requestAnimationFrame || function (callback) { window.setTimeout(callback, 1000 / 60); }; })();
var fx = { config: { background: "#e9cdd0", color: "#bc204b", highlight: "#e06287" }, dots: [] };
fx.canvas = document.getElementById("canvas");
fx.ctx = fx.canvas.getContext("2d");
Math.TO_RAD = Math.PI / 180;
Math.getDistance = function (x1, y1, x2, y2) {
var xs = 0, ys = 0;
xs = x1 - x2;
ys = y1 - y2;
xs = xs * xs;
ys = ys * ys;
return Math.sqrt(xs + ys);
};
Math.getDegree = function (x1, y1, x2, y2) {
var dx = x2 - x1, dy = y2 - y1;
return Math.atan2(dy, dx) / Math.TO_RAD;
};
var Dot = function (opts) {
this.color = opts.color;
this.x = 0;
this.y = 0;
this.dest_x = (opts.dest_x - 75);
this.dest_y = (opts.dest_y - 75);
};
Dot.prototype.update = function () {
var d = this, dist_x = d.dest_x - d.x, dist_y = d.dest_y - d.y;
d.x += dist_x * 0.05;
d.y += dist_y * 0.05;
fx.ctx.fillStyle = d.color;
fx.ctx.fillRect(d.x - 2, d.y - 2, 4, 4);
};
fx.setFullScreen = function () {
fx.height = fx.canvas.height = window.innerHeight;
fx.width = fx.canvas.width = window.innerWidth;
};
fx.handleMouseEvent = function (e, power) {
var radius = 75, k = fx.dots.length, i = 0, mx, my, dist, degree, d;
if (e.offsetX) {
mx = e.offsetX;
my = e.offsetY;
} else if (e.layerX) {
mx = e.layerX;
my = e.layerY;
}
mx -= fx.width / 2;
my -= fx.height / 2;
for (; i < k; i = i + 1) {
d = fx.dots[i];
dist = Math.getDistance(mx, my, d.x, d.y);
if (dist < radius) {
degree = Math.getDegree(d.x, d.y, mx, my);
d.x += (Math.cos(degree * Math.TO_RAD) * ((radius - dist) * power));
d.y += (Math.sin(degree * Math.TO_RAD) * ((radius - dist) * power));
d.color = fx.config.highlight;
} else { d.color = fx.config.color; }
}
};
fx.createHeart = function () {
var coords = [[1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [3, 2], [3, 3], [3, 4], [3, 5],
[3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [5, 2], [5, 3],
[5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [6, 2], [6, 3], [6, 4], [6, 5], [6, 6], [6, 7], [6, 8], [6, 9], [6, 10],
[6, 11], [6, 12], [7, 3], [7, 4], [7, 5], [7, 6], [7, 7], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [8, 3], [8, 4], [8, 5],
[8, 6], [8, 7], [8, 8], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [9, 2], [9, 3], [9, 4], [9, 5], [9, 6], [9, 7], [9, 8], [9, 9], [9, 10],
[9, 11], [9, 12], [10, 2], [10, 3], [10, 4], [10, 5], [10, 6], [10, 7], [10, 8], [10, 9], [10, 10], [10, 11], [11, 2], [11, 3], [11, 4],
[11, 5], [11, 6], [11, 7], [11, 8], [11, 9], [11, 10], [11, 11], [12, 2], [12, 3], [12, 4], [12, 5], [12, 6], [12, 7], [12, 8], [12, 9],
[12, 10], [13, 3], [13, 4], [13, 5], [13, 6], [13, 7], [13, 8], [13, 9], [14, 4], [14, 5], [14, 6], [14, 7], [14, 8]], k = coords.length,
raster = 10, i = 0;
for (; i < k; i = i + 1) { fx.dots.push(new Dot({ dest_x: coords[i][0] * raster, dest_y: coords[i][1] * raster, color: fx.config.color })); }
};
fx.loop = function () {
var ctx = fx.ctx, k = fx.dots.length, i = 0;
ctx.fillStyle = fx.config.background;
ctx.fillRect(0, 0, fx.width, fx.height);
ctx.save();
ctx.translate(fx.width / 2, fx.height / 2);
for (; i < k; i = i + 1) { fx.dots[i].update(); }
ctx.restore();
requestAnimationFrame(fx.loop);
};
window.addEventListener("resize", fx.setFullScreen);
fx.canvas.addEventListener("mousemove", function (e) { fx.handleMouseEvent(e, -0.1); });
fx.canvas.addEventListener("mousedown", function (e) { fx.handleMouseEvent(e, 1); });
fx.setFullScreen();
fx.createHeart();
fx.loop();
Thanks for visiting