GLOBAL_PULSATION = false;
var ENCODE_DATA = ["BLUR", "BLENDING", "GLOBAL_PULSATION", "TEXT", "TREMBLING", "ARC", "PULSATION_PERIOD", "PARTICLE_RADIUS", "PULSATION", "BLINK"];
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) {
QUALITY_TO_FONT_SIZE = [10, 20, 50, 100, 200, 350];
QUALITY_TO_SCALE = [20, 14, 6, 3, 1.5, 0.9];
QUALITY_TO_TEXT_POS = [10, 18, 43, 86, 170, 280];
window.onload = function() {
document.body.style.backgroundColor = BACKGROUND;
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var tcanvas = document.createElement("canvas");
var tctx = tcanvas.getContext("2d");
single_particle_area = total_area / total_particles;
area_length = Math.sqrt(single_particle_area);
console.log(area_length);
for(var i = 1; i <= total_particles; i++) {
particles.push(new particle(i));
this.r = Math.round(Math.random() * 255 | 0);
this.g = Math.round(Math.random() * 255 | 0);
this.b = Math.round(Math.random() * 255 | 0);
this.x = (i * area_length) % W;
this.y = (i * area_length) / W * area_length;
this.deltaOffset = Math.random() * PULSATION_PERIOD | 0;
this.radius = 0.1 + Math.random() * 2;
function new_positions() {
tctx.fillStyle = "white";
tctx.fillRect(0, 0, W, H)
tctx.font = "bold " + QUALITY_TO_FONT_SIZE[QUALITY] + "px " + FANCY_FONT;
var text = TEXT || String(Math.random()).substr(-3);
tctx.strokeStyle = "black";
tctx.strokeText(text, (QUALITY + 1) * 5, QUALITY_TO_TEXT_POS[QUALITY]);
image_data = tctx.getImageData(0, 0, W, H);
pixels = image_data.data;
for(var i = 0; i < pixels.length; i = i + 4) {
x: (i / 4 % W | 0) * QUALITY_TO_SCALE[QUALITY] | 0,
y: (i / 4 / W | 0) * QUALITY_TO_SCALE[QUALITY] | 0
positions.push(position);
ctx.globalCompositeOperation = "source-over";
if(BLUR) ctx.globalAlpha = 0.1;
else if(!BLUR && !BLINK) ctx.globalAlpha = 1.0;
ctx.fillStyle = BACKGROUND;
if(BLENDING) ctx.globalCompositeOperation = "lighter";
for(var i = 0; i < particles.length; i++) {
ctx.fillStyle = "rgb(" + p.r + ", " + p.g + ", " + p.b + ")";
ctx.fillStyle = "rgba(" + p.r + ", " + p.g + ", " + p.b + ", " + p.alpha + ")";
if(BLINK) ctx.globalAlpha = Math.sin(Math.PI * mod * 1.0);
var mod = ((GLOBAL_PULSATION ? 0 : p.deltaOffset) + now) % PULSATION_PERIOD / PULSATION_PERIOD;
mod = Math.sin(mod * Math.PI);
var offset = TREMBLING ? TREMBLING * (-1 + Math.random() * 2) : 0;
var radius = PARTICLE_RADIUS * p.radius;
ctx.fillRect(offset + p.x - mod * radius / 2 | 0, offset + p.y - mod * radius / 2 | 0, radius * mod, radius * mod);
ctx.arc(offset + p.x | 0, offset + p.y | 0, radius * mod, Math.PI * 2, false);
p.x += (p.dx - p.x) / 10;
p.y += (p.dy - p.y) / 10;
function get_destinations() {
for(var i = 0; i < particles.length; i++) {
for(var n = 0; n < positions.length; n++) {
distance[n] = Math.sqrt((pa.x - po.x) * (pa.x - po.x) + (pa.y - po.y) * (pa.y - po.y));
if(distance[n] <= distance[nearest_position]) {
particles[i].dx = positions[nearest_position].x;
particles[i].dy = positions[nearest_position].y;
particles[i].distance = distance[nearest_position];
var po1 = positions[nearest_position];
for(var n = 0; n < positions.length; n++) {
distance = Math.sqrt((po1.x - po2.x) * (po1.x - po2.x) + (po1.y - po2.y) * (po1.y - po2.y));
setInterval(draw, 16.67);
setInterval(new_positions, 2000);
document.getElementById("globalPulsation").addEventListener("change", function() {
case 0: GLOBAL_PULSATION = false; break;
case 1: GLOBAL_PULSATION = true; break;
document.getElementById("effect").addEventListener("change", function() {
case 0: BLUR = false; BLINK = false; break;
case 1: BLUR = true; BLINK = false; break;
case 2: BLUR = false; BLINK = true; break;
case 3: BLUR = true; TREMBLING = 5; break;
document.getElementById("pulsationSpeed").addEventListener("change", function() {
PULSATION_PERIOD = this.value;
document.getElementById("particleRadius").addEventListener("change", function() {
PARTICLE_RADIUS = this.value;
document.getElementById("shape").addEventListener("change", function() {
ARC = !parseInt(this.value);
document.getElementById("blending").addEventListener("change", function() {
BLENDING = parseInt(this.value);
document.getElementById("link").addEventListener("click", function() {
for(var i = 0; i < ENCODE_DATA.length; i++) {
var key = ENCODE_DATA[i];
if(typeof val !== "string") val = val | 0;
else val = encodeURIComponent(val);
var link = "http://cssdeck.com/labs/full/db2o5oej/0/noframe/?options=" + data.join("__");
prompt("your link", link);
var temp = GET['options'].split("__");
for(var i = 0; i < ENCODE_DATA.length * 2; i += 2) {
if(typeof window[temp[i]] !== "string") val = parseInt(val);
else val = decodeURIComponent(val);
document.getElementById("gui").style.display = "none";
document.getElementById("text").addEventListener("click", function() {
TEXT = prompt("Enter new text", TEXT);