- Author:
- Jocelyn NATALI
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- Compo:
- classic
- Demo link:
- https://js1k.com/2012-love/demo/1229
- Shortlink:
- https://js1k.com/1229
- Blog post:
- please update here!
- Bytes:
- 716
- Chars:
- 716
- Submission
var e=c,g=a,h=[],i=2*Math.PI;e.width=window.innerWidth;e.height=window.innerHeight;for(var k=0;100>k;k++){var l=e.width/2,m=e.height/2,n=-10+20*Math.random(),o=-10+20*Math.random(),p=e.height/10,p=p+Math.random()*p;h.push(new q)}g.fillStyle="#000";g.fillRect(0,0,e.width,e.height);setInterval(r,30);function r(){for(var j in h){var f=h[j],d=f;if(0>d.x||d.x>e.width-1)d.a*=-1;if(0>d.y||d.y>e.height-1)d.b*=-1;d.x+=d.a;d.y+=d.b;g.fillStyle=f.color;g.beginPath();g.arc(f.x,f.y,f.width,0,i,!0);g.fill()}}function q(){var j=m,f=n,d=o,s=p,t="rgba("+Math.round(255*Math.random())+", "+Math.round(255*Math.random())+", "+Math.round(255*Math.random())+", 0.01)";this.x=l;this.y=j;this.a=f;this.b=d;this.width=s;this.color=t};
- Description
- It's that you can feel when your are in love. Full window colored plasma.
- Base64 encoded
dmFyIGU9YyxnPWEsaD1bXSxpPTIqTWF0aC5QSTtlLndpZHRoPXdpbmRvdy5pbm5lcldpZHRoO2UuaGVpZ2h0PXdpbmRvdy5pbm5lckhlaWdodDtmb3IodmFyIGs9MDsxMDA+aztrKyspe3ZhciBsPWUud2lkdGgvMixtPWUuaGVpZ2h0LzIsbj0tMTArMjAqTWF0aC5yYW5kb20oKSxvPS0xMCsyMCpNYXRoLnJhbmRvbSgpLHA9ZS5oZWlnaHQvMTAscD1wK01hdGgucmFuZG9tKCkqcDtoLnB1c2gobmV3IHEpfWcuZmlsbFN0eWxlPSIjMDAwIjtnLmZpbGxSZWN0KDAsMCxlLndpZHRoLGUuaGVpZ2h0KTtzZXRJbnRlcnZhbChyLDMwKTtmdW5jdGlvbiByKCl7Zm9yKHZhciBqIGluIGgpe3ZhciBmPWhbal0sZD1mO2lmKDA+ZC54fHxkLng+ZS53aWR0aC0xKWQuYSo9LTE7aWYoMD5kLnl8fGQueT5lLmhlaWdodC0xKWQuYio9LTE7ZC54Kz1kLmE7ZC55Kz1kLmI7Zy5maWxsU3R5bGU9Zi5jb2xvcjtnLmJlZ2luUGF0aCgpO2cuYXJjKGYueCxmLnksZi53aWR0aCwwLGksITApO2cuZmlsbCgpfX1mdW5jdGlvbiBxKCl7dmFyIGo9bSxmPW4sZD1vLHM9cCx0PSJyZ2JhKCIrTWF0aC5yb3VuZCgyNTUqTWF0aC5yYW5kb20oKSkrIiwgIitNYXRoLnJvdW5kKDI1NSpNYXRoLnJhbmRvbSgpKSsiLCAiK01hdGgucm91bmQoMjU1Kk1hdGgucmFuZG9tKCkpKyIsIDAuMDEpIjt0aGlzLng9bDt0aGlzLnk9ajt0aGlzLmE9Zjt0aGlzLmI9ZDt0aGlzLndpZHRoPXM7dGhpcy5jb2xvcj10fTs=
- Original source
var g_body = b;
var g_canvas = c;
var g_context = a;
var g_ballArray = new Array();
var g_2PI = Math.PI * 2;
init();
function init() {
g_canvas.width = window.innerWidth;
g_canvas.height = window.innerHeight;
for (var i = 0; i < 100; i++) {
var x = g_canvas.width / 2;
var y = g_canvas.height / 2;
var xInc = -10 + Math.random() * 20;
var yInc = -10 + Math.random() * 20;
var width = g_canvas.height / 10;
width += Math.random() * width;
var color = getColor(Math.round(Math.random() * 255), Math.round(Math.random() * 255), Math.round(Math.random() * 255), 0.01);
g_ballArray.push(new Ball(x, y, xInc, yInc, width, color));
}
clearScreen("#000");
setInterval(animate, 30);
}
function animate() {
for (var i in g_ballArray) {
var ball = g_ballArray[i];
ball.manage();
ball.draw();
}
}
function clearScreen(color) {
g_context.fillStyle = color;
g_context.fillRect(0, 0, g_canvas.width, g_canvas.height);
}
/**
* @constructor
*/
function Ball(x, y, xInc, yInc, width, color) {
this.x = x;
this.y = y;
this.xInc = xInc;
this.yInc = yInc;
this.width = width;
this.color = color;
}
Ball.prototype.manage = function () {
if ((this.x < 0) || (this.x > (g_canvas.width - 1)))
this.xInc *= -1;
if ((this.y < 0) || (this.y > (g_canvas.height - 1)))
this.yInc *= -1;
this.x += this.xInc;
this.y += this.yInc;
}
Ball.prototype.draw = function () {
g_context.fillStyle = this.color;
g_context.beginPath();
g_context.arc(this.x, this.y, this.width, 0, g_2PI, true);
g_context.fill();
}
function getColor(r, g, b, a) {
return "rgba(" + r + ", " + g + ", " + b + ", " + a + ")";
}