//Adding a multiplier of 5 to visually see this better.
setTimeout(function () {
(function (a, b, c) {
//setting canvas width
c.width = b * 5;
//get context 2d of canvas
t = c.getContext('2d');
//setting storke style.
t.strokeStyle = 'black';
//looping from a to b
//for (var z = a; z <= b; z++) {
var i = a;
var si = setInterval(function(){
if(i > b){
clearInterval(si);
alert('stopping');
}
//calculating A(i) and converting it to a binary string
g = (Math.floor(((i * i) + 6 * i * (i % 2) + 24) / 48) >>> 0).toString(2);
//looping through that string
for (j = 0; j < g.length; j++) {
//since canvas is upside down and the first digit is actually the last digit:
if (g[g.length - 1 - j] == '1') {
//we create the 1 by 1 rect
t.rect((i - a) * 5, j * 5, 5, 5);
//we draw the rect
t.fill();
}
}
i++;
}, 500);
//}
//we append everything to the body
document.body.appendChild(c);
//parameters are put here
})(0, 300, document.createElement('canvas'));
}, 0);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.