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
il y a 8 ans
il y a 8 ans
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. function poll() {
  2. var xhr = new XMLHttpRequest();
  3. xhr.onload = function() {
  4. var state = JSON.parse(xhr.responseText);
  5. updateScene(state);
  6. };
  7. xhr.onerror = function(e){
  8. //soft_console.innerHTML = "\n" + "Lost connection to server";
  9. };
  10. xhr.open("GET", "/state", true);
  11. xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
  12. xhr.send();
  13. }
  14. function updateScene(state) {
  15. if (state.needs_update === false){return;}
  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.nodes) {
  23. var node = state.nodes[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.edges.length; ++i) {
  32. var edge = state.edges[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. }