Simulate graph states in the browser
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.

graph.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. var graph = {};
  2. graph.colors = ["red", "green"];
  3. graph.prepare = function() {
  4. materials.prepare();
  5. //poller.connect(graph.update);
  6. };
  7. graph.center = function() {
  8. var middle = new THREE.Vector3(0, 0, 0);
  9. for (var i in abj.node) {
  10. middle = middle.add(abj.node[i].position);
  11. }
  12. middle = middle.multiplyScalar(1.0/abj.order());
  13. return middle;
  14. };
  15. graph.update = function(newState) {
  16. if (newState){abj.update(newState);}
  17. var gs = gui.scene.getObjectByName("graphstate");
  18. if (gs){ gui.scene.remove(gs); }
  19. var geometry = new THREE.Geometry();
  20. geometry.colors = [];
  21. for (var i in abj.node) {
  22. var color = graph.colors[abj.node[i].vop % graph.colors.length];
  23. if (abj.node[i].color !== undefined){
  24. color = abj.node[i].color;
  25. }
  26. geometry.vertices.push(abj.node[i].position);
  27. geometry.colors.push(new THREE.Color(color));
  28. }
  29. graph.center();
  30. gui.controls.target.copy(graph.center());
  31. var edges = new THREE.Object3D();
  32. var my_edges = abj.edgelist();
  33. for (i = 0; i < my_edges.length; ++i) {
  34. var edge = my_edges[i];
  35. var start = abj.node[edge[0]].position;
  36. var startpos = new THREE.Vector3(start.x, start.y, start.z);
  37. var end = abj.node[edge[1]].position;
  38. var endpos = new THREE.Vector3(end.x, end.y, end.z);
  39. var newEdge = materials.makeCurve(startpos, endpos);
  40. edges.add(newEdge);
  41. }
  42. if (editor.selection) {
  43. var node = editor.selection;
  44. if (Object.prototype.hasOwnProperty.call(abj.node, node)) {
  45. // Do nothing ...
  46. gui.controls.target.copy(abj.node[node].position);
  47. node_name.innerHTML = "Node " + node;
  48. node_data.className = "visible";
  49. node_vop.innerHTML = "VOP: " + abj.node[node].vop;
  50. } else {
  51. editor.selection = undefined;
  52. node_data.className = "hidden";
  53. }
  54. } else {
  55. node_data.className = "hidden";
  56. }
  57. var particles = new THREE.Points(geometry, materials.qubit);
  58. var object = new THREE.Object3D();
  59. object.name = "graphstate";
  60. object.add(particles);
  61. object.add(edges);
  62. gui.scene.add(object);
  63. gui.render();
  64. };