diff --git a/both_webgpu/both_deno_gfx.mjs b/both_webgpu/both_deno_gfx.mjs index f33ea9b..dea19c8 100644 --- a/both_webgpu/both_deno_gfx.mjs +++ b/both_webgpu/both_deno_gfx.mjs @@ -59,34 +59,31 @@ const { adapter, device } = await getDeviceAndAdapter(navigator); const window = new WindowBuilder("Hello, Deno!", 640, 480).build(); const canvas = window.canvas(); -async function loop(frames) { +async function loop(frames, waitingForKeyboard = true) { if (frames == 0) { return; } const event = (await window.events().next()).value; - if (event.type == EventType.Quit) { - return; - } else { - // if (event.type == EventType.Draw) { - // Rainbow effect - const r = Math.sin(Date.now() / 1000) * 127 + 128; - const g = Math.sin(Date.now() / 1000 + 2) * 127 + 128; - const b = Math.sin(Date.now() / 1000 + 4) * 127 + 128; - canvas.setDrawColor(Math.floor(r), Math.floor(g), Math.floor(b), 255); - canvas.clear(); - await main(navigator); - canvas.present(); - } - await loop(frames - 1); -} - -async function loopx(frames) { - if (frames == 0) { - return; + switch (event.type) { + case EventType.Quit: + return; + case EventType.KeyDown: + waitingForKeyboard = false; + break; + default: + if (spin == false) { + const r = Math.sin(Date.now() / 1000) * 127 + 128; + const g = Math.sin(Date.now() / 1000 + 2) * 127 + 128; + const b = Math.sin(Date.now() / 1000 + 4) * 127 + 128; + canvas.setDrawColor(Math.floor(r), Math.floor(g), Math.floor(b), 255); + canvas.clear(); + await main(navigator); + canvas.present(); + frames--; + } + break; } - await main(navigator); - minwin.canvas.present(); - await loopx(frames - 1); + await loop(frames, waitingForKeyboard); } await loop(2);