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.

150 lignes
4.2KB

  1. var editor = {};
  2. var pi2 = Math.PI / 2;
  3. editor.selection = undefined;
  4. editor.mouseOver = undefined;
  5. editor.orientations = [
  6. new THREE.Euler(pi2, 0, 0),
  7. new THREE.Euler(0, 0, 0),
  8. new THREE.Euler(pi2, 0, pi2),
  9. ];
  10. editor.onFreeMove = function() {
  11. var found = editor.findNodeOnRay(mouse.ray);
  12. if (editor.mouseOver !== found) {
  13. editor.mouseOver = found;
  14. if (found) {
  15. var n = abj.node[found];
  16. var s = "Node " + found + "<br/> ";
  17. for (var i in n) {
  18. if (i!="position"){
  19. s += i + ":" + n[i] + " ";
  20. }
  21. }
  22. s += "";
  23. gui.nodeMessage(s);
  24. } else {
  25. gui.hideNodeMessage();
  26. }
  27. }
  28. };
  29. editor.focus = function(node) {
  30. gui.hideNodeMessage();
  31. editor.selection = node;
  32. gui.serverMessage("Selected node " + node + ".");
  33. };
  34. editor.addQubitAtPoint = function(point) {
  35. if (point === null) {
  36. return;
  37. }
  38. point.round();
  39. var new_node = Math.floor(point.x) + "," + Math.floor(point.y) + "," + Math.floor(point.z);
  40. websocket.edit({action:"create", name:new_node, position: point});
  41. editor.focus(new_node);
  42. gui.serverMessage("Created node " + new_node +".");
  43. };
  44. editor.onClick = function() {
  45. var found = editor.findNodeOnRay(mouse.ray);
  46. if (found) {
  47. editor.focus(found);
  48. } else {
  49. var intersection = mouse.ray.intersectPlane(editor.plane);
  50. if (intersection !== null) {
  51. editor.addQubitAtPoint(intersection);
  52. }
  53. }
  54. };
  55. editor.onShiftClick = function() {
  56. var found = editor.findNodeOnRay(mouse.ray);
  57. if (found === undefined){ return; }
  58. if (editor.selection === undefined){ return; }
  59. if (found === editor.selection){ return; }
  60. //abj.act_cz(found, editor.selection);
  61. websocket.edit({action:"cz", start:found, end:editor.selection});
  62. editor.focus(found);
  63. gui.serverMessage("Acted CZ between " + found + " & " + editor.selection + ".");
  64. graph.update();
  65. };
  66. editor.onCtrlClick = function() {
  67. var found = editor.findNodeOnRay(mouse.ray);
  68. if (found === undefined){ return; }
  69. if (editor.selection === undefined){ return; }
  70. editor.focus(found);
  71. websocket.edit({action:"hadamard", node:found});
  72. gui.serverMessage("Acted H on node " + found + ".");
  73. graph.update();
  74. };
  75. editor.prepare = function() {
  76. mouse.onFreeMove = editor.onFreeMove;
  77. mouse.onClick = editor.onClick;
  78. mouse.onShiftClick = editor.onShiftClick;
  79. mouse.onCtrlClick = editor.onCtrlClick;
  80. document.addEventListener("keydown", editor.onKey, false);
  81. editor.makeGrid();
  82. };
  83. editor.onKey = function(evt) {
  84. if (evt.keyCode === 32) {
  85. editor.setOrientation((editor.orientation + 1) % 3);
  86. }
  87. if (evt.keyCode === 46 || evt.keyCode === 68) {
  88. editor.deleteNode();
  89. }
  90. };
  91. editor.setOrientation = function(orientation) {
  92. editor.orientation = orientation;
  93. var rotation = editor.orientations[orientation];
  94. var normal = new THREE.Vector3(0, 1, 0);
  95. normal.applyEuler(rotation);
  96. editor.grid.rotation.copy(rotation);
  97. editor.plane = new THREE.Plane();
  98. editor.plane.setFromNormalAndCoplanarPoint(normal, editor.grid.position);
  99. gui.render();
  100. };
  101. editor.makeGrid = function() {
  102. editor.grid = new THREE.GridHelper(10, 1);
  103. editor.grid.setColors(0xbbbbbb, 0xeeeeee);
  104. editor.setOrientation(0);
  105. gui.scene.add(editor.grid);
  106. };
  107. editor.update = function() {};
  108. // Gets a reference to the node nearest to the mouse cursor
  109. editor.findNodeOnRay = function(ray) {
  110. for (var n in abj.node) {
  111. if (ray.distanceSqToPoint(abj.node[n].position) < 0.012) {
  112. return n;
  113. }
  114. }
  115. return undefined;
  116. };
  117. editor.deleteNode = function() {
  118. if (editor.selection === undefined){ return; }
  119. websocket.edit({action:"delete", node:editor.selection});
  120. graph.update();
  121. gui.serverMessage("Deleted node " + editor.selection + ".");
  122. editor.selection = undefined;
  123. node_data.className = "hidden";
  124. };
  125. editor.localComplementation = function() {
  126. if (editor.selection === undefined){ return; }
  127. abj.local_complementation(editor.selection);
  128. graph.update();
  129. gui.serverMessage("Inverted neighbourhood of " + editor.selection + ".");
  130. };