HTML5 Javascript Canvas Gravity

by Spsoi

HTML

<!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>Document</title>
</head>
<body>
    <canvas id="canvas" width="500" height="500"></canvas>
</body>
</html>

CSS

canvas {
    border: 1px solid #000;
}

JavaScript

canvas = document.querySelector('#canvas');
let c = canvas.getContext('2d');

let mouse = {
    x: innerWidth / 2,
    y: innerHeight / 2
}

let color = [
    '#2185c5',
    '#7ECEFD',
    '#FFF6E5',
    '#FF7F66'
];

document.addEventListener("mousemove", function(event){
    mouse.x = event.clientX;
    mouse.y = event.clientY;
});

function animate() {
    console.log(mouse.x);
    console.log(mouse.y);
    c.clearRect(0,0, canvas.width, canvas.height);
    c.fillText("HTML CANVAS BOILERPLATE", mouse.x, mouse.y)
    requestAnimationFrame(animate);
}

animate();