-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodes.js
More file actions
96 lines (79 loc) · 2.51 KB
/
nodes.js
File metadata and controls
96 lines (79 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var centre = new Point(0, 0);
function randomisePositions()
{
for(let a=0; a < nodes.length; a++)
{
nodes[a].location.x=randomMinMax(-200,200);
nodes[a].location.y=randomMinMax(-200,200);
}
draw();
reposition();
loopAnimate();
}
function createChildNode(sourceNode)
{
let point;
if(sourceNode==-1)
point = new Point(0, 0);
else
{
point = new Point (randomMinMax(-50, 50), randomMinMax(-50, 50) );
point.alterPosition(nodes[sourceNode]); // alter new point based on where its source is
}
nodes.push(new Node(nodes.length, point, new Vector(0,0), "", "true")); // is a child node
if(sourceNode>=0)
edges.push(new Edge(sourceNode, nodes.length -1 ));
return ;
}
function deleteNode(node)
{
// nodes.splice(node, 1); - this means the edges will have to be updated with a new sources & targets!
nodes[node].visibility = "false";
a = edges.length;
while (a--)
{
if( (edges[a].source == node || edges[a].target == node))
{
console.log("edge: " + edges[a].source + "-" + edges[a].target +" deleted");
edges.splice(a, 1);
}
}
}
function searchDeleteEdges(u,v)
{
for(a=0;a<edges.length;a++)
{
if( (edges[a].source == u && edges[a].target == v) || (edges[a].source == v && edges[a].target == u))
{
edges.splice(a, 1);
console.log("edge " + u + "-" + v +" deleted");
return true;
}
}
return false;
}
function connectTheNodes(n1, n2)
{
edges.push(new Edge(n1, n2));
}
function createStartNode()
{
createChildNode(-1);
}
function createNetwork()
{
let min = -200, max = 200;
nodes[0] = new Node(0, new Point (0,0), new Vector(0,0), "Fruit");
nodes[1] = new Node(1, new Point (randomMinMax(min, max), randomMinMax(min, max)), new Vector(0,0), "Berried");
nodes[2] = new Node(2, new Point (randomMinMax(min, max), randomMinMax(min, max)), new Vector(0,0), "Citrus");
nodes[3] = new Node(3, new Point (randomMinMax(min, max), randomMinMax(min, max)), new Vector(0,0), "Raspberry");
nodes[4] = new Node(4, new Point (randomMinMax(min, max), randomMinMax(min, max)), new Vector(0,0), "Strawberry");
nodes[5] = new Node(5, new Point (randomMinMax(min, max), randomMinMax(min, max)), new Vector(0,0), "Orange");
nodes[6] = new Node(6, new Point (randomMinMax(min, max), randomMinMax(min, max)), new Vector(0,0), "Lemon");
edges[0] = new Edge(0,1);
edges[1] = new Edge(0,2);
edges[2] = new Edge(1,3);
edges[3] = new Edge(1,4);
edges[4] = new Edge(2,5);
edges[5] = new Edge(2,6);
}