Skip to content

Instantly share code, notes, and snippets.

@klaylton
Created December 24, 2018 04:08
Show Gist options
  • Save klaylton/f36b91851fb15bd45562cea8bbf326df to your computer and use it in GitHub Desktop.
Save klaylton/f36b91851fb15bd45562cea8bbf326df to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/witoned
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
canvas{
border: 1px solid red;
}
</style>
</head>
<body>
<canvas width="500" height="500"></canvas>
<script id="jsbin-javascript">
var canvas = document.querySelector("canvas")
var c = canvas.getContext("2d")
var w = canvas.width;
var h = canvas.height;
window.addEventListener("mousemove", function(e){
var cor = "red";
if( e.x + 30 > w || e.x - 30 < 0 ){
cor = "green";
} else if ( e.y + 30 > h || e.y - 30 < 0 ) {
cor = "blue";
} else {
cor = `hsl(${e.y}, 100%, 50%)`;
}
circle(e.x, e.y, cor);
});
function circle(x, y, cor){
c.clearRect(0, 0, 500, 500)
c.beginPath();
c.arc(x, y, 30, 0, Math.PI*2);
c.fillStyle = cor;
c.lineWidth = 5;
c.strokeStyle = cor;
c.stroke();
c.fill()
}
</script>
<script id="jsbin-source-css" type="text/css">canvas{
border: 1px solid red;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">var canvas = document.querySelector("canvas")
var c = canvas.getContext("2d")
var w = canvas.width;
var h = canvas.height;
window.addEventListener("mousemove", function(e){
var cor = "red";
if( e.x + 30 > w || e.x - 30 < 0 ){
cor = "green";
} else if ( e.y + 30 > h || e.y - 30 < 0 ) {
cor = "blue";
} else {
cor = `hsl(${e.y}, 100%, 50%)`;
}
circle(e.x, e.y, cor);
});
function circle(x, y, cor){
c.clearRect(0, 0, 500, 500)
c.beginPath();
c.arc(x, y, 30, 0, Math.PI*2);
c.fillStyle = cor;
c.lineWidth = 5;
c.strokeStyle = cor;
c.stroke();
c.fill()
}</script></body>
</html>
canvas{
border: 1px solid red;
}
var canvas = document.querySelector("canvas")
var c = canvas.getContext("2d")
var w = canvas.width;
var h = canvas.height;
window.addEventListener("mousemove", function(e){
var cor = "red";
if( e.x + 30 > w || e.x - 30 < 0 ){
cor = "green";
} else if ( e.y + 30 > h || e.y - 30 < 0 ) {
cor = "blue";
} else {
cor = `hsl(${e.y}, 100%, 50%)`;
}
circle(e.x, e.y, cor);
});
function circle(x, y, cor){
c.clearRect(0, 0, 500, 500)
c.beginPath();
c.arc(x, y, 30, 0, Math.PI*2);
c.fillStyle = cor;
c.lineWidth = 5;
c.strokeStyle = cor;
c.stroke();
c.fill()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment