Created
October 16, 2019 08:05
-
-
Save JonathanDn/7e56c6dce510b9441e287fc28a2b0c62 to your computer and use it in GitHub Desktop.
Revisions
-
JonathanDn created this gist
Oct 16, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ body { margin: 0; overflow: hidden; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ <canvas></canvas> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,77 @@ // Initial Setup var canvas = document.querySelector('canvas'); var c = canvas.getContext('2d'); canvas.width = innerWidth; canvas.height = innerHeight; // Variables var mouse = { y: innerWidth / 2, x: innerHeight / 2 } var color = [ '#2185C5', '#7ECEFD', '#FFF6E5', '#FF7F66' ] // Event Listeners addEventListener("mousemove", function(){ mouse.x = event.clientX, mouse.y = event.clientY }); addEventListener("resize", function() { canvas.width = innerWidth, canvas.height = innerHeight init(); }); // Utility Functions function randomIntFromRange(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } function randomColor(colors) { return color[Math.floor(Math.random() * colors.length)]; } function Object(x, y, radius, color) { this.x = x; this.y = y; this.radius = radius; this.color = color; this.update = function() { this.draw(); } this.draw = function() { c.beginPath(); c.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false); c.fillStyle = this.color; c.fill(); c.closePath(); } } // Implementation function init() { } // Animation Loop function animate() { requestAnimationFrame(animate); c.clearRect(0, 0, canvas.width, canvas.height); c.fillText("HTML CAVNAS BOILERPLATE", mouse.x, mouse.y); } init(); animate();