Ajax Loader
HTML
<div id="gui">
1
<div id="gui">
2
 
3
<label>effect</label>
4
<select id="effect">
5
  <option value=0>none</option>
6
  <option value=1>blur</option>
7
  <option value=2>blink</option>
8
  <option value=3>earthquake</option>
9
</select>
10
 
11
<label>global pulsation</label>
12
<select id="globalPulsation">
13
  <option value=0>no</option>
14
  <option value=1>yes</option>
15
</select>
16
 
17
<label>pulsation speed</label>
18
<select id="pulsationSpeed">
19
  <option value=100>0.1 s</option>
20
  <option value=250>0.25 s</option>
21
  <option value=500 selected>0.5 s</option>
22
  <option value=1000>1 s</option>
23
  <option value=1500>1.5 s</option> 
24
</select>
25
 
26
<label>radius</label>
27
<select id="particleRadius">
28
  <option value=2>2</option>
29
  <option value=5 selected>5</option>
30
  <option value=7>7</option>
31
  <option value=10>10</option>
32
  <option value=15>15</option>  
33
</select>
34
 
35
  <label>shapes</label>
36
  <select id="shape">
37
  <option value=0>circles</option>
38
  <option value=1>rectangles</option>
39
</select>
40
  
41
  <label>blending</label>
42
  <select id="blending">
43
  <option value=1 selected>yes</option>
44
  <option value=0>no</option>
45
</select>
46
  <button id="text">text</button>
47
  <button id="link">link</button>
48
</div>
49
<canvas id="canvas" width="600" height="300"></canvas>
50
 
51
<div class="copy">
52
  &copy; copystuff by <a href="http://rezoner.net">Rezoner</a> and <a href="http://cssdeck.com">Rishabh</a> - <a style="color:#835;" href="http://cssdeck.com/labs/db2o5oej/0">Compose your own effect</a>
