Rain Landing in a Pond
How do I make an rain landing in a pond?
A series of slowly expanding circles, randomly appearing on a blue background (subtle circular gradient) gives me the impression of rain drops falling in a pond, creating ripples. Although the appearance is quite different, I based the code on this pen here, http://codepen.io/jackrugile/pen/Jbnpv.. What is a rain landing in a pond? How do you make a rain landing in a pond? This script and codes were developed by Ed Ball on 12 November 2022, Saturday.
Rain Landing in a Pond - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Rain Landing in a Pond</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <body> <canvas id="c"></canvas>
</body> <script src="js/index.js"></script>
</body>
</html>
Rain Landing in a Pond - Script Codes CSS Codes
body { margin: 0; padding: 0; height: 100%; width: 100%; }
canvas { display: block; position: absolute; background: -moz-radial-gradient(center, ellipse cover, rgba(171,209,234,0.5) 0%, rgba(125,185,232,0.75) 100%); /* FF3.6+ */ background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,rgba(171,209,234,0.5)), color-stop(100%,rgba(125,185,232,0.75))); /* Chrome,Safari4+ */ background: -webkit-radial-gradient(center, ellipse cover, rgba(171,209,234,0.5) 0%,rgba(125,185,232,0.75) 100%); /* Chrome10+,Safari5.1+ */ background: -o-radial-gradient(center, ellipse cover, rgba(171,209,234,0.5) 0%,rgba(125,185,232,0.75) 100%); /* Opera 12+ */ background: -ms-radial-gradient(center, ellipse cover, rgba(171,209,234,0.5) 0%,rgba(125,185,232,0.75) 100%); /* IE10+ */ background: radial-gradient(ellipse at center, rgba(171,209,234,0.5) 0%,rgba(125,185,232,0.75) 100%); /* W3C */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#80abd1ea', endColorstr='#bf7db9e8',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */ }
Rain Landing in a Pond - Script Codes JS Codes
//setTimeoue needed to get full screen canvas
setTimeout(function() {
function resizeCanvas() { ch = window.innerHeight; cw = window.innerWidth; c.width = cw; c.height = ch;
};
var cw, ch, c = document.getElementById('c'), ctx = c.getContext('2d'), parts = [], globalTick = 0, rand = function(min, max){ return Math.floor( (Math.random() * (max - min + 1) ) + min); };
var Part = function(){ this.reset();
};
Part.prototype.reset = function(){ this.startRadius = rand(1, 10); // this.startRadius = rand(20, 25); this.radius = this.startRadius; this.x = rand(0, c.width); this.y = rand(0, c.height); this.hue = 210; this.saturation = rand(40, 60); this.lightness = rand(70, 80); this.startAlpha = 0.5; this.alpha = this.startAlpha; this.decayRate = .3; this.startLife = rand(20, 30); // this.startLife = 15; this.life = this.startLife; this.lineWidth = 1;
}
Part.prototype.update = function(){ this.alpha = this.startAlpha * (this.life / this.startLife); this.radius = this.radius+1; this.life -= this.decayRate;
};
Part.prototype.render = function(){ ctx.beginPath(); ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false); ctx.fillStyle = ctx.strokeStyle = 'hsla('+this.hue+', '+this.saturation+'%, '+this.lightness+'%, '+this.alpha+')'; ctx.lineWidth = this.lineWidth; ctx.fill(); // ctx.stroke();
};
var createParts = function(){ parts.push(new Part());
};
var updateParts = function(){ var i = parts.length; while(i--){ if (parts[i].life < 0){ parts.splice(i, 1) } parts[i].update(); }
};
var renderParts = function(){ var i = parts.length; while(i--){ parts[i].render(); }
};
var clear = function(){ ctx.globalCompositeOperation = 'destination-out'; ctx.fillStyle = 'hsla(0, 0%, 0%, 1)'; ctx.fillRect(0, 0, cw, ch); ctx.globalCompositeOperation = 'source-over';
};
//Run through the first iterations to get all the parts ready for rendering.
for (i = 0 ; i < 200 ; i++){ if (globalTick % 6 == 0){ createParts(); } updateParts(); globalTick++;
}
var loop = function(){ window.requestAnimFrame(loop, c); clear(); if (globalTick % 6 == 0){ createParts(); } updateParts(); renderParts(); globalTick++;
};
window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)}}();
resizeCanvas();
window.onresize = resizeCanvas;
loop();
}, 1);
Developer | Ed Ball |
Username | edball |
Uploaded | November 12, 2022 |
Rating | 4.5 |
Size | 3,009 Kb |
Views | 16,192 |
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 |
Purple Rain | 2,783 Kb |
Chues | 4,045 Kb |
Estimating Pi using the Monte Carlo Method | 3,025 Kb |
Floating Helicopter | 3,024 Kb |
DTMF Tones in Web Audio | 2,938 Kb |
Ringback tone in Web Audio | 2,851 Kb |
NASA Quindar tones in Web Audio | 2,787 Kb |
Planetary Gear System | 2,340 Kb |
Alphabet Monogram with SCSS and SVG | 7,082 Kb |
Happypillar | 3,181 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 |
CSS Donut Charts | Seanstopnik | 2,908 Kb |
Twitch | SarahDunlap | 2,937 Kb |
Halo 5 REQ Guide Bookmarklet | Cwacht | 3,993 Kb |
Yuliya v krylova | Rafszul | 37,351 Kb |
A Pen by Jim Savage | Madebyjam | 2,418 Kb |
Sass random color animation | Jotavejv | 4,827 Kb |
Multi column experiment. | Spylefkaditis | 2,805 Kb |
Buttons for autumn | Nikazawila | 1,795 Kb |
Pure CSS read more toggle | Idered | 2,344 Kb |
Drag in vanilla js using dotval math instead of translate | Paulq | 2,662 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!