Rain Landing in a Pond

Developer
Size
3,009 Kb
Views
16,192

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 Previews

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);
Rain Landing in a Pond - Script Codes
Rain Landing in a Pond - Script Codes
Home Page Home
Developer Ed Ball
Username edball
Uploaded November 12, 2022
Rating 4.5
Size 3,009 Kb
Views 16,192
Do you need developer help for Rain Landing in a Pond?

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!

Ed Ball (edball) Script Codes
Create amazing love letters with AI!

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!