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.

8 anni fa
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. var graph = {};
  2. graph.colors = ["red", "green", "yellow", "green", "pink", "orange", "purple"];
  3. graph.prepare = function() {
  4. materials.prepare();
  5. websocket.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. var particles = new THREE.Points(geometry, materials.qubit);
  43. var object = new THREE.Object3D();
  44. object.name = "graphstate";
  45. object.add(particles);
  46. object.add(edges);
  47. gui.scene.add(object);
  48. gui.render();
  49. };