Anders and Briegel in Python
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

51 lines
1.5KB

  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. if (abj.node[i].color !== undefined){
  16. color = abj.node[i].color;
  17. }
  18. geometry.vertices.push(abj.node[i].position);
  19. geometry.colors.push(new THREE.Color(color));
  20. }
  21. var edges = new THREE.Object3D();
  22. var my_edges = abj.edgelist();
  23. for (i = 0; i < my_edges.length; ++i) {
  24. var edge = my_edges[i];
  25. var start = abj.node[edge[0]].position;
  26. var startpos = new THREE.Vector3(start.x, start.y, start.z);
  27. var end = abj.node[edge[1]].position;
  28. var endpos = new THREE.Vector3(end.x, end.y, end.z);
  29. var newEdge = materials.makeCurve(startpos, endpos);
  30. edges.add(newEdge);
  31. }
  32. var particles = new THREE.Points(geometry, materials.qubit);
  33. graph.object = new THREE.Object3D();
  34. graph.object.name = "graphstate";
  35. graph.object.add(particles);
  36. graph.object.add(edges);
  37. gui.scene.add(graph.object);
  38. gui.render();
  39. };
  40. graph.test = function(command) {
  41. //Act the command
  42. //Send it back to the server, ultimately thru to python
  43. };