From c82fb7318957aa1f57d448ae55ef7a08881751d7 Mon Sep 17 00:00:00 2001 From: hikarupsp Date: Sun, 2 Feb 2014 16:10:29 +0900 Subject: [PATCH] =?utf8?q?=E3=82=B0=E3=83=A9=E3=83=95=E8=87=AA=E5=8B=95?= =?utf8?q?=E8=BF=BD=E5=B0=BE=E6=A9=9F=E8=83=BD=E3=82=92=E8=BF=BD=E5=8A=A0?= =?utf8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- mgcanvas/index.html | 27 ++++++++++++++++++++++ mgcanvas/mgcanvas.js | 64 ++++++++++++++++++++++++---------------------------- 2 files changed, 56 insertions(+), 35 deletions(-) mode change 100644 => 100755 mgcanvas/index.html mode change 100644 => 100755 mgcanvas/mgcanvas.js diff --git a/mgcanvas/index.html b/mgcanvas/index.html old mode 100644 new mode 100755 index 16e9d19..89a4a8c --- a/mgcanvas/index.html +++ b/mgcanvas/index.html @@ -102,6 +102,33 @@ onload = function() { ["G", "J"], ]]); + /* + mgmain.setGraph([[ + "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O", + ],[ + ["A", "B"], + ["A", "C"], + ["A", "D"], + ["A", "E"], + // + ["B", "F"], + ["B", "G"], + // + ["C", "H"], + ["C", "I"], + // + ["D", "J"], + ["D", "K"], + // + ["E", "L"], + ["E", "M"], + // + ["A", "N"], + // + ["M", "O"], + ]]); + */ + } diff --git a/mgcanvas/mgcanvas.js b/mgcanvas/mgcanvas.js old mode 100644 new mode 100755 index 36e6541..c91093b --- a/mgcanvas/mgcanvas.js +++ b/mgcanvas/mgcanvas.js @@ -24,9 +24,6 @@ function MGCanvas(canvasDOMObj){ //console.log("x:" + loc.x); //console.log("y:" + loc.y); }; - //ファイルの入力を受け付ける場合はコメントを外す - //this.canvas.addEventListener('dragover', function(evt){ return that.handleDragOver(evt); }, false); - //this.canvas.addEventListener('drop', function(evt){ return that.handleFileSelect(evt); }, false); } MGCanvas.prototype = { setGraph: function(gArray){ @@ -59,6 +56,27 @@ MGCanvas.prototype = { p[i].position.y -= g.y; } }, + bringInScreen: function(){ + //大きく外れていないときには動かさない + var g = new Point2D(0, 0); + var p; + p = this.nodeList; + for(var i = 0, iLen = p.length; i < iLen; i++){ + g.x += p[i].position.x; + g.y += p[i].position.y; + } + g.x /= p.length; + g.y /= p.length; + if( g.x < this.displayRect.origin.x / 2 || + g.x > -this.displayRect.origin.x / 2 || + g.y < this.displayRect.origin.y / 2 || + g.y > -this.displayRect.origin.x / 2){ + for(var i = 0, iLen = p.length; i < iLen; i++){ + p[i].position.x -= g.x; + p[i].position.y -= g.y; + } + } + }, tick: function(){ var p; var t; @@ -69,10 +87,14 @@ MGCanvas.prototype = { this.tickCount++; //console.log(this.tickCount); + if(this.tickCount % 30 == 0){ + this.bringInScreen(); + } // // Check // + p = this.nodeList; for(var i = 0, iLen = p.length; i < iLen; i++){ nTemp = this.getVectorLength(p[i].vector); @@ -85,6 +107,7 @@ MGCanvas.prototype = { n.ignoreEdgeRepulsion = 10; } + // // Move // @@ -250,35 +273,6 @@ MGCanvas.prototype = { this.context.translate(w, h); this.displayRect = new Rectangle(-w, -h, this.canvas.width, this.canvas.height); }, - loadAIMemory: function(str){ - console.log(str); - }, - // http://www.html5rocks.com/ja/tutorials/file/dndfiles/ - handleFileSelect: function(evt){ - evt.stopPropagation(); - evt.preventDefault(); - - var files = evt.dataTransfer.files; // FileList object. - var that = this; - - // files is a FileList of File objects. List some properties. - var output = []; - for(var i = 0, f; f = files[i]; i++){ - var r = new FileReader(); - r.onload = (function(file){ - return function(e){ - //mainAI.sendTextFromFileToAI(r.result, file.name, file.lastModifiedDate, "File"); - that.loadAIMemory(r.result); - } - })(f); - r.readAsText(f); - } - }, - handleDragOver: function(evt){ - evt.stopPropagation(); - evt.preventDefault(); - evt.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy. - }, } function MGNode(env, identifier){ @@ -288,9 +282,9 @@ function MGNode(env, identifier){ this.size = 10; //ランダムな初期ベクトルをもつ。 this.vector = new Point2D(Math.random() * 2 - 1, Math.random() * 2 - 1); - this.friction = (100 - 7) / 100; - this.repulsionLengthNode = 100; - this.repulsionLengthEdge = 75; + this.friction = (100 - 8) / 100; + this.repulsionLengthNode = 90; + this.repulsionLengthEdge = 90; this.ignoreEdgeRepulsion = 0; } MGNode.prototype = { -- 2.11.0