summaryrefslogtreecommitdiff
path: root/quickdraw-game.html
diff options
context:
space:
mode:
authorsimon-ec <simon@eustaceconsulting.com>2026-06-06 19:04:01 -0400
committersimon-ec <simon@eustaceconsulting.com>2026-06-06 19:04:01 -0400
commite02696b245720df5ce05a0109589c74d8ff5b217 (patch)
tree566e4c0596b557451eead7ca9e2a309a797cb811 /quickdraw-game.html
init
Diffstat (limited to 'quickdraw-game.html')
-rw-r--r--quickdraw-game.html90
1 files changed, 90 insertions, 0 deletions
diff --git a/quickdraw-game.html b/quickdraw-game.html
new file mode 100644
index 0000000..6d9746f
--- /dev/null
+++ b/quickdraw-game.html
@@ -0,0 +1,90 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <style>
+ * {
+ box-sizing: border-box;
+ margin: 0;
+ padding: 0;
+ }
+ html {
+ height: 100vh;
+ width: 100vw;
+ background-color: #161616;
+ }
+ body {
+ display: flex;
+ justify-content: center;
+ }
+ #target {
+ height: 20px;
+ width: 20px;
+ background-color: red;
+ position: relative;
+ }
+ #frame {
+ width: 75%;
+ height: 100vh;
+ border: 1px solid white;
+ }
+ </style>
+ </head>
+ <body>
+
+ <div id="frame">
+
+ </div>
+
+ <script>
+
+ const targetWidth = 20;
+ const targetHeight = 20;
+
+ let pageWidth = window.innerWidth;
+ let pageHeight = window.innerHeight;
+
+ const frameElement = document.getElementById("frame");
+ let frameHeight = frameElement.offsetHeight - targetHeight;
+ let frameWidth = frameElement.offsetWidth - targetWidth;
+
+ let target;
+
+
+ window.addEventListener("resize", (e) => {
+ this.pageWidth = window.innerWidth;
+ this.pageHeight = window.innerHeight;
+ this.frameHeight = frameElement.offsetHeight;
+ this.frameWidth = frameElement.offsetWidth;
+ console.log('page: ' + this.pageWidth + ' x ' + this.pageHeight);
+ console.log('frame: ' + this.frameWidth + ' x ' + this.frameHeight);
+ });
+
+ generateTarget();
+
+ // init logs:
+ console.log('page: ' + pageWidth + ' x ' + pageHeight);
+ console.log('frame: ' + frameWidth + ' x ' + frameHeight);
+
+
+
+
+
+
+ function generateTarget() {
+ const target = document.createElement("div");
+ target.id = "target";
+ target.style.top = getRandomInt(0, frameHeight) + 'px';
+ target.style.left = getRandomInt(0, frameWidth) + 'px';
+ console.log(target);
+ document.getElementById("frame").insertAdjacentElement("afterbegin", target);
+ }
+
+
+ function getRandomInt(min, max) {
+ const minCeiled = Math.ceil(min);
+ const maxFloored = Math.floor(max);
+ return Math.floor(Math.random() * (maxFloored - minCeiled) + minCeiled); // The maximum is exclusive and the minimum is inclusive
+ }
+ </script>
+ </body>
+</html> \ No newline at end of file