Anders and Briegel in Python
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

80 satır
2.4KB

  1. var gui = {};
  2. gui.prepare = function() {
  3. gui.renderer = new THREE.WebGLRenderer({
  4. "antialias": true
  5. });
  6. gui.renderer.setSize(window.innerWidth, window.innerHeight);
  7. gui.renderer.setClearColor(0xffffff, 1);
  8. document.querySelector("body").appendChild(gui.renderer.domElement);
  9. window.addEventListener("resize", gui.onWindowResize, false);
  10. gui.makeScene();
  11. gui.camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.3, 1000);
  12. gui.controls = new THREE.OrbitControls(gui.camera);
  13. gui.controls.addEventListener("change", gui.render);
  14. gui.controls.center.set(0, 0, 0);
  15. gui.controls.rotateSpeed = 0.2;
  16. gui.controls.userPanSpeed = 0.3;
  17. gui.camera.position.set(0, 0, 20);
  18. };
  19. // Someone resized the window
  20. gui.onWindowResize = function(evt) {
  21. console.log(gui);
  22. gui.camera.aspect = window.innerWidth / window.innerHeight;
  23. gui.camera.updateProjectionMatrix();
  24. gui.renderer.setSize(window.innerWidth, window.innerHeight);
  25. gui.render();
  26. };
  27. // Render the current frame to the screen
  28. gui.render = function() {
  29. requestAnimationFrame(function() {
  30. gui.renderer.render(gui.scene, gui.camera);
  31. });
  32. };
  33. // Make the extra bits of gui
  34. gui.makeScene = function() {
  35. gui.scene = new THREE.Scene();
  36. var grid = new THREE.GridHelper(10, 1);
  37. grid.rotation.x = Math.PI / 2;
  38. grid.setColors(0xdddddd, 0xeeeeee);
  39. gui.scene.add(grid);
  40. };
  41. // Put an HTML message to the screen
  42. gui.serverMessage = function(msgtext) {
  43. message.innerHTML = msgtext;
  44. message.className = "visible";
  45. };
  46. // Set the position of the info popup
  47. gui.setInfoPosition = function(position){
  48. w = node_info.offsetWidth;
  49. h = node_info.offsetHeight;
  50. node_info.style.left = position.x - w/2 + "px";
  51. node_info.style.top = position.y - h -10 + "px";
  52. node_info.className = "visible";
  53. };
  54. // The main loop
  55. gui.loop = function() {
  56. gui.controls.update();
  57. requestAnimationFrame(gui.loop);
  58. };
  59. // Try to add a qubit at the current mouse position
  60. gui.addQubitAtMouse = function(event) {
  61. this.raycaster.setFromCamera(mouse, camera);
  62. var intersection = this.raycaster.ray.intersectPlane(this.plane);
  63. intersection.x = Math.round(intersection.x);
  64. intersection.y = Math.round(intersection.y);
  65. abj.add_node(Object.keys(vops).length, {
  66. "position": intersection
  67. });
  68. graph.update();
  69. };