xonecas.io
142
St

startsInvasion / files

startsInvasion / js / script.js

2.4 KB
1
2!function (window) {
3
4   var scene, camera, renderer, particle, mousex, mousey, 
5      count     = 0,
6      particles = [],
7      width     = window.innerWidth,
8      height    = window.innerHeight,
9      sep       = 150,
10      amountx   = 50,
11      amounty   = 50;
12
13   $.domReady(function () {
14
15      scene = new THREE.Scene();
16
17
18      camera = new THREE.Camera(75, width / height, 1, 10000);
19      camera.position.z = 1000;
20      camera.position.y = 400;
21      camera.position.x = 1000;
22
23      var material =  new THREE.ParticleCanvasMaterial({
24         color: 0xffffff,
25         program: function (ctx) {
26            ctx.beginPath();
27            ctx.moveTo(0, -15);
28            ctx.lineTo(60, -15); // right
29            ctx.lineTo(0, -60); // left bottom
30            ctx.lineTo(30, -0); // top
31            ctx.lineTo(60, -60); // right bottom
32            ctx.lineTo(0, -15);
33            ctx.fill();
34         }
35      });
36
37      var i = 0;
38      particles = [];
39      for (var ix = 0; ix < amountx; ix++) {
40         for (var iy = 0; iy < amounty; iy++) {
41            particle = particles[i++] = new THREE.Particle(material);
42            particle.position.x = ix * sep - ((amountx * sep) / 2);
43            particle.position.z = iy * sep - ((amounty * sep) / 2);
44            
45            scene.addObject(particle);
46         }
47      }
48
49
50      renderer = new THREE.CanvasRenderer();
51      renderer.setSize(width -30, height -30);
52      $('body').append(renderer.domElement);
53
54      render();
55
56      $(document).bind('mousemove', move);
57      $(document).bind('click', function (ev) {
58         console.log(camera);
59      });
60   });
61
62   function move (ev) {
63      mousex = ev.clientX - width / 2;
64      mousey = ev.clientY - height / 2;
65   }
66
67
68   function render () {
69      camera.position.x = mousex * 5 * -1;
70      camera.position.y = mousey * 5 * -1;
71
72      var i = 0;
73      for (var ix = 0; ix < amountx; ix++) {
74         for (var iy = 0; iy < amounty; iy++) {
75            particle = particles[i++];
76// taken from the example, I don't get this bit..
77particle.position.y = ( Math.sin( ( ix + count ) * 0.3 ) * 100 ) + ( Math.sin( ( iy + count ) * 0.5 ) * 100 );
78particle.scale.x = particle.scale.y = ( Math.sin( ( ix + count ) * 0.3 ) + 0.2 ) + ( Math.sin( ( iy + count ) * 0.5 ) + 0.2 );
79               
80         }
81      }
82
83      renderer.render(scene, camera);
84      requestAnimationFrame(render);
85      count += 0.1;
86   };
87
88
89} (window, undefined);
90
91
92
93
94
95
96
97
98
99
100