commit 397c8495435775e1f5415910c0283ddadfc9b254 Author: Kizarm Date: Sat Dec 16 16:27:51 2023 +0100 add pages diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3efaf1a --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# kdevelop +.kde* +*.kdev4 +# other +*.o +lib/libWASM.a diff --git a/bin/index.html b/bin/index.html new file mode 100644 index 0000000..351a1d8 --- /dev/null +++ b/bin/index.html @@ -0,0 +1,27 @@ + + + + + + Quantum + + +
+

Kvantový vývoj.

+

Harmonický oscilátor. +

+

Kvantová jáma. +

+

Obojí je jen přepis apletu ze serveru Aldebaran, to už na novějších prohlížečích nefunguje, + je to jednoduše přepsáno jako bare-bone webassembly modul. Původně to bylo napsáno pro emscripten, + ale nakonec je to zoptimalizováno jen pro clang, nakonec není to nic složitého a těch pár knihovních + funkcí je dopsáno ručně, byť ne moc efektivně. A je to tak 10x menší (ne, že by na tom moc záleželo). +

+

Není to nijak učesané, nejsou ani ošetřeny všechny závislosti a tím méně chyby. Celkem to však + funguje, je např. vidět, že čistý bázový stav nemá časový vývoj. Samozřejmě chybí i jakékoli + komentáře, ale dělal jsem to abych se něco nového naučil, ne abych to prodal.´ +

+
+ diff --git a/bin/oscilator.html b/bin/oscilator.html new file mode 100644 index 0000000..611efce --- /dev/null +++ b/bin/oscilator.html @@ -0,0 +1,131 @@ + + + + + + Oscilator + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
Váhy:
12345678910
 
+
Rychlost 
+

+ + + diff --git a/bin/oscilator.js b/bin/oscilator.js new file mode 100644 index 0000000..3960411 --- /dev/null +++ b/bin/oscilator.js @@ -0,0 +1,116 @@ +var gWASM = null; // WASM -> global object +var Animate = 0; +var canvas = document.getElementById('canvas'); +var context = canvas.getContext('2d'); +var bgImage = new Image(); +window.onload = async function() { + const memory = new WebAssembly.Memory({ initial: 128 }); + if (!memory) { + console.log ('!!! WebAssembly not supported'); return; + } + const importObject = { + env: { memory }, + imports: { // importované funkce do wasm + PrintOut : (ptr, len) => { + const view = new Uint8Array (memory.buffer, ptr, len); + const utf8decoder = new TextDecoder(); + console.log (utf8decoder.decode(view)); + }, + memoryGrow : (len) => { + console.log ('Growing the memory by ' + len.toString() + '. 64K blocks'); + importObject.env.memory.grow (len); + }, + }, + }; + const response = await fetch('./oscilator.wasm'); + const bytes = await response.arrayBuffer(); + const module = await WebAssembly.instantiate(bytes, importObject); + gWASM = { + asm : module.instance.exports, + mem : memory, + }; + gWASM.asm.Init(memory.buffer.byteLength); + + window.addEventListener('resize', resizeCanvas, false); + resizeCanvas(); + ClearWeights(); + + const id = document.getElementById ('speed'); + id.value = 1; +} +function SetSpeed () { + const id = document.getElementById ('speed'); + gWASM.asm.setSpeed (parseInt (id.value)); + document.getElementById ('showspeed').innerHTML = 'Rychlost : ' + id.value; +} +function StartStop () { + Animate = gWASM.asm.gEnabled (); + const id = document.getElementById ('animate'); + if (Animate) id.innerHTML = 'Stop'; + else id.innerHTML = 'Vývoj'; +} +function SetWeight (n) { + const sid = 'Weight' + n; + const val = document.getElementById (sid).value; + const m = n + 1; + const out = m.toString() + ' : ' + val.toString() + '%'; + document.getElementById('weightText').innerHTML = out; + gWASM.asm.setWeight (n, parseInt (val)); + drawPass (); +} +function ClearWeights () { + for (i=0; i<10; i++) { + const sid = 'Weight' + i; + document.getElementById (sid).value = 0; + document.getElementById('weightText').innerHTML = 'vynulováno'; + gWASM.asm.setWeight (i,0); + } + gWASM.asm.Reset(); + drawPass(); +} +function resizeCanvas() { + const width = canvas.clientWidth; + const height = canvas.clientHeight; + canvas.width = width; + canvas.height = height; + gWASM.asm.graph (width, height); + drawStuff (); + window.setTimeout (ReplotPass, 50); +} +function drawStuff() { + context.clearRect(0, 0, canvas.widht, canvas.height); + delete bgImage; + bgImage = backup (gWASM.asm.bg_data()); + context.drawImage (bgImage, 0, 0); + const fgImage = backup (gWASM.asm.fg_data()); + context.drawImage (fgImage, 0, 0); +} +function drawPass() { + const fgImage = backup (gWASM.asm.fg_data()); + context.clearRect(0, 0, canvas.widht, canvas.height); + context.drawImage (bgImage, 0, 0); + context.drawImage (fgImage, 0, 0); +} +function ReplotPass () { + if (Animate) { + // console.log ('Pass'); + const fgImage = backup (gWASM.asm.gStep()); + context.clearRect(0, 0, canvas.widht, canvas.height); + context.drawImage (bgImage, 0, 0); + context.drawImage (fgImage, 0, 0); + } + window.setTimeout (ReplotPass, 20); +} +function backup (m_Data) { + const buffer = gWASM.mem.buffer; + const memarr = new Uint32Array (buffer, m_Data, 2); + const canvas = document.getElementById('canvas'); + const width = canvas.width; + const height = canvas.height; + const tmpcvs = new OffscreenCanvas(width, height); + const tmpctx = tmpcvs.getContext('2d'); + const bytes = new ImageData (new Uint8ClampedArray (buffer, memarr[0], memarr[1]), width, height); + tmpctx.putImageData (bytes, 0, 0); + return tmpcvs; // vrati obrazek +} + diff --git a/bin/oscilator.wasm b/bin/oscilator.wasm new file mode 100755 index 0000000..44541f3 Binary files /dev/null and b/bin/oscilator.wasm differ diff --git a/bin/well.html b/bin/well.html new file mode 100644 index 0000000..54c41a7 --- /dev/null +++ b/bin/well.html @@ -0,0 +1,131 @@ + + + + + + Quantum_Well + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
Váhy:
12345678910
 
+
Rychlost 
+

+ + + diff --git a/bin/well.js b/bin/well.js new file mode 100644 index 0000000..be48ea0 --- /dev/null +++ b/bin/well.js @@ -0,0 +1,116 @@ +var gWASM = null; // WASM -> global object +var Animate = 0; +var canvas = document.getElementById('canvas'); +var context = canvas.getContext('2d'); +var bgImage = new Image(); +window.onload = async function() { + const memory = new WebAssembly.Memory({ initial: 128 }); + if (!memory) { + console.log ('!!! WebAssembly not supported'); return; + } + const importObject = { + env: { memory }, + imports: { // importované funkce do wasm + PrintOut : (ptr, len) => { + const view = new Uint8Array (memory.buffer, ptr, len); + const utf8decoder = new TextDecoder(); + console.log (utf8decoder.decode(view)); + }, + memoryGrow : (len) => { + console.log ('Growing the memory by ' + len.toString() + '. 64K blocks'); + importObject.env.memory.grow (len); + }, + }, + }; + const response = await fetch('./well.wasm'); + const bytes = await response.arrayBuffer(); + const module = await WebAssembly.instantiate(bytes, importObject); + gWASM = { + asm : module.instance.exports, + mem : memory, + }; + gWASM.asm.Init(memory.buffer.byteLength); + + window.addEventListener('resize', resizeCanvas, false); + resizeCanvas(); + ClearWeights(); + + const id = document.getElementById ('speed'); + id.value = 1; +} +function SetSpeed () { + const id = document.getElementById ('speed'); + gWASM.asm.setSpeed (parseInt (id.value)); + document.getElementById ('showspeed').innerHTML = 'Rychlost : ' + id.value; +} +function StartStop () { + Animate = gWASM.asm.gEnabled (); + const id = document.getElementById ('animate'); + if (Animate) id.innerHTML = 'Stop'; + else id.innerHTML = 'Vývoj'; +} +function SetWeight (n) { + const sid = 'Weight' + n; + const val = document.getElementById (sid).value; + const m = n + 1; + const out = m.toString() + ' : ' + val.toString() + '%'; + document.getElementById('weightText').innerHTML = out; + gWASM.asm.setWeight (n, parseInt (val)); + drawPass (); +} +function ClearWeights () { + for (i=0; i<10; i++) { + const sid = 'Weight' + i; + document.getElementById (sid).value = 0; + document.getElementById('weightText').innerHTML = 'vynulováno'; + gWASM.asm.setWeight (i,0); + } + gWASM.asm.Reset(); + drawPass(); +} +function resizeCanvas() { + const width = canvas.clientWidth; + const height = canvas.clientHeight; + canvas.width = width; + canvas.height = height; + gWASM.asm.graph (width, height); + drawStuff (); + window.setTimeout (ReplotPass, 50); +} +function drawStuff() { + context.clearRect(0, 0, canvas.widht, canvas.height); + delete bgImage; + bgImage = backup (gWASM.asm.bg_data()); + context.drawImage (bgImage, 0, 0); + const fgImage = backup (gWASM.asm.fg_data()); + context.drawImage (fgImage, 0, 0); +} +function drawPass() { + const fgImage = backup (gWASM.asm.fg_data()); + context.clearRect(0, 0, canvas.widht, canvas.height); + context.drawImage (bgImage, 0, 0); + context.drawImage (fgImage, 0, 0); +} +function ReplotPass () { + if (Animate) { + // console.log ('Pass'); + const fgImage = backup (gWASM.asm.gStep()); + context.clearRect(0, 0, canvas.widht, canvas.height); + context.drawImage (bgImage, 0, 0); + context.drawImage (fgImage, 0, 0); + } + window.setTimeout (ReplotPass, 20); +} +function backup (m_Data) { + const buffer = gWASM.mem.buffer; + const memarr = new Uint32Array (buffer, m_Data, 2); + const canvas = document.getElementById('canvas'); + const width = canvas.width; + const height = canvas.height; + const tmpcvs = new OffscreenCanvas(width, height); + const tmpctx = tmpcvs.getContext('2d'); + const bytes = new ImageData (new Uint8ClampedArray (buffer, memarr[0], memarr[1]), width, height); + tmpctx.putImageData (bytes, 0, 0); + return tmpcvs; // vrati obrazek +} + diff --git a/bin/well.wasm b/bin/well.wasm new file mode 100755 index 0000000..86622ad Binary files /dev/null and b/bin/well.wasm differ