Snow
How do I make an snow?
Forked from Brian Douglas's Pen Snow.. What is a snow? How do you make a snow? This script and codes were developed by Moeid Saleem on 28 October 2022, Friday.
Snow - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Snow</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas id="c" width="800" height="800"></canvas> <script src="js/index.js"></script>
</body>
</html>
Snow - Script Codes CSS Codes
body { background: #222; text-align: center;
}
canvas { background: -webkit-linear-gradient( rgb(84, 184, 195), rgb(125, 205, 178) ); background: linear-gradient( rgb(84, 184, 195), rgb(125, 205, 178) ); opacity: 30%;
}
Snow - Script Codes JS Codes
function Utils() {}
Utils.prototype.randomNumber = function(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min;
};
Utils.prototype.Sin = function(n, angle, arc, plus) { return plus ? n + Math.sin(angle) * arc : n - Math.sin(angle) * arc;
};
Utils.prototype.Cos = function(n, angle, arc, plus) { return plus ? n + Math.cos(angle) * arc : n - Math.cos(angle) * arc;
};
var utils = new Utils();
(function(Utils) { function Canvas(_) { this.canvas = document.getElementById(_); this.context = this.canvas.getContext('2d'); this.width = this.canvas.width; this.height = this.canvas.height; } function Snow(canvas, amount) { this.canvas = canvas; this.amount = amount; this.generate(); this.init(); } Snow.prototype.config = function(_) { return { id: _, x: 0, y: 0, vx: 0, vy: 0, alpha: 0.1, angle: 0 }; }; Snow.prototype.generate = function() { var i, snowflake; this.arr = []; for (i = 0; i < this.amount; ++i) { snowflake = this.config(i); this.arr.push(snowflake); } }; Snow.prototype.reset = function(_) { _ = this.arr[_]; _.init = false; _.x = Utils.randomNumber(0, this.canvas.width); _.y = Utils.randomNumber(0, this.canvas.height / 3); _.vy = Utils.randomNumber(0.5, 1.5); _.vx = Utils.randomNumber(0.1, 0.5); _.alpha = Utils.randomNumber(0.1, 0.5); }; Snow.prototype.tick = function(_) { var index = _; _ = this.arr[_]; this.canvas.context.fillStyle = "rgba(255,255,255, " + _.alpha + ")"; if (_.id % 2 === 0) { this.canvas.context.fillRect(_.x, _.y, 3, 3); } else { this.flake(_); } _.y += _.vy; _.id % 2 === 0 ? _.x = Utils.Sin(_.x, _.angle, 1, true) : _.x = Utils.Cos(_.x, _.angle, 0.5, true); _.angle+=0.01; if (_.init) { _.alpha -= 0.01; } else { _.alpha += 0.01; } if (_.alpha <= 0) { this.reset(index); } else if (_.alpha >= 1) { _.init = true; } }; Snow.prototype.flake = function(_) { var size = 3; this.canvas.context.save(); this.canvas.context.translate(_.x, _.y); for (var row = 0; row < 3; row++) { for (var column = 0; column < 3; column++) { var x = column * size; var y = row * size; if (row % 2 == 0) { if (column % 2 == 0) { this.canvas.context.fillStyle = "transparent"; } else { this.canvas.context.fillStyle = "rgba(255,255,255, " + _.alpha + ")"; } } else { if (column % 2 == 0) { this.canvas.context.fillStyle = "rgba(255,255,255, " + _.alpha + ")"; } else { this.canvas.context.fillStyle = "transparent"; } } this.canvas.context.fillRect(x, y, size, size); } } this.canvas.context.fill(); this.canvas.context.restore(); }; Snow.prototype.render = function() { var _this = this, i; this.canvas.context.clearRect(0, 0, this.canvas.width, this.canvas.height); for (i = 0; i < this.arr.length; ++i) { this.tick(i); } window.requestAnimationFrame(this.render.bind(this)); }; Snow.prototype.init = function() { var i; for (i = 0; i < this.arr.length; ++i) { this.reset(i); } this.render(); console.table(this.arr); }; return new Snow(new Canvas('c'), 20);
})(utils);
Developer | Moeid Saleem |
Username | moeidsaleem |
Uploaded | October 28, 2022 |
Rating | 3 |
Size | 2,733 Kb |
Views | 22,264 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
A Pen by Moeid Saleem | 1,862 Kb |
TEP landing page | 5,476 Kb |
Astronomic particles | 3,784 Kb |
Astronomic particles | 3,652 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Calculator - codevember 08 - 2016 | Caiocares | 3,260 Kb |
Sony Xperia Z3 Flat MockUp | Dapinitial | 4,379 Kb |
A Pen by Xand0r | Xand0r | 1,928 Kb |
Mobile first social buttons with no iframe | Alistairtweedie | 3,158 Kb |
Adding and Removing Element | Accimeesterlin | 2,119 Kb |
CSS- UI Element States Pseudo-Classes | Tesla809 | 2,206 Kb |
CSS3 Fullscreen Background Slideshow | Leetech | 3,435 Kb |
Replace url via jquery | Serluk | 1,429 Kb |
RPG Style Text Dialogue | Odylic | 2,635 Kb |
Nice responsive team page | Infomiho | 3,139 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!