Skip to content

Instantly share code, notes, and snippets.

@wolf20482
Created March 10, 2022 08:13
Show Gist options
  • Save wolf20482/ae3fd1fda1c348d769f656f52fcc521d to your computer and use it in GitHub Desktop.
Save wolf20482/ae3fd1fda1c348d769f656f52fcc521d to your computer and use it in GitHub Desktop.
random colors with mouse
<!DOCTYPE html>
<html>
<head>
<style>
html,
body {
margin: 0 !important;
padding: 0 !important;
overflow-x: hidden !important;
overflow-y: hidden !important;
}
</style>
</head>
<body>
<canvas id="nft" width="300" height="150" onmousemove="myFunction(event)">
update your browser</canvas>
<script>
let c = document.getElementById("nft");
c.width = window.innerWidth;
c.height = window.innerHeight;
let ctx = c.getContext("2d");
function myFunction(e) {
ctx.fillStyle = "#" + Math.floor(Math.random() * 16777215).toString(16);
let x = e.clientX;
let y = e.clientY;
ctx.fillRect(x, y, 4, 4);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment