I tried to declare the size of html canvas in css, rather than javascript, and this somehow causes the sizes and objects drawn with js to appear all weird. Here is my HTML code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Computing Animatie</title>
<style>
body {
overflow: hidden;
background-color: black;
background-image: url('./pictures/project_bg.jpg');
background-size: 1375px;
}
canvas {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<canvas id="can"></canvas>
<script src="animation.js"></script>
</body>
</html>
and here is my javascript code:
const can = document.getElementById('can');
const ctx = can.getContext('2d');
(function test(){
ctx.beginPath();
ctx.fillStyle = 'red';
ctx.fillRect(100, 100, 50, 50);
ctx.closePath();
})();
When i run this, the rectangle gets weirdly stretched. I hope anyone knows anything...