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>Water Waves</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<canvas id="myCanvas"></canvas>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<filter id="shadowed-goo">
<feGaussianBlur in="SourceGraphic" result="blur" stdDeviation="10" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -7"
result="goo" />
<feGaussianBlur in="goo" result="shadow" stdDeviation="3" />
<feColorMatrix in="shadow" mode="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -0.2"
result="shadow" />
<feOffset in="shadow" dx="1" dy="1" result="shadow" />
<feBlend in2="shadow" in="goo" result="goo" />
<feBlend in2="goo" in="SourceGraphic" result="mix" />
</filter>
<filter id="goo">
<feGaussianBlur in="SourceGraphic" result="blur" stdDeviation="10" />
<feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -7"
result="goo" />
<feBlend in2="goo" in="SourceGraphic" result="mix" />
</filter>
</defs>
</svg>
<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%;
background: hsl(190, 100%, 10%);
overflow: hidden;
}
#myCanvas {
display: block;
filter: url(#shadowed-goo);
}
svg {
display: none;
}
Below is the javascript code for this video.
index.js
const twoPi = Math.PI * 2;
class App {
constructor() {
this.canvas = document.getElementById("myCanvas");
this.context = this.canvas.getContext("2d");
this.height = this.canvas.height = window.innerHeight;
this.width = this.canvas.width = window.innerWidth;
this.center = { x: this.width / 2, y: this.height / 2 };
this.circleContainers = [];
window.addEventListener("resize", () => this.resizeCanvas(), false);
}
resizeCanvas() {
this.height = this.canvas.height = window.innerHeight;
this.width = this.canvas.width = window.innerWidth;
this.center = { x: this.width / 2, y: this.height / 2 };
this.circleContainers = [];
this.initializeCircleContainers();
}
initializeCircleContainers() {
for (let i = 0; i < this.width + 100; i += 100) {
for (let j = 0; j < this.height + 100; j += 100) {
let circleContainer = new CircleContainer(this.context, i, j);
circleContainer.initializeCircles();
this.circleContainers.push(circleContainer);
}
}
}
update() { for (let k = 0; k < this.circleContainers.length; k++) { this.circleContainers[k].update(); } }
render() {
this.context.clearRect(0, 0, this.width, this.height);
for (let l = 0; l < this.circleContainers.length; l++) { this.circleContainers[l].render(); }
}
loop() {
this.update();
this.render();
window.requestAnimationFrame(() => this.loop());
}
}
class CircleContainer {
constructor(context, x, y) {
this.context = context;
this.position = { x, y };
this.numberOfCircles = 19;
this.circles = [];
this.baseRadius = 20;
this.bounceRadius = 150;
this.singleSlice = twoPi / this.numberOfCircles;
}
initializeCircles() {
for (let m = 0; m < this.numberOfCircles; m++) {
this.circles.push(new Circle(this.position.x, this.position.y + Math.random(), this.baseRadius, this.bounceRadius, m * this.singleSlice));
}
}
update() { for (let n = 0; n < this.numberOfCircles; n++) { this.circles[n].update(this.context); } }
render() { for (let o = 0; o < this.numberOfCircles; o++) { this.circles[o].render(this.context); } }
}
class Circle {
constructor(x, y, baseRadius, bounceRadius, angleCircle) {
this.basePosition = { x, y };
this.position = { x, y };
this.speed = 0.01;
this.baseSize = 10;
this.size = 10;
this.angle = x + y;
this.baseRadius = baseRadius;
this.bounceRadius = bounceRadius;
this.angleCircle = angleCircle;
}
update() {
this.position.x = this.basePosition.x + Math.cos(this.angleCircle) * (Math.sin(this.angle + this.angleCircle) * this.bounceRadius + this.baseRadius);
this.position.y = this.basePosition.y + Math.sin(this.angleCircle) * (Math.sin(this.angle + this.angleCircle) * this.bounceRadius + this.baseRadius);
this.size = Math.cos(this.angle) * 8 + this.baseSize;
this.angle += this.speed;
}
render(context) {
context.fillStyle = "hsl(190, 100%, " + this.size * 4 + "%)";
context.beginPath();
context.arc(this.position.x, this.position.y, this.size, 0, twoPi);
context.fill();
}
}
window.onload = function () {
const app = new App();
app.initializeCircleContainers();
app.loop();
};
Thanks for visiting