Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 line
1.5KB

  1. var graph = {};
  2. graph.colors = ["lightblue", "green", "yellow", "red", "pink", "orange", "purple"];
  3. graph.prepare = function() {
  4. materials.prepare();
  5. websocket.connect(graph.update);
  6. };
  7. graph.update = function(newState) {
  8. if (newState){abj.update(newState);}
  9. if (graph.object){gui.scene.remove(graph.object);}
  10. graph.object = null;
  11. var geometry = new THREE.Geometry();
  12. geometry.colors = [];
  13. for (var i in abj.vops) {
  14. var vop = abj.vops[i];
  15. var pos = abj.meta[i].position;
  16. var vertex = new THREE.Vector3(pos.x, pos.y, pos.z);
  17. geometry.vertices.push(vertex);
  18. geometry.colors.push(new THREE.Color(graph.colors[abj.vops[i] % graph.colors.length]));
  19. }
  20. var edges = new THREE.Object3D();
  21. var my_edges = abj.edgelist();
  22. for (i = 0; i < my_edges.length; ++i) {
  23. var edge = my_edges[i];
  24. var start = abj.meta[edge[0]].position;
  25. var startpos = new THREE.Vector3(start.x, start.y, start.z);
  26. var end = abj.meta[edge[1]].position;
  27. var endpos = new THREE.Vector3(end.x, end.y, end.z);
  28. var newEdge = materials.makeCurve(startpos, endpos);
  29. edges.add(newEdge);
  30. }
  31. var particles = new THREE.Points(geometry, materials.qubit);
  32. graph.object = new THREE.Object3D();
  33. graph.object.name = "graphstate";
  34. graph.object.add(particles);
  35. graph.object.add(edges);
  36. gui.scene.add(graph.object);
  37. gui.render();
  38. };
  39. graph.add_node = function(x, y, z) {
  40. meta = {position: new THREE.Vector3(x, y, z)};
  41. abj.add_node(abj.order(), meta);
  42. };