Skip to content

Commit 82af889

Browse files
committed
add more information
1 parent b548be8 commit 82af889

File tree

16 files changed

+276
-48
lines changed

16 files changed

+276
-48
lines changed

docs/assets/github-mark-white.png

6.36 KB
Loading

docs/assets/sphere.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<meta charset="UTF-8" />
88
<link rel="stylesheet" href="style.css">
9-
<link rel="preload" href="./wasm/editor_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
10-
<link rel="preload" href="./wasm/editor.js" as="script">
9+
<link rel="preload" href="/./wasm/editor_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
10+
<link rel="preload" href="/./wasm/editor.js" as="script">
1111
</head>
1212
<body>
1313
<div id="main"></div>
1414
<script>
1515
// We can't use a module script here because we need to start the script immediately when streaming
16-
import("./wasm/editor.js").then(
16+
import("/./wasm/editor.js").then(
1717
({ default: init }) => {
18-
init("./wasm/editor_bg.wasm").then((wasm) => {
18+
init("/./wasm/editor_bg.wasm").then((wasm) => {
1919
if (wasm.__wbindgen_start == undefined) {
2020
wasm.main();
2121
}

docs/wasm/editor.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,15 @@ function __wbg_adapter_50(arg0, arg1) {
229229
}
230230

231231
function __wbg_adapter_53(arg0, arg1, arg2) {
232-
wasm.closure317_externref_shim(arg0, arg1, arg2);
232+
wasm.closure321_externref_shim(arg0, arg1, arg2);
233233
}
234234

235235
function __wbg_adapter_56(arg0, arg1, arg2) {
236-
wasm.closure320_externref_shim(arg0, arg1, arg2);
236+
wasm.closure324_externref_shim(arg0, arg1, arg2);
237237
}
238238

239239
function __wbg_adapter_59(arg0, arg1, arg2) {
240-
wasm.closure524_externref_shim(arg0, arg1, arg2);
240+
wasm.closure528_externref_shim(arg0, arg1, arg2);
241241
}
242242

243243
const __wbindgen_enum_ScrollBehavior = ["auto", "instant", "smooth"];
@@ -1368,20 +1368,20 @@ function __wbg_get_imports() {
13681368
const ret = false;
13691369
return ret;
13701370
};
1371-
imports.wbg.__wbindgen_closure_wrapper1062 = function(arg0, arg1, arg2) {
1372-
const ret = makeMutClosure(arg0, arg1, 525, __wbg_adapter_59);
1371+
imports.wbg.__wbindgen_closure_wrapper1073 = function(arg0, arg1, arg2) {
1372+
const ret = makeMutClosure(arg0, arg1, 529, __wbg_adapter_59);
13731373
return ret;
13741374
};
1375-
imports.wbg.__wbindgen_closure_wrapper734 = function(arg0, arg1, arg2) {
1376-
const ret = makeMutClosure(arg0, arg1, 314, __wbg_adapter_50);
1375+
imports.wbg.__wbindgen_closure_wrapper745 = function(arg0, arg1, arg2) {
1376+
const ret = makeMutClosure(arg0, arg1, 318, __wbg_adapter_50);
13771377
return ret;
13781378
};
1379-
imports.wbg.__wbindgen_closure_wrapper736 = function(arg0, arg1, arg2) {
1380-
const ret = makeMutClosure(arg0, arg1, 314, __wbg_adapter_53);
1379+
imports.wbg.__wbindgen_closure_wrapper747 = function(arg0, arg1, arg2) {
1380+
const ret = makeMutClosure(arg0, arg1, 318, __wbg_adapter_53);
13811381
return ret;
13821382
};
1383-
imports.wbg.__wbindgen_closure_wrapper738 = function(arg0, arg1, arg2) {
1384-
const ret = makeMutClosure(arg0, arg1, 314, __wbg_adapter_56);
1383+
imports.wbg.__wbindgen_closure_wrapper749 = function(arg0, arg1, arg2) {
1384+
const ret = makeMutClosure(arg0, arg1, 318, __wbg_adapter_56);
13851385
return ret;
13861386
};
13871387
imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {

docs/wasm/editor.js.br

-1 Bytes
Binary file not shown.

docs/wasm/editor_bg.wasm

11.4 KB
Binary file not shown.

docs/wasm/editor_bg.wasm.br

3.07 KB
Binary file not shown.

editor/assets/github-mark-white.png

4.72 KB
Loading

editor/assets/sphere.js

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,22 @@ const material = new THREE.PointsMaterial({ size: 1, vertexColors: true });
2828
const points = new THREE.Points(geometry, material);
2929
scene.add(points);
3030

31+
let vertices_current = [];
32+
let vertices_target = [];
33+
3134
async function updatePoints(newPositions) {
3235
let vertices = new Float32Array(newPositions);
3336

37+
vertices_target = [];
38+
for (let i = 0; i < newPositions.length; i += 3) {
39+
let {r, theta, phi} = cartesianToSpherical(newPositions[i], newPositions[i + 1], newPositions[i + 2]);
40+
vertices_target.push(r, theta, phi);
41+
}
42+
if (vertices_current.length != vertices_target.length) {
43+
console.log("qubit length changed");
44+
vertices_current = vertices_target;
45+
}
46+
3447
let clean_vertices = [];
3548
let counts = [];
3649
for (let i = 0; i < vertices.length; i += 3) {
@@ -56,24 +69,54 @@ async function updatePoints(newPositions) {
5669
let colors = [];
5770
for (let i = 0; i < counts.length; i++) {
5871
let total = (vertices.length / 3) - 1;
72+
if (total == 0) { total = 1000; }
5973
let color = new THREE.Color().setHSL((1 - (counts[i] / total)) * 0.7, 0.8, 0.5);
60-
console.log((1 - (counts[i] / total)) * 0.7);
6174
colors.push(color.r, color.g, color.b);
6275
}
6376

64-
console.log(counts);
65-
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(clean_vertices), 3 ) );
77+
let colors_all = [];
78+
for (let i = 0; i < vertices.length; i += 3) {
79+
for (let j = 0; j < clean_vertices.length; j += 3) {
80+
const dx = vertices[i] - clean_vertices[j];
81+
const dy = vertices[i + 1] - clean_vertices[j + 1];
82+
const dz = vertices[i + 2] - clean_vertices[j + 2];
83+
const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
6684

67-
geometry.setAttribute('color', new THREE.Float32BufferAttribute( colors, 3 ) );
68-
geometry.attributes.position.needsUpdate = true; // Flag for updating
85+
if (distance < 0.05) {
86+
colors_all.push(colors[j], colors[j + 1], colors[j + 2]);
87+
}
88+
}
89+
}
90+
91+
geometry.setAttribute('color', new THREE.Float32BufferAttribute( colors_all, 3 ) );
6992
geometry.attributes.color.needsUpdate = true; // Flag for updating
7093
}
7194

95+
function cartesianToSpherical(x, y, z) {
96+
const r = Math.sqrt(x * x + y * y + z * z);
97+
if (r < 0.05) {
98+
return { r, theta: 0, phi: 0 };
99+
}
100+
const theta = Math.acos(z / r); // polar angle
101+
const phi = Math.atan2(y, x); // azimuthal angle
102+
return { r, theta, phi };
103+
}
104+
105+
function sphericalToCartesian(r, theta, phi) {
106+
const x = r * Math.sin(theta) * Math.cos(phi);
107+
const y = r * Math.sin(theta) * Math.sin(phi);
108+
const z = r * Math.cos(theta);
109+
return { x, y, z };
110+
}
111+
112+
function lerp(a, b, t) {
113+
return a + (b - a) * t;
114+
}
115+
72116
document.addEventListener("blochpointsupdate", function(e) { updatePoints(e.detail) });
73117

74118
let vertices = [
75119
0, 8, 0,
76-
0, 8, 0,
77120
];
78121

79122
updatePoints(vertices);
@@ -101,6 +144,19 @@ function animate() {
101144
requestAnimationFrame(animate);
102145

103146
controls.update();
147+
148+
for (let i = 0; i < vertices_current.length; i += 1) {
149+
vertices_current[i] = lerp(vertices_current[i], vertices_target[i], 0.1)
150+
}
151+
152+
let vertices = [];
153+
for (let i = 0; i < vertices_current.length; i += 3) {
154+
let { x, y, z } = sphericalToCartesian(vertices_current[i], vertices_current[i + 1], vertices_current[i + 2]);
155+
vertices.push(x, y, z);
156+
}
157+
158+
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(vertices), 3 ) );
159+
geometry.attributes.position.needsUpdate = true; // Flag for updating
104160

105161
renderer.render(scene, camera);
106162
}

editor/assets/style.css

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ body {
88

99
h1 {
1010
color: #ffffeb;
11-
margin: 10px 0;
11+
margin-bottom: 10px;
12+
margin-top: 0px;
1213
}
1314

1415
.register {
@@ -163,6 +164,16 @@ button {
163164
border-radius: 6px;
164165
}
165166

167+
select {
168+
background: #ffffeb;
169+
border: none;
170+
border-radius: 6px;
171+
}
172+
173+
option {
174+
175+
}
176+
166177
button:active {
167178
background: lightgrey;
168179
}
@@ -224,13 +235,15 @@ button:active {
224235
background: #ffffeb;
225236
border-radius: 8px;
226237
padding: 8px;
238+
height: fit-content;
227239
}
228240

229241
.blochinfo {
230242
background: #ffffeb;
231243
border-radius: 8px;
232244
padding: 8px;
233245
width: 340px;
246+
min-width: 340px;
234247
}
235248

236249
.qubitgradient {
@@ -252,3 +265,19 @@ h3 {
252265
p {
253266
font-size: 15px;
254267
}
268+
269+
.header{
270+
display: flex;
271+
flex-direction: row;
272+
justify-content: space-between;
273+
}
274+
275+
.githublink {
276+
position: relative;
277+
top: 14px;
278+
}
279+
280+
.githublink img {
281+
width: 32px;
282+
height: 32px;
283+
}

0 commit comments

Comments
 (0)