Created
October 28, 2011 07:44
-
-
Save egonelbre/1321824 to your computer and use it in GitHub Desktop.
experimental image from code
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
// http://www.reddit.com/r/programming/comments/lrg7f/experimental_images_from_very_short_programs/ | |
function start() { | |
var t = pt = 0; | |
clearTimeout(timer); | |
var func = ""+ | |
"function animate() {" + | |
" var x = y = pi = 0, W = w, S = size; " + | |
" for (var i = 0; i < S;) { " + | |
" img.data[i] = <code>; i++; t++; " + | |
" img.data[i] = <code>; i++; t++; " + | |
" img.data[i] = <code>; i++; t++; " + | |
" img.data[i] = 255; i++; t++; " + | |
" x++; pi++; pt++; " + | |
" if ( x == W ) { x = 0; y++; }" + | |
" }" + | |
" <post>;" + | |
" ctx.putImageData(img, 0, 0);" + | |
" timer = setTimeout(animate, 0);" + | |
"}"; | |
func = func.replace( /<code>/g, codebox.value ); | |
if ( inc.checked ) | |
func = func.replace( /<post>/g, "pt++; t++;" ); | |
else | |
func = func.replace( /<post>/g, "t=0;" ); | |
eval( func ); | |
animate(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment