-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
69 lines (55 loc) · 1.83 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Kasey Eljoundi">
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/p5.min.js"></script>
<script src="graph_obj.js"></script>
<script src="node_obj.js"></script>
<script>
var graph;
var drawn;
function setup() {
var nodeSize = 20;
var nodePadding = 100;
var nodeCount = 15;
var nodeConnections = 2;
createCanvas(windowWidth, windowHeight);
background(200);
textAlign(CENTER);
graph = new Graph(nodeCount, nodeConnections, 40, nodePadding);
if(drawn = graph.positionNodes()){
graph.makeConnections();
}else{
text("graph could not be rendered, check parameters", width/2, height/2);
}
}
function draw() {
background(200);
if(drawn)
graph.render();
}
function mousePressed() {
//index of pressed node
var pressed = -1;
//for each node in graph
for(var i=0; i<graph.nodes.length; i++){
//reset fill color
graph.nodes[i].unclick();
//if dist between mouse and a node is less than radius
// then we have clicked on that node
if( dist(graph.nodes[i].x,graph.nodes[i].y,mouseX,mouseY) < graph.nodeSize ){
pressed = i;
}
}
//fire click event for Node
if(pressed >= 0)
graph.nodes[pressed].click();
}
</script>
</head>
<body>
</body>
</html>