Skip to content

Instantly share code, notes, and snippets.

Created November 13, 2015 14:15
Show Gist options
  • Save anonymous/4fb98465efc30931c567 to your computer and use it in GitHub Desktop.
Save anonymous/4fb98465efc30931c567 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/koyoqiyuti
<!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>
html, body {
height: 100%;
margin: 0;
}
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