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.

poll.js 1.5KB

il y a 8 ans
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. var body;
  2. function poll() {
  3. var xhr = new XMLHttpRequest();
  4. xhr.onload = function() {
  5. var state = JSON.parse(xhr.responseText);
  6. updateScene(state);
  7. };
  8. xhr.onerror = function(e){
  9. //soft_console.innerHTML = "\n" + "Lost connection to server";
  10. };
  11. xhr.open("GET", "/state", true);
  12. xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
  13. xhr.send();
  14. }
  15. function updateScene(state) {
  16. var oldState = scene.getObjectByName("graphstate");
  17. scene.remove(oldState);
  18. oldState = null;
  19. var geometry = new THREE.Geometry();
  20. //nodeGeometry.labels = [];
  21. //nodeGeometry.colors = [];
  22. for (var i in state.vops) {
  23. var vop = state.vops[i];
  24. var pos = state.meta[i].pos;
  25. var vertex = new THREE.Vector3(pos.x, pos.y, pos.z);
  26. geometry.vertices.push(vertex);
  27. //geometry.colors[i] = new THREE.Color(n.color);
  28. //geometry.labels[i] = n.label;
  29. }
  30. var edges = new THREE.Object3D();
  31. for (i=0; i < state.edge.length; ++i) {
  32. var edge = state.edge[i];
  33. var start = state.meta[edge[0]].pos;
  34. var end = state.meta[edge[1]].pos;
  35. var newEdge = makeEdge(start, end);
  36. edges.add(newEdge);
  37. }
  38. var particles = new THREE.Points(geometry, materials.qubit);
  39. var newState = new THREE.Object3D();
  40. newState.name = "graphstate";
  41. newState.add(particles);
  42. newState.add(edges);
  43. scene.add(newState);
  44. render();
  45. }