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.

50 lignes
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. };