Преглед на файлове

added repulsion between centered node to keep theme moving
removed also colliding but have to find a way to smoothly slow down theme near center

Bachir Soussi Chiadmi преди 6 години
родител
ревизия
0d8c1f3913

+ 50 - 4
sites/all/modules/figli/edlp_corpus/assets/dist/scripts/corpus.min.js

@@ -39,6 +39,9 @@
     var _no_articles_nodes = [];
     var _nodes_by_entries = {};
     var _nodes_by_nid = {};
+    var _nodes_centered = [];
+    var _nodes_centered_attractions = [];
+
 
     // var _particules = [];
     // var _base_radius = 3; // nodes radius (real radius, not diametre)
@@ -200,6 +203,8 @@
       console.log('_articles_nodes',_articles_nodes);
       console.log('_no_articles_nodes',_no_articles_nodes);
       console.log('_nodes_by_entries', _nodes_by_entries);
+
+      console.log('_physics.attractions.length', _physics.attractions.length);
     };
 
     function Node(i,node,d){
@@ -250,6 +255,8 @@
       this.aside = false;
       this.scrambling = false;
 
+      this.n_repulses = {};
+
       // prototypes
       if (typeof Node.initialized == "undefined") {
 
@@ -411,14 +418,14 @@
 
         Node.prototype.setAside = function(){
           this.aside = true;
-          this.fade();
+          // this.fade();
           this.stopScrambling();
           this.unsetCentered();
           this.repulse_center.on = true;
         }
         Node.prototype.unsetAside = function(){
           this.aside = false;
-          this.unFade();
+          // this.unFade();
           this.repulse_center.on = false;
         }
 
@@ -475,21 +482,32 @@
     // TODO: we may convert a lot of computation into a web worker https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
     function checkParticulesCollisions(){
       // pre create vars to save memory;
-      var d, full_rad,
+      var d, full_rad, margin,
           newVelX1, newVelY1, newVelX2, newVelY2,
           makeup, angle;
       // colisions between _particules
       for (var n = 0; n < _nodes.length; n++) {
 
+        // avoid colliding for centered nodes
+        if(_nodes[n].center) continue;
+
+        // TODO: find a way to smouthly slow down theme near center 
+
+        // avoid colliding for scrambling nodes
         if(_nodes[n].scrambling) continue;
 
         for (var q = n+1; q < _nodes.length; q++) {
           if(q===n) continue;
 
+
           // avoid impact between center and aside particules
           if((_nodes[n].center && _nodes[q].aside) || (_nodes[n].aside && _nodes[q].center))
             continue;
 
+          // TODO: what if centered nodes are repulsing each other ??
+
+          margin = _nodes[n].center ? 1 : 1;
+
           // avoid impact between two centered particulses that comes to the center
           if(_nodes[n].center && _nodes[q].center){
             if(Math.min(_nodes[n].p.distanceTo(_attracter), _nodes[q].p.distanceTo(_attracter)) > 300){
@@ -499,7 +517,7 @@
 
           d = _nodes[n].p.distanceTo(_nodes[q].p);
 
-          full_rad = _nodes[n].r + _nodes[q].r;
+          full_rad = _nodes[n].r*margin + _nodes[q].r*margin;
 
           // if not colliding skip following
           if(d > full_rad) continue;
@@ -562,13 +580,41 @@
     // | _|| ' \  _| '_/ -_) -_|_-<
     // |___|_||_\__|_| \___\___/__/
     function filterEntree(t){
+      _nodes_centered = [];
       for (var n = 0; n < _nodes.length; n++) {
         if(_nodes[n].entrees.indexOf(t) == -1){
           _nodes[n].setAside();
         }else{
           _nodes[n].setCenteredOnEntree(t);
+          _nodes_centered.push(_nodes[n]);
+        }
+      }
+      createNodesRepulsions();
+    };
+
+    function createNodesRepulsions(){
+      // how to delete all these attractions before creates new once
+      console.log('_nodes_centered', _nodes_centered);
+      purgeNodesRepulsions();
+      for (var n = 0; n < _nodes_centered.length; n++) {
+        for (var q = n+1; q < _nodes_centered.length; q++) {
+          _physics.makeAttraction(_nodes_centered[n].p, _nodes_centered[q].p, -0.4, 10);
+        }
+      }
+    };
+
+    function purgeNodesRepulsions(){
+      // console.log('_physics.attractions.length', _physics.attractions.length);
+      for (var a = _physics.attractions.length-1; a >= 0; a--) {
+        // assuming that only nodes repulsions have constant < 1
+        // and are all at the end of array
+        if(Math.abs(_physics.attractions[a].constant) < 1){
+          _physics.attractions.splice(a,1);
+        }else{
+          break;
         }
       }
+      // console.log('_physics.attractions.length', _physics.attractions.length);
     };
 
     function scrambleCollection(){

+ 50 - 4
sites/all/modules/figli/edlp_corpus/assets/scripts/corpus.js

@@ -39,6 +39,9 @@
     var _no_articles_nodes = [];
     var _nodes_by_entries = {};
     var _nodes_by_nid = {};
+    var _nodes_centered = [];
+    var _nodes_centered_attractions = [];
+
 
     // var _particules = [];
     // var _base_radius = 3; // nodes radius (real radius, not diametre)
@@ -200,6 +203,8 @@
       console.log('_articles_nodes',_articles_nodes);
       console.log('_no_articles_nodes',_no_articles_nodes);
       console.log('_nodes_by_entries', _nodes_by_entries);
+
+      console.log('_physics.attractions.length', _physics.attractions.length);
     };
 
     function Node(i,node,d){
@@ -250,6 +255,8 @@
       this.aside = false;
       this.scrambling = false;
 
+      this.n_repulses = {};
+
       // prototypes
       if (typeof Node.initialized == "undefined") {
 
@@ -411,14 +418,14 @@
 
         Node.prototype.setAside = function(){
           this.aside = true;
-          this.fade();
+          // this.fade();
           this.stopScrambling();
           this.unsetCentered();
           this.repulse_center.on = true;
         }
         Node.prototype.unsetAside = function(){
           this.aside = false;
-          this.unFade();
+          // this.unFade();
           this.repulse_center.on = false;
         }
 
@@ -475,21 +482,32 @@
     // TODO: we may convert a lot of computation into a web worker https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
     function checkParticulesCollisions(){
       // pre create vars to save memory;
-      var d, full_rad,
+      var d, full_rad, margin,
           newVelX1, newVelY1, newVelX2, newVelY2,
           makeup, angle;
       // colisions between _particules
       for (var n = 0; n < _nodes.length; n++) {
 
+        // avoid colliding for centered nodes
+        if(_nodes[n].center) continue;
+
+        // TODO: find a way to smouthly slow down theme near center 
+
+        // avoid colliding for scrambling nodes
         if(_nodes[n].scrambling) continue;
 
         for (var q = n+1; q < _nodes.length; q++) {
           if(q===n) continue;
 
+
           // avoid impact between center and aside particules
           if((_nodes[n].center && _nodes[q].aside) || (_nodes[n].aside && _nodes[q].center))
             continue;
 
+          // TODO: what if centered nodes are repulsing each other ??
+
+          margin = _nodes[n].center ? 1 : 1;
+
           // avoid impact between two centered particulses that comes to the center
           if(_nodes[n].center && _nodes[q].center){
             if(Math.min(_nodes[n].p.distanceTo(_attracter), _nodes[q].p.distanceTo(_attracter)) > 300){
@@ -499,7 +517,7 @@
 
           d = _nodes[n].p.distanceTo(_nodes[q].p);
 
-          full_rad = _nodes[n].r + _nodes[q].r;
+          full_rad = _nodes[n].r*margin + _nodes[q].r*margin;
 
           // if not colliding skip following
           if(d > full_rad) continue;
@@ -562,13 +580,41 @@
     // | _|| ' \  _| '_/ -_) -_|_-<
     // |___|_||_\__|_| \___\___/__/
     function filterEntree(t){
+      _nodes_centered = [];
       for (var n = 0; n < _nodes.length; n++) {
         if(_nodes[n].entrees.indexOf(t) == -1){
           _nodes[n].setAside();
         }else{
           _nodes[n].setCenteredOnEntree(t);
+          _nodes_centered.push(_nodes[n]);
+        }
+      }
+      createNodesRepulsions();
+    };
+
+    function createNodesRepulsions(){
+      // how to delete all these attractions before creates new once
+      console.log('_nodes_centered', _nodes_centered);
+      purgeNodesRepulsions();
+      for (var n = 0; n < _nodes_centered.length; n++) {
+        for (var q = n+1; q < _nodes_centered.length; q++) {
+          _physics.makeAttraction(_nodes_centered[n].p, _nodes_centered[q].p, -0.4, 10);
+        }
+      }
+    };
+
+    function purgeNodesRepulsions(){
+      // console.log('_physics.attractions.length', _physics.attractions.length);
+      for (var a = _physics.attractions.length-1; a >= 0; a--) {
+        // assuming that only nodes repulsions have constant < 1
+        // and are all at the end of array
+        if(Math.abs(_physics.attractions[a].constant) < 1){
+          _physics.attractions.splice(a,1);
+        }else{
+          break;
         }
       }
+      // console.log('_physics.attractions.length', _physics.attractions.length);
     };
 
     function scrambleCollection(){