Created
September 21, 2012 16:40
-
-
Save nazomikan/3762540 to your computer and use it in GitHub Desktop.
Processing division
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
(function () { | |
var queue; | |
queue = createQueue(0, 0, 100, 100, 25, function (xMin, yMin, xMax, yMax) { | |
var x, y; | |
for (x = xMin; x < xMax; x++) { | |
for (y = yMin; y < yMax; y++) { | |
// do someThing | |
} | |
} | |
}); | |
// lazy output | |
(function lazyLoop(i) { | |
var task = queue[i++]; | |
task(); | |
if (i < queue.length) { | |
setTimeout(function () { | |
lazyLoop(i); | |
}, 50); | |
} | |
}(0)); | |
function createQueue(startW, startH, endW, endH, delta, callback) { | |
var queue = [], startX, startY, endX, endY, updateY; | |
for (startY = startH, endY = endH; startY < endY; startY) { | |
for (startX = startW, endX = endW; startX < endX; startX) { | |
let x = startX, | |
y = startY, | |
xz = ((endW < startX + delta) ? endW : startX + delta), | |
yz = ((endH < startY + delta) ? endH : startY + delta); | |
updateY = yz; | |
queue.push(function () { | |
callback(x, y, xz, yz); | |
}); | |
startX = xz; | |
} | |
startY = updateY; | |
} | |
return queue; | |
/* | |
return [ | |
function () { | |
callback(0, 0, 25, 25); | |
}, | |
function () { | |
callback(25, 0, 50, 25); | |
}, | |
function () { | |
callback(50, 0, 75, 25); | |
}, | |
function () { | |
callback(75, 0, 100, 25); | |
}, | |
function () { | |
callback(0, 25, 25, 50); | |
}, | |
function () { | |
callback(25, 25, 50, 50); | |
}, | |
function () { | |
callback(50, 25, 75, 50); | |
}, | |
function () { | |
callback(75, 25, 100, 50); | |
}, | |
function () { | |
callback(0, 50, 25, 75); | |
}, | |
function () { | |
callback(25, 50, 50, 75); | |
}, | |
function () { | |
callback(50, 50, 75, 75); | |
}, | |
function () { | |
callback(75, 50, 100, 75); | |
}, | |
function () { | |
callback(0, 75, 25, 100); | |
}, | |
function () { | |
callback(25, 75, 50, 100); | |
}, | |
function () { | |
callback(50, 75, 75, 100); | |
}, | |
function () { | |
callback(75, 75, 100, 100); | |
} | |
]; | |
*/ | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment