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.

graph.js 1.9KB

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