Skip to content

Instantly share code, notes, and snippets.

@simudream
Created November 27, 2014 00:34
Show Gist options
  • Save simudream/4a75b310bcfc6fb1d25e to your computer and use it in GitHub Desktop.
Save simudream/4a75b310bcfc6fb1d25e to your computer and use it in GitHub Desktop.
Rain of Fire
var s = new Sketch.create({autoclear: false}),
drops = [],
maxDrops = 200,
Drop = function() {};
Drop.prototype.setup = function() {
this.x = random(0, s.width);
this.y = random(-200, -5);
this.radius = random(1,4);
this.vy = this.radius + random();
this.h = random(0,30);
this.s = 100;
this.l = random(40,50);
this.color = 'hsla('+random(0,30)+', 100%, 50%, 1)';
}
Drop.prototype.update = function() {
this.x += random(-1,1);
this.y += this.vy;
var r = random();
if (r < .4) this.l -= r;
}
Drop.prototype.draw = function() {
s.fillStyle = 'hsl('+this.h+','+this.s+'%,'+this.l+'%)'
s.beginPath();
s.arc(this.x, this.y, this.radius, 0, TWO_PI);
s.fill();
s.closePath();
}
s.setup = function() {
for(var i=0; i<maxDrops; i++) {
drops[i] = new Drop();
drops[i].setup();
}
}
s.update = function() {
var i = drops.length;
while(i--) {
drops[i].update();
if (drops[i].l < 0 || drops[i].y - drops[i].radius > s.height) {
drops[i].setup();
}
}
}
s.draw = function() {
s.fillStyle = 'rgba(0,0,0,.1)';
s.fillRect(0,0,s.width,s.height);
for (var i = 0; i < drops.length; i++) {
drops[i].draw();
}
}
@import "compass/css3";
html, body {
background: #000;
margin: 0;
padding: 0;
overflow: hidden;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment