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.

44 line
1.3KB

  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.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.node) {
  14. var color = graph.colors[abj.node[i].vop % graph.colors.length];
  15. geometry.vertices.push(abj.node[i].position);
  16. geometry.colors.push(new THREE.Color(color));
  17. }
  18. var edges = new THREE.Object3D();
  19. var my_edges = abj.edgelist();
  20. for (i = 0; i < my_edges.length; ++i) {
  21. var edge = my_edges[i];
  22. var start = abj.node[edge[0]].position;
  23. var startpos = new THREE.Vector3(start.x, start.y, start.z);
  24. var end = abj.node[edge[1]].position;
  25. var endpos = new THREE.Vector3(end.x, end.y, end.z);
  26. var newEdge = materials.makeCurve(startpos, endpos);
  27. edges.add(newEdge);
  28. }
  29. var particles = new THREE.Points(geometry, materials.qubit);
  30. graph.object = new THREE.Object3D();
  31. graph.object.name = "graphstate";
  32. graph.object.add(particles);
  33. graph.object.add(edges);
  34. gui.scene.add(graph.object);
  35. gui.render();
  36. };