Anders and Briegel in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

67 lignes
1.9KB

  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. if (graph.object){gui.scene.remove(graph.object);}
  18. graph.object = null;
  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. graph.object = new THREE.Object3D();
  44. graph.object.name = "graphstate";
  45. graph.object.add(particles);
  46. graph.object.add(edges);
  47. gui.scene.add(graph.object);
  48. gui.render();
  49. geometry = null;
  50. edges=null;
  51. particles = null;
  52. graph.object = null;
  53. };
  54. graph.test = function(command) {
  55. //Act the command
  56. //Send it back to the server, ultimately thru to python
  57. };