Lively Kernel canvas
// this script is evaluated on world load
200 50 15010function(firstMorph, secondMorph) {
var connectors = firstMorph.connectorMorphs;
if (!connectors)
return false;
for (var i=0; i < connectors.length; i++) {
var connector = connectors[i];
if (!connector) continue;
var start = connector.startMorph;
var end = connector.endMorph;
if (start === firstMorph && end === secondMorph)
return true; // forward
if (start === secondMorph && end === firstMorph)
return true; // back
}
return false;
}function(morph) {
if (!morph._cached_node_center)
morph._cached_node_center = morph.getCenter();
return morph._cached_node_center
}function(morph) {
return 0.1;
}function(morph, v) {
morph._cached_node_center = morph._cached_node_center.addPt(v);
}function(morph) {
if (!morph._cached_node_center)
return;
var v = morph._cached_node_center.subPt(morph.getCenter());
morph.moveBy(v);
this.ensureToStayInWorldBounds(morph);
morph._cached_node_center = undefined;
}function(morph, morphs) {
var avg = pt(0,0);
for (var i=0; i < morphs.length; i++) {
var ea = morphs[i];
if (ea === morph)
continue;
var d = this.centerOf(morph).subPt(this.centerOf(ea));
var dist = d.fastR();
var isConnected = this.areConnected(morph, ea);
if (!isConnected && dist > this.maxDist + 150 * this.energy(morph))
continue;
var force = this.forceOfMorph(ea, d, dist, isConnected);
avg = avg.addPt(force);
}
if (avg.eqPt(pt(0,0)))
return avg;
return Point.polar(this.energy(morph)*this.step, avg.theta());
}function(morph, vector, dist, isConnected) {
// effect positive --> push away, negative -> attract
if (dist == 0)
return pt(0,0);
var effect;
if (dist < this.minDist) {
effect = 1;
} else if (isConnected) {
if (dist <= this.maxDist) return pt(0,0);
effect = -1;
} else {
if (dist >= this.maxDist) return pt(0,0);
effect = 1;
}
return vector.fastNormalized().scaleBy(effect);
}function(morph, nodes) {
if (this.energy(morph) <= 0) return;
if (!this.calls) {
this.calls = 1;
}
this.calls++;
var v = this.forceOfMorphs(morph, nodes);
if (!v.x || !v.y ) return;
this.moveMorphBy(morph, v);
}function(morph) {
if (!this.activeBoundsOfWorld) {
// World bounds are sometimes wrong??? Use canvas ...
var canvas = Global.document.getElementById('canvas');
this.activeBoundsOfWorld = pt(canvas.clientWidth,
canvas.clientHeight).subPt(morph.getExtent()).extentAsRectangle();
}
if (!this.activeBoundsOfWorld.containsPoint(morph.getPosition())) {
var pos = this.activeBoundsOfWorld.closestPointToPt(morph.getPosition());
morph.setPosition(pos);
}
}
timeToRun = function(func) {
var time = new Date();
func();
return new Date() - time;
}
allNodes = function() {
return WorldMorph.current().submorphs.select(function(ea){
return ea.isNodeMorph});
}
Global.layoutAllNodes = function() {
nodes = allNodes();
l = new NodeMorphLayouter();
timeToRun(function(){
for (var i=0; i< 100; i++) {
nodes.each(function(ea) {
l.stepMorph(ea, nodes)
})
}
nodes.each(function(ea) {
l.applyMoveCacheToMorph(ea)
})
})
}
LayoutMorphswithForce40false- null
layoutfalsenullnull
null
null-1.2396639426365312nullfalsetrue
null-1.925851001345406nullfalsetrue
null-2.6047013545075393nullfalsetrue
null-1.6565563323500212nullfalsetrue
nulltrue
null-2.9591239187268186nullfalsetrue
Node16- null
Shape16- null
null-1.4063603698425207nullfalsetrue
WorldMorph16- null
Widget16
Wrapper16
WorldMorph16- null
PasteUpMorph16- null
SVGNode16null
Textnulltrue
nulltrue
null0.4636476090008061nullnull
true
nulltrue
nulltrue
nulltrue
aText16- null
null
true
null-1.1902899496825317nullfalsetruenull
true
true
true
10003.631586566095886Wikicontroltrue
Morph16
createLayer("NodeMorphLayer");layerClass(NodeMorphLayer,Morph,{getisNodeMorph(){returntrue},connectedNodes:function(){returnthis.getConnectorMorphs().collect(function(ea){if(this===ea.startMorph)returnea.endMorphelsereturnea.startMorph},this)},isConnectedTo:function(proceed,otherNode){returnthis.connectedNodes().indexOf(otherNode)!=-1;},})
nulltrue19truetruefalsefalsetruetruefalse
false1truefalsetruetruefalse
nullfalsetruenullfalse
Nodesfalsenullfalse
false
false
falsenullfalsefalsenullnullnullnullfalsenull74