Browse Source

Small changes to editor

master
Pete Shadbolt 8 years ago
parent
commit
0c54c159ef
5 changed files with 53 additions and 30 deletions
  1. +8
    -6
      abp/clifford.py
  2. +16
    -8
      examples/visualization_demo.py
  3. +22
    -10
      static/scripts/editor.js
  4. +1
    -0
      static/scripts/gui.js
  5. +6
    -6
      static/scripts/tables.js

+ 8
- 6
abp/clifford.py View File

@@ -124,17 +124,19 @@ def write_javascript_tables():
""" Write the tables to javascript files for consumption in the browser """
path = os.path.dirname(sys.argv[0])
path = os.path.split(path)[0]
with open(os.path.join(path, "client/tables.js"), "w") as f:
f.write("var decompositions = {};\n"\
with open(os.path.join(path, "static/scripts/tables.js"), "w") as f:
f.write("var tables = {\n");
f.write("\tdecompositions : {},\n"\
.format(json.dumps(decompositions)))
f.write("var conjugation_table = {};\n"\
f.write("\tconjugation_table : {},\n"\
.format(json.dumps(conjugation_table.tolist())))
f.write("var times_table = {};\n"\
f.write("\ttimes_table : {},\n"\
.format(json.dumps(times_table.tolist())))
f.write("var cz_table = {};\n"\
f.write("\tcz_table : {},\n"\
.format(json.dumps(cz_table.tolist())))
f.write("var clifford = {};\n"\
f.write("\tclifford : {}\n"\
.format(json.dumps(by_name)))
f.write("};");


# First try to load tables from cache. If that fails, build them from


+ 16
- 8
examples/visualization_demo.py View File

@@ -3,13 +3,21 @@ import numpy as np
import time

s = VisibleGraphState()
for i in range(200):
x = 10*np.cos(np.pi*2*i/60)
y = 10*np.sin(np.pi*2*i/60)
s.add_node(i, {"position": {"x":round(x, 2), "y":round(y, 2), "z":round(i/50., 2)}})
s.act_local_rotation(i, "hadamard")
for i in range(200-1):
s.act_cz(i, i+1)
time.sleep(.3)
for i in range(100):
s.add_node(i, {"position": {"x":i, "y":i, "z":i}});
s.update()
time.sleep(.5)


#for i in range(200):
#x = 10*np.cos(np.pi*2*i/60)
#y = 10*np.sin(np.pi*2*i/60)
#s.add_node(i, {"position": {"x":round(x, 2), "y":round(y, 2), "z":round(i/50., 2)}})
#s.act_local_rotation(i, "hadamard")


#for i in range(200-1):
#s.act_cz(i, i+1)
#time.sleep(.3)
#s.update()


+ 22
- 10
static/scripts/editor.js View File

@@ -1,6 +1,15 @@
var editor = {};
var pi2 = Math.pi / 2;

editor.nearest = undefined;

editor.orientations = {
xy: new THREE.Matrix4(),
xz: new THREE.Matrix4(),
yz: new THREE.Matrix4()
};
editor.orientations.xz.makeRotationX(pi2);

editor.onFreeMove = function() {
var n = editor.nearestNode(mouse.ray);
if (editor.nearest !== n) {
@@ -16,7 +25,7 @@ editor.onFreeMove = function() {

editor.onClick = function() {
var n = editor.nearestNode(mouse.ray);
if (n){
if (n) {
var p = abj.meta[n].position;
editor.grid.position.set(p.x, p.y, p.z);
gui.controls.target.set(p.x, p.y, p.z);
@@ -30,7 +39,9 @@ editor.onClick = function() {
intersection.y = Math.round(intersection.y, 0);
intersection.z = Math.round(intersection.z, 0);
var newNode = abj.order();
abj.add_node(newNode, {position:intersection});
abj.add_node(newNode, {
position: intersection
});
editor.grid.position.set(intersection.x, intersection.y, intersection.z);
gui.controls.target.set(intersection.x, intersection.y, intersection.z);
graph.update();
@@ -41,15 +52,13 @@ editor.onClick = function() {
editor.prepare = function() {
mouse.onFreeMove = editor.onFreeMove;
mouse.onClick = editor.onClick;
document.addEventListener("keydown", editor.onKey, false);
document.addEventListener("keydown", editor.onKey, false);
editor.makeGrid();
};

editor.onKey = function(evt){
if (evt.keyCode==32){
editor.grid.rotation.x += Math.PI/2;
var m = new THREE.Matrix4();
m.makeRotationX(Math.PI/2);
editor.onKey = function(evt) {
if (evt.keyCode == 32) {
editor.grid.rotation.x += Math.PI / 2;
editor.plane.applyMatrix4(m);
gui.render();
gui.serverMessage("Rotated into the XY plane or whatever");
@@ -60,9 +69,13 @@ editor.makeGrid = function() {
editor.grid = new THREE.GridHelper(10, 1);
editor.grid.rotation.x = Math.PI / 2;
editor.grid.setColors(0xbbbbbb, 0xeeeeee);
//editor.grid.matrixAutoUpdate = false;
editor.plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
gui.scene.add(editor.grid);
}
};

editor.update = function(){
};

// Gets a reference to the node nearest to the mouse cursor
// TODO: get rid of meta{}
@@ -74,4 +87,3 @@ editor.nearestNode = function(ray) {
}
return undefined;
};


+ 1
- 0
static/scripts/gui.js View File

@@ -72,6 +72,7 @@ gui.setInfoPosition = function(position){
// The main loop
gui.loop = function() {
gui.controls.update();
editor.update();
requestAnimationFrame(gui.loop);
};



+ 6
- 6
static/scripts/tables.js
File diff suppressed because it is too large
View File


Loading…
Cancel
Save