Skip to content

Instantly share code, notes, and snippets.

@egonelbre
Created October 28, 2011 07:44
Show Gist options
  • Save egonelbre/1321824 to your computer and use it in GitHub Desktop.
Save egonelbre/1321824 to your computer and use it in GitHub Desktop.
experimental image from code
// 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