summaryrefslogtreecommitdiff
path: root/generate_graph.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2015-11-19 17:07:55 +0100
committeremkael <emkael@tlen.pl>2015-11-19 17:07:55 +0100
commit2149b9150157c59685d7cf0b888a437ebacf9bae (patch)
tree9c0b193f4eb8eaf9fa273a17fe7f11cf8c6abc3a /generate_graph.py
parent100c4bac8636aa112596b5b2afe49164f1782625 (diff)
* fancy graph generator
Diffstat (limited to 'generate_graph.py')
-rw-r--r--generate_graph.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/generate_graph.py b/generate_graph.py
new file mode 100644
index 0000000..7fb44f9
--- /dev/null
+++ b/generate_graph.py
@@ -0,0 +1,78 @@
+import sys, json, random
+from math import ceil, pi, sin, cos
+
+sizes = [1.0, 0.9, 0.8, 0.7, 0.3, 0.2, 0.1]
+counts = sys.argv[1:8]
+
+base_size = 200
+mass_quotient = float(sys.argv[8])
+size_quotient = float(sys.argv[9])
+subnode_threshold = float(sys.argv[10])
+
+nodes = {}
+
+nodes['n0'] = {'width': base_size, 'height': base_size, 'color': 'white', 'mass': base_size, 'fixed': True, 'x': 0, 'y': 0}
+node_count = 1
+
+node_sizes = []
+for i in counts:
+ node_sizes = node_sizes + [sizes.pop(0)] * int(i)
+
+node_images = {
+ 1.0: 'blue.png',
+ 0.9: 'blue.png',
+ 0.8: 'blue.png',
+ 0.7: 'blue.png',
+ 0.3: 'red.png',
+ 0.2: 'yellow.png',
+ 0.1: 'black.png'
+}
+node_colors = {
+ 1.0: '#3495FF',
+ 0.9: '#3495FF',
+ 0.8: '#3495FF',
+ 0.7: '#3495FF',
+ 0.3: 'red',
+ 0.2: 'yellow',
+ 0.1: 'white'
+}
+
+angular_positions = [2 * pi / len(node_sizes) * (n - 1) for n in range(1, len(node_sizes)+1)]
+random.shuffle(angular_positions)
+
+edges = {}
+edges['n0'] = {}
+for node_size in node_sizes:
+ node_id = 'n' + str(node_count)
+ node_dimension = max(10, int(ceil(base_size * node_size * size_quotient)))
+ node_mass = int(ceil(base_size * mass_quotient))
+ node_angular_position = angular_positions[node_count-1]
+ node_position = { 'x': 0.05 * cos(node_angular_position),
+ 'y': 0.05 * sin(node_angular_position) }
+ nodes[node_id] = {'width': node_dimension, 'height': node_dimension, 'mass': node_mass, 'color': node_colors[node_size], 'fixed': True, 'x': node_position['x'], 'y': node_position['y']}
+ edges['n0'][node_id] = {}
+ edges[node_id] = {}
+ node_count += 1
+ subnode_count = 1
+ subnode_sizes = [n for n in node_sizes if (node_size > 0.2) and (random.random() > subnode_threshold)]
+ for subnode_size in subnode_sizes:
+ subnode_id = node_id + '_' + str(subnode_count)
+ subnode_dimension = max(5, int(ceil(base_size * node_size * subnode_size * size_quotient * size_quotient)))
+ subnode_mass = int(ceil(base_size * mass_quotient))
+ nodes[subnode_id] = {'width': subnode_dimension, 'height': subnode_dimension, 'mass': subnode_mass, 'color': node_colors[subnode_size], 'fixed': True, 'x': node_position['x'], 'y': node_position['y']}
+ edges[node_id][subnode_id] = {}
+ subnode_count += 1
+
+print json.dumps(
+ {
+ 'repulsion': 1000,
+ 'stiffness': 100,
+ 'friction': 100,
+ 'precision': 0.99,
+ 'fps': 40,
+ 'dt': 0.05,
+ 'gravity': True,
+ 'nodes': nodes,
+ 'edges': edges
+ }
+)