Created
December 24, 2018 04:08
-
-
Save klaylton/f36b91851fb15bd45562cea8bbf326df to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/witoned
This file contains 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 characters
<!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> |
This file contains 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 characters
canvas{ | |
border: 1px solid red; | |
} |
This file contains 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 characters
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