106 lines
3.0 KiB
HTML
106 lines
3.0 KiB
HTML
<!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>
|