53
</div>
54
 
 
CSS
body { background: #003; text-align: center; font-family: "trebuchet ms" }
1
body { background: #003; text-align: center; font-family: "trebuchet ms" }
2
 
3
canvas { left: 50%; position: absolute; top: 50%; margin-top: -150px; margin-left: -300px; }
4
 
5
#gui { background: rgba(0, 60, 60, 0.5); padding: 4px; border-bottom: 1px solid rgba(0, 0, 0, 0.5); }
6
 
7
label { color: #0aa; font-size: 11px; max-width: 60px; display: inline-block; vertical-align:middle } 
8
 
9
select { background: rgba(0, 0, 0, 0.5); color: #0ff; border-radius: 7px; border: 0; padding: 2px; font-size: 13px }
10
 
11
option { background: #012; }
12
 
13
.copy { position: absolute; bottom: 16px; right: 16px; color: #228 }
14
    
15
a { color: #259 }
 
JavaScript
/* 
1
/* 
2
original script by Rishabh
3
additions by Rezoner: blur, pulsation, quality, blinking, arc/rect, trembling, background adjusting
4
*/
5
  
6
/* play with these values */
7
 
8
BLUR = false;
9
 
10
PULSATION = true;
11
PULSATION_PERIOD = 500;
12
PARTICLE_RADIUS = 5;
13
 
14
/* disable blur before using blink */
15
 
16
BLINK = false;
17
 
18
GLOBAL_PULSATION = false;
19
 
20
QUALITY = 2; /* 0 - 5 */
21
 
22
/* set false if you prefer rectangles */
23
ARC = true;
24
 
25
/* trembling + blur = fun */
26
TREMBLING = 0; /* 0 - infinity */
27
 
28
FANCY_FONT = "arial";
29
 
30
BACKGROUND = "#003";
31
 
32
BLENDING = true;
33
 
34
/* if empty the text will be a random number */
35
TEXT = "";
36
 
37
/* ------------------ */
38
 
39
var ENCODE_DATA = ["BLUR", "BLENDING", "GLOBAL_PULSATION", "TEXT", "TREMBLING", "ARC", "PULSATION_PERIOD", "PARTICLE_RADIUS", "PULSATION", "BLINK"];
40
 
41
var GET = {};
42
 
43
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) {
44
  GET[key] = value;
45
});
46
 
47
decodeData();
48
 
49
QUALITY_TO_FONT_SIZE = [10, 20, 50, 100, 200, 350];
50
QUALITY_TO_SCALE = [20, 14, 6, 3, 1.5, 0.9];
51
QUALITY_TO_TEXT_POS = [10, 18, 43, 86, 170, 280];
52
 
53
window.onload = function() {
54
  document.body.style.backgroundColor = BACKGROUND;
55
  
56
  var canvas = document.getElementById("canvas");
57
  var ctx = canvas.getContext("2d");
58
 
59
  var W = canvas.width;
60
  var H = canvas.height;
61
 
62
  var tcanvas = document.createElement("canvas");
63
  var tctx = tcanvas.getContext("2d");
64
  tcanvas.width = W;
65
  tcanvas.height = H;
66
 
67
 
68
  total_area = W * H;
69
  total_particles = 800;
70
  single_particle_area = total_area / total_particles;
71
  area_length = Math.sqrt(single_particle_area);
72
  console.log(area_length);
73
 
74
  var particles = [];
75
  for(var i = 1; i <= total_particles; i++) {
76
    particles.push(new particle(i));
77
  }
78
 
79
  function particle(i) {
80
    this.r = Math.round(Math.random() * 255 | 0);
81
    this.g = Math.round(Math.random() * 255 | 0);
82
    this.b = Math.round(Math.random() * 255 | 0);
83
    this.alpha = 1;
84
 
85
    this.x = (i * area_length) % W;
86
    this.y = (i * area_length) / W * area_length;
87
 
88
 
89
    /* randomize delta to make particles sparkling */
90
    this.deltaOffset = Math.random() * PULSATION_PERIOD | 0;
91
 
92
    this.radius = 0.1 + Math.random() * 2;
93
  }
94
 
95
  var positions = [];
96
 
97
  function new_positions() {
98
    tctx.fillStyle = "white";
99
    tctx.fillRect(0, 0, W, H)
100
    tctx.fill();
101
 
102
    tctx.font = "bold " + QUALITY_TO_FONT_SIZE[QUALITY] + "px " + FANCY_FONT;
103
    var text = TEXT || String(Math.random()).substr(-3);
104
 
105
    tctx.strokeStyle = "black";
106
    tctx.strokeText(text, (QUALITY + 1) * 5, QUALITY_TO_TEXT_POS[QUALITY]);
107
 
108
    image_data = tctx.getImageData(0, 0, W, H);
109
    pixels = image_data.data;
110
    positions = [];
111
    for(var i = 0; i < pixels.length; i = i + 4) {
112
      if(pixels[i] != 255) {
113
        position = {
114
          x: (i / 4 % W | 0) * QUALITY_TO_SCALE[QUALITY] | 0,
115
          y: (i / 4 / W | 0) * QUALITY_TO_SCALE[QUALITY] | 0
116
        }
117
        positions.push(position);
118
      }
119
    }   
120
 
121
    get_destinations();
122
  }
123
 
124
  function draw() {
125
 
126
    var now = Date.now();
127
 
128
    ctx.globalCompositeOperation = "source-over";
129
    
130
    if(BLUR) ctx.globalAlpha = 0.1;
131
    else if(!BLUR && !BLINK) ctx.globalAlpha = 1.0;
132
    
133
    ctx.fillStyle = BACKGROUND;
134
    ctx.fillRect(0, 0, W, H)
135
 
136
    if(BLENDING) ctx.globalCompositeOperation = "lighter";
137
 
138
    for(var i = 0; i < particles.length; i++) {
139
      p = particles[i];
140
 
141
      /* in lower qualities there is not enough full pixels for all of  them - dirty hack*/
142
 
143
      if(isNaN(p.x)) continue
144
 
145
      ctx.beginPath();
146
      ctx.fillStyle = "rgb(" + p.r + ", " + p.g + ", " + p.b + ")";
147
      ctx.fillStyle = "rgba(" + p.r + ", " + p.g + ", " + p.b + ", " + p.alpha + ")";
148
 
149
 
150
      if(BLINK) ctx.globalAlpha = Math.sin(Math.PI * mod * 1.0);
151
 
152
      if(PULSATION) { /* this would be 0 -> 1 */
153
        var mod = ((GLOBAL_PULSATION ? 0 : p.deltaOffset) + now) % PULSATION_PERIOD / PULSATION_PERIOD;
154
 
155
        /* lets make the value bouncing with sinus */
156
        mod = Math.sin(mod * Math.PI);
157
      } else var mod = 1;
158
 
159
      var offset = TREMBLING ? TREMBLING * (-1 + Math.random() * 2) : 0;
160
      
161
      var radius = PARTICLE_RADIUS * p.radius;
162
 
163
      if(!ARC) {
164
        ctx.fillRect(offset + p.x - mod * radius / 2 | 0, offset + p.y - mod * radius / 2 | 0, radius * mod, radius * mod);
165
      } else {
166
        ctx.arc(offset + p.x | 0, offset + p.y | 0, radius * mod, Math.PI * 2, false);
167
        ctx.fill();
168
      }
169
 
170
 
171
 
172
      p.x += (p.dx - p.x) / 10;
173
      p.y += (p.dy - p.y) / 10;
174
    }
175
  }
176
 
177
  function get_destinations() {
178
    for(var i = 0; i < particles.length; i++) {
179
      pa = particles[i];
180
      particles[i].alpha = 1;
181
      var distance = [];
182
      nearest_position = 0;
183
      if(positions.length) {
184
        for(var n = 0; n < positions.length; n++) {
185
          po = positions[n];
186
          distance[n] = Math.sqrt((pa.x - po.x) * (pa.x - po.x) + (pa.y - po.y) * (pa.y - po.y));
187
          if(n > 0) {
188
            if(distance[n] <= distance[nearest_position]) {
189
              nearest_position = n;
190
            }
191
          }
192
        }
193
        particles[i].dx = positions[nearest_position].x;
194
        particles[i].dy = positions[nearest_position].y;
195
        particles[i].distance = distance[nearest_position];
196
 
197
        var po1 = positions[nearest_position];
198
        for(var n = 0; n < positions.length; n++) {
199
          var po2 = positions[n];
200
          distance = Math.sqrt((po1.x - po2.x) * (po1.x - po2.x) + (po1.y - po2.y) * (po1.y - po2.y));
201
          if(distance <= 5) {
202
            positions.splice(n, 1);
203
          }
204
        }
205
      } else {
206
        //particles[i].alpha = 0;
207
      }
208
    }
209
  }
210
 
211
  function init() {
212
    new_positions();
213
    setInterval(draw, 16.67);
214
    setInterval(new_positions, 2000);
215
  }
216
 
217
  init();
218
}
219
  
220
/* GUI */
221
  
222
 
223
  document.getElementById("globalPulsation").addEventListener("change", function() {    
224
    switch(this.value | 0) {
225
      case 0: GLOBAL_PULSATION = false; break;
226
      case 1: GLOBAL_PULSATION = true; break;     
227
    }       
228
  });
229
        
230
        
231
  document.getElementById("effect").addEventListener("change", function() {   
232
    TREMBLING = 0;
233
    switch(this.value | 0) {
234
      case 0: BLUR = false; BLINK = false; break;
235
      case 1: BLUR = true; BLINK = false; break;
236
      case 2: BLUR = false; BLINK = true; break;
237
      case 3: BLUR = true; TREMBLING = 5; break;
238
    }       
239
  });
240
  
241
    document.getElementById("pulsationSpeed").addEventListener("change", function() {   
242
    PULSATION_PERIOD = this.value;    
243
  });
244
        
245
    document.getElementById("particleRadius").addEventListener("change", function() {   
246
    PARTICLE_RADIUS = this.value; 
247
  });
248
  
249
    document.getElementById("shape").addEventListener("change", function() {    
250
    ARC = !parseInt(this.value);  
251
  });
252
  
253
  
254
      document.getElementById("blending").addEventListener("change", function() {   
255
    BLENDING = parseInt(this.value);  
256
  });
257
 
258
 
259
 
260
document.getElementById("link").addEventListener("click", function() {
261
  var data = [ ];
262
  for(var i = 0; i < ENCODE_DATA.length; i++) {
263
    var key = ENCODE_DATA[i];
264
    var val = window[key];
265
    if(typeof val !== "string") val = val | 0;
266
    else val = encodeURIComponent(val);
267
    data.push(key, val);
268
  }
269
  
270
  var link = "http://cssdeck.com/labs/full/db2o5oej/0/noframe/?options=" + data.join("__");
271
  
272
  prompt("your link", link);
273
});
274
  
275
function decodeData() {
276
  if(GET['options']) {  
277
    var temp = GET['options'].split("__");
278
    for(var i = 0; i < ENCODE_DATA.length * 2; i += 2) {
279
      var val = temp[i + 1];  
280
      if(typeof window[temp[i]] !== "string") val = parseInt(val);
281
      else val = decodeURIComponent(val);
282
      window[temp[i]] = val;    
283
    }
284
    document.getElementById("gui").style.display = "none";
285
  } 
286
}
287
  
288
  document.getElementById("text").addEventListener("click", function() {
289
  TEXT = prompt("Enter new text", TEXT);
290
  });
291
  
 

HTML5 Canvas Text Particles Effect - remixed

CSSDeck G+