From 499d2d6e6394e2569b19a808b77bf921878bfbfa Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Thu, 6 Feb 2025 11:07:03 -0600 Subject: [PATCH] bunnymark --- examples/bunnymark/bunny.png | Bin 0 -> 449 bytes examples/bunnymark/config.js | 5 +++ examples/bunnymark/main.js | 69 +++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 examples/bunnymark/bunny.png create mode 100644 examples/bunnymark/config.js create mode 100644 examples/bunnymark/main.js diff --git a/examples/bunnymark/bunny.png b/examples/bunnymark/bunny.png new file mode 100644 index 0000000000000000000000000000000000000000..79c31675083b7ffc272a6370bc189360bde484d0 GIT binary patch literal 449 zcmV;y0Y3hTP)SOJFMz`0@qn1GK$9W|wOohG3Lai}FkWLtiT<2<{JbM8>W7|R$! zUuNqg#gmKmsTnILy&K;zJjd^_40xy)%EA1>FWWk~LFpr>Et|!Hv(V>Hs9!2xEQJ>~!qz76HLsxFXdG zs5~GjUDeD6dXvG$_#HtoUok|M-X@BSTy{VK4P?TJZcz}O&FVzD0fZu8Yajr@?2aYL r_Q@_>J=ju&>AqoA-=wzwF98MsNX4 60) fpsSamples.shift() + var sum = 0 + for (var f of fpsSamples) sum += f + fpsAvg = sum / fpsSamples.length + + // If left mouse is down, spawn some more bunnies: + var mouse = input.mousestate() + if (mouse.left) + for (var i = 0; i < 50; i++) { + bunnies.push({ + x: mouse.x, + y: mouse.y, + vx: (Math.random() * 300) - 150, + vy: (Math.random() * 300) - 150 + }) + } + + // Update bunny positions and bounce them inside the screen: + for (var i = 0; i < bunnies.length; i++) { + var b = bunnies[i] + b.x += b.vx * dt + b.y += b.vy * dt + + // Bounce off left/right edges + if (b.x < 0) { b.x = 0; b.vx = -b.vx } + else if (b.x > config.width) { b.x = config.width; b.vx = -b.vx } + + // Bounce off bottom/top edges + if (b.y < 0) { b.y = 0; b.vy = -b.vy } + else if (b.y > config.height) { b.y = config.height; b.vy = -b.vy } + } +} + +this.hud = function() { + draw.images(bunnyTex, bunnies) + + var msg = 'FPS: ' + fpsAvg.toFixed(2) + ' Bunnies: ' + bunnies.length + draw.text(msg, {x:0, y:0, width:config.width, height:40}, undefined, 0, Color.white, 0) +}