summaryrefslogtreecommitdiff
path: root/quickdraw-game.html
blob: 175abfb21c12b542a42835b2258a46bc73ebcfda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!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: absolute;
            }
            #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);
            });

            let k, r, x, y;
            let radians;
            for (let i = 0; i < 360; i++) {
              r = frameWidth / 2;

              radians = degreesToRadians(i);

              x = r * Math.cos(i);
              y = r * Math.sin(i);
              console.log(x + ', ' + y);

              generateTarget(x, y);
            }

            // init logs:
            console.log('page: ' + pageWidth + ' x ' + pageHeight);
            console.log('frame: ' + frameWidth + ' x ' + frameHeight);


            

            function degreesToRadians(degrees) {
              return degrees * (Math.PI / 180)
            }
            
            
            function generateTarget(x, y) {
                const target = document.createElement("div");
                target.id = "target";
                target.style.top = y +'px';
                target.style.left = x + '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>