var Outs, Inps, Btnt, Canvas; // async/await z příkladu na webu window.onload = async function() { Outs = document.getElementById('stdout'); Inps = document.getElementById('input'); Btnt = document.getElementById('buttonTest'); Canvas = document.getElementById('canvas'); Outs.value = ''; await getFile ('osc.txt'); Btnt.onclick = () => { Outs.value = ''; run (); }; }; function print (str) { Outs.value += str; } async function getFile (name) { console.log(name); const response = await fetch (name); if (!response.ok) return; const bytes = await response.arrayBuffer(); const array = new Uint8Array(bytes); const decoder = new TextDecoder(); Inps.value = decoder.decode(bytes); return false; } /////////////////////////////////////////////// function run () { let code = Inps.value; try { eval (code); } catch (err) { print('Error: ' + err.message + '\n'); } } function solve (hh, steps, data, pf) { let p = data; const N = pf.length; const hal = 0.5 * hh; const hhs = hh / 6.0; let min = {t:+1.0e100, w:[]}; for (let k=0; k max.t) max.t = p.t; for (let k=0; k max.w[k]) max.w[k] = p.w[k]; } result [0] = new Object (structuredClone(p)); for (let index=1; index max.t) max.t = np.t; for (let k=0; k max.w[k]) max.w[k] = np.w[k]; } result [index] = new Object (np); } initCanvas () return {data:result, m:min, p:max}; } function getValue (pt, si) { if (si.length > 1) { // w return pt[si[0]][si[1]]; } else { // t return pt[si[0]]; } } function initCanvas () { const width = canvas.clientWidth; const height = canvas.clientHeight; canvas.width = width; canvas.height = height; const ctx = canvas.getContext("2d"); ctx.clearRect(0, 0, canvas.width, canvas.height); } function plot (r, po, color) { print('plot:' + JSON.stringify(po) + '\n'); const p0 = r.data[0]; print('min: ' + JSON.stringify(r.m) + '\n'); print('max: ' + JSON.stringify(r.p) + '\n'); const xmin = getValue (r.m, po.x); const xmax = getValue (r.p, po.x); const ymin = getValue (r.m, po.y); const ymax = getValue (r.p, po.y); const xzom = canvas.width / (xmax - xmin); const yzom = canvas.height / (ymin - ymax); const xofs = xmin * canvas.width / (xmin - xmax); const yofs = ymax * canvas.height / (ymax - ymin); //console.log (xmin, xmax, ymin, ymax); const ctx = canvas.getContext("2d"); ctx.beginPath(); const x0 = xzom * getValue(p0, po.x) + xofs; const y0 = yzom * getValue(p0, po.y) + yofs; ctx.moveTo(x0, y0); for (let n=1; n