noisybox blog
https://noisybox.net/images/favicon.ico
https://noisybox.net/images/profile_pic_200.png
© 2017 jason plumb / noisybox / infiltration lab.
2008-12-20T07:41:05.000Z
Jason Plumb
jason@noisybox.net
urn:uuid:75392340-704d-463f-9dc0-98b78c24a4bc
Learning Python by building image-pooping Markov chains
https://noisybox.net/blog/2008/12/learning_python_by_building_image_pooping_markov_chains
2008-12-20T07:41:05.000Z
<p>In my ongoing attempt to learn yet another utilitarian programming language, I have decided to pick up some <a href="http://www.python.org/">Python</a>. I'm only still scratching the surface (for example I haven't even touched python regular expressions yet, nor object persistence/marshalling), but I've managed to make a few toys. I often learn best by just diving in and doing, and I've come to enjoy stumbling through toy projects when learning a new language.</p>
<p>So I thought it would be interesting to see what kind of images I could create with a self-modifying, mutative <a href="http://en.wikipedia.org/wiki/Markov_chain">Markov chain</a>. While the results below aren't yet self-modifying, they're somewhat entertaining eye-candy that's probably been done hundreds of times before.</p>
<p><a href="http://noisybox.net/blog/images/200812mkv/mkv_00294879.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_00294879_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_01174319.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_01174319_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_16019421.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_16019421_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_21103684.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_21103684_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_21404725.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_21404725_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_21411251.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_21411251_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_25136828.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_25136828_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_25573795.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_25573795_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_30463790.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_30463790_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_34642315.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_34642315_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_58100696.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_58100696_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_60252644.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_60252644_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_61193764.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_61193764_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_70404383.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_70404383_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_71999801.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_71999801_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_75234506.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_75234506_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_77991590.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_77991590_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_83478400.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_83478400_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_87915004.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_87915004_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_91808825.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_91808825_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_93268553.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_93268553_th.png" alt="image"></a>
<a href="http://noisybox.net/blog/images/200812mkv/mkv_99965624.png"><img src="http://noisybox.net/blog/images/200812mkv/mkv_99965624_th.png" alt="image"></a></p>
<p>I'm using the <a href="http://www.pythonware.com/products/pil/">Python Imaging Lirbary (PIL)</a> to create/paint the images. Sure, it's pretty well documented and intuitive, but doesn't immediatly support drawing with alpha transparency, which is a real bummer. There is at least one other drawing toolkit that does alpha, and one that does that with opengl. It would be nice to render these in realtime, but the current incantation seems to take about a second to do about 54k 2d polygons, which isn't exactly fast. I'm also not yet sure how much of that time is spent in python versus actual Tk rendering.</p>
<p>I'm now mostly interested in switching drawing toolkits to support alpha, doing marshalling to save/restore interesting chains, and coming up with interesting strategies of self-modification. The current models are very linear, and it might be nice to have a little abstraction that allows nonlinear curving to happen more seamlessly.</p>
<p>I'll probably share the code after I continue to learn from my mistakes and make things more better.</p>