Created
November 13, 2015 14:15
-
-
Save anonymous/4fb98465efc30931c567 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/koyoqiyuti
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 characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
html, body { | |
height: 100%; | |
margin: 0; | |
} | |
</style> | |
</head> | |
<body> | |
<canvas id="canvas"></canvas> | |
<script id="jsbin-javascript"> | |
var canvas = document.querySelector('#canvas'), | |
ctx = canvas.getContext('2d'); | |
var w = 4, | |
h = 3; | |
canvas.width = w; | |
canvas.height = h; | |
for (var i = 0; i < w * h; i++) { | |
var y = Math.floor(i / w), | |
x = i % w, | |
fill; | |
if (y == 1 || x == 1) { | |
fill = '#ccc'; | |
} else { | |
fill = 'white'; | |
} | |
ctx.fillStyle = fill; | |
ctx.fillRect(x, y, 1, 1); | |
} | |
var url = canvas.toDataURL('image/png'); | |
var style = 'url(\'' + url + '\') no-repeat cover'; | |
var bs = document.querySelector('body').style; | |
bs.backgroundImage = 'url(' + url + ')'; | |
bs.backgroundRepeat = 'no-repeat'; | |
bs.backgroundSize = 'cover'; | |
bs.backgroundPosition = '50% 50%'; | |
</script> | |
<script id="jsbin-source-css" type="text/css">html, body { | |
height: 100%; | |
margin: 0; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var canvas = document.querySelector('#canvas'), | |
ctx = canvas.getContext('2d'); | |
var w = 4, | |
h = 3; | |
canvas.width = w; | |
canvas.height = h; | |
for (var i = 0; i < w * h; i++) { | |
var y = Math.floor(i / w), | |
x = i % w, | |
fill; | |
if (y == 1 || x == 1) { | |
fill = '#ccc'; | |
} else { | |
fill = 'white'; | |
} | |
ctx.fillStyle = fill; | |
ctx.fillRect(x, y, 1, 1); | |
} | |
var url = canvas.toDataURL('image/png'); | |
var style = 'url(\'' + url + '\') no-repeat cover'; | |
var bs = document.querySelector('body').style; | |
bs.backgroundImage = 'url(' + url + ')'; | |
bs.backgroundRepeat = 'no-repeat'; | |
bs.backgroundSize = 'cover'; | |
bs.backgroundPosition = '50% 50%';</script></body> | |
</html> |
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 characters
html, body { | |
height: 100%; | |
margin: 0; | |
} |
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 characters
var canvas = document.querySelector('#canvas'), | |
ctx = canvas.getContext('2d'); | |
var w = 4, | |
h = 3; | |
canvas.width = w; | |
canvas.height = h; | |
for (var i = 0; i < w * h; i++) { | |
var y = Math.floor(i / w), | |
x = i % w, | |
fill; | |
if (y == 1 || x == 1) { | |
fill = '#ccc'; | |
} else { | |
fill = 'white'; | |
} | |
ctx.fillStyle = fill; | |
ctx.fillRect(x, y, 1, 1); | |
} | |
var url = canvas.toDataURL('image/png'); | |
var style = 'url(\'' + url + '\') no-repeat cover'; | |
var bs = document.querySelector('body').style; | |
bs.backgroundImage = 'url(' + url + ')'; | |
bs.backgroundRepeat = 'no-repeat'; | |
bs.backgroundSize = 'cover'; | |
bs.backgroundPosition = '50% 50%'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment