Skip to content

Commit

Permalink
now waits for key to draw
Browse files Browse the repository at this point in the history
  • Loading branch information
John Owens committed Nov 5, 2024
1 parent 0515b6a commit 8a72738
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions both_webgpu/both_deno_gfx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 8a72738

Please sign in to comment.