Created
December 25, 2018 13:36
-
-
Save klaylton/edc8f393c92955059638629a180a5fce to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/zabexec
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"> | |
body { | |
margin: 0px; | |
padding: 0px; | |
} | |
</style> | |
</head> | |
<body> | |
<canvas id="myCanvas"></canvas> | |
<div></div> | |
<script id="jsbin-javascript"> | |
window.onload = function (){ | |
var canvas = document.getElementById('myCanvas'); | |
canvas.width = window.innerWidth; | |
canvas.height = window.innerHeight; | |
var context = canvas.getContext('2d'); | |
var centerX = canvas.width / 2; | |
var centerY = canvas.height / 2; | |
var radius = 50; | |
function circle(x, y){ | |
context.beginPath(); | |
context.arc(x, y, radius, 0, 2 * Math.PI, false); | |
context.fillStyle = 'green'; | |
context.fill(); | |
context.lineWidth = 5; | |
context.strokeStyle = '#003300'; | |
context.stroke(); | |
} | |
function rect(x, y){ | |
context.clearRect(0,0,canvas.width,canvas.height) | |
context.fillStyle = "blue"; | |
context.fillRect(x, y, 50, 50); | |
} | |
var walk = true; | |
var walkY = true; | |
var x = 0; | |
var y = 0; | |
function update(){ | |
if( walkY ) { | |
y+=5 | |
} else { | |
y-=5 | |
} | |
if( walk ) { | |
x+=5 | |
} else { | |
x-=5 | |
} | |
if( x+50 >= canvas.width || x <= 0 ) { | |
walk = !walk; | |
} | |
if ( y+50 >= canvas.height || y <= 0 ) { | |
walkY = !walkY; | |
} | |
document.querySelector("div").innerHTML = x | |
rect(x, y); | |
requestAnimationFrame(update) | |
}; | |
update() | |
} | |
</script> | |
<script id="jsbin-source-css" type="text/css">body { | |
margin: 0px; | |
padding: 0px; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">window.onload = function (){ | |
var canvas = document.getElementById('myCanvas'); | |
canvas.width = window.innerWidth; | |
canvas.height = window.innerHeight; | |
var context = canvas.getContext('2d'); | |
var centerX = canvas.width / 2; | |
var centerY = canvas.height / 2; | |
var radius = 50; | |
function circle(x, y){ | |
context.beginPath(); | |
context.arc(x, y, radius, 0, 2 * Math.PI, false); | |
context.fillStyle = 'green'; | |
context.fill(); | |
context.lineWidth = 5; | |
context.strokeStyle = '#003300'; | |
context.stroke(); | |
} | |
function rect(x, y){ | |
context.clearRect(0,0,canvas.width,canvas.height) | |
context.fillStyle = "blue"; | |
context.fillRect(x, y, 50, 50); | |
} | |
var walk = true; | |
var walkY = true; | |
var x = 0; | |
var y = 0; | |
function update(){ | |
if( walkY ) { | |
y+=5 | |
} else { | |
y-=5 | |
} | |
if( walk ) { | |
x+=5 | |
} else { | |
x-=5 | |
} | |
if( x+50 >= canvas.width || x <= 0 ) { | |
walk = !walk; | |
} | |
if ( y+50 >= canvas.height || y <= 0 ) { | |
walkY = !walkY; | |
} | |
document.querySelector("div").innerHTML = x | |
rect(x, y); | |
requestAnimationFrame(update) | |
}; | |
update() | |
} </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
body { | |
margin: 0px; | |
padding: 0px; | |
} |
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
window.onload = function (){ | |
var canvas = document.getElementById('myCanvas'); | |
canvas.width = window.innerWidth; | |
canvas.height = window.innerHeight; | |
var context = canvas.getContext('2d'); | |
var centerX = canvas.width / 2; | |
var centerY = canvas.height / 2; | |
var radius = 50; | |
function circle(x, y){ | |
context.beginPath(); | |
context.arc(x, y, radius, 0, 2 * Math.PI, false); | |
context.fillStyle = 'green'; | |
context.fill(); | |
context.lineWidth = 5; | |
context.strokeStyle = '#003300'; | |
context.stroke(); | |
} | |
function rect(x, y){ | |
context.clearRect(0,0,canvas.width,canvas.height) | |
context.fillStyle = "blue"; | |
context.fillRect(x, y, 50, 50); | |
} | |
var walk = true; | |
var walkY = true; | |
var x = 0; | |
var y = 0; | |
function update(){ | |
if( walkY ) { | |
y+=5 | |
} else { | |
y-=5 | |
} | |
if( walk ) { | |
x+=5 | |
} else { | |
x-=5 | |
} | |
if( x+50 >= canvas.width || x <= 0 ) { | |
walk = !walk; | |
} | |
if ( y+50 >= canvas.height || y <= 0 ) { | |
walkY = !walkY; | |
} | |
document.querySelector("div").innerHTML = x | |
rect(x, y); | |
requestAnimationFrame(update) | |
}; | |
update() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment