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.

60 lines
1.7KB

  1. function poll() {
  2. var ws = new WebSocket("ws://localhost:5000/echo");
  3. ws.onopen = function()
  4. {
  5. // Web Socket is connected, send data using send()
  6. ws.send("Hello from the browser! I connected okay");
  7. console.log("Sent a message to the server");
  8. };
  9. ws.onmessage = function (evt)
  10. {
  11. var received_msg = evt.data;
  12. console.log("I got a message from the server:");
  13. console.log(evt.data);
  14. };
  15. ws.onclose = function()
  16. {
  17. ws.send("Bye by from the browser");
  18. console.log("Connection is closed...");
  19. };
  20. }
  21. function updateScene(state) {
  22. if (state.needs_update === false){return;}
  23. var oldState = scene.getObjectByName("graphstate");
  24. scene.remove(oldState);
  25. oldState = null;
  26. var geometry = new THREE.Geometry();
  27. //nodeGeometry.labels = [];
  28. //nodeGeometry.colors = [];
  29. for (var i in state.nodes) {
  30. var node = state.nodes[i];
  31. var pos = state.meta[i].pos;
  32. var vertex = new THREE.Vector3(pos.x, pos.y, pos.z);
  33. geometry.vertices.push(vertex);
  34. //geometry.colors[i] = new THREE.Color(n.color);
  35. //geometry.labels[i] = n.label;
  36. }
  37. var edges = new THREE.Object3D();
  38. for (i=0; i < state.edges.length; ++i) {
  39. var edge = state.edges[i];
  40. var start = state.meta[edge[0]].pos;
  41. var end = state.meta[edge[1]].pos;
  42. var newEdge = makeEdge(start, end);
  43. edges.add(newEdge);
  44. }
  45. var particles = new THREE.Points(geometry, materials.qubit);
  46. var newState = new THREE.Object3D();
  47. newState.name = "graphstate";
  48. newState.add(particles);
  49. newState.add(edges);
  50. scene.add(newState);
  51. render();
  52. }