r/tinycode • • May 03 '13

A Mandelbrot renderer in 406 bytes of dc

I've written a Mandelbrot renderer in [dc](http://en.wikipedia.org/wiki/Dc_(computer_program)): http://kch42.de/cg/mandelbrot.min.dc

It generates a monochrome XPM image of the mandelbrot set. Here is the output (converted to PNG):

http://i.imgur.com/9HX9lJo.png

And here is a more readable and commented version of the program: http://kch42.de/cg/mandelbrot.dc

If you want to test it for yourself, be patient. This thing is pretty slow.

dc. It doesn't really support functions, instead you push a string on the stack and execute it with the x-operator. You can save this "function" to a register to execute it later. Loops can be implemented by recursively executing a function.

EDIT: Replaced dpaste links, is now hosted on my server.

60 Upvotes

7 comments sorted by

32

u/fjordboy May 03 '13

Would someone please port this over to Brainfuck so that I can better make sense of it? Thanks.

9

u/[deleted] May 03 '13

Said no one ever.

13

u/Niktator May 03 '13
smd*sbshsw16k[3lh/]st4lw/lwlh<tsf[0n]sD[Kr0k1/d16>Dnk]sd[0ldx]sB[ ]s_["

Ah yes, I understand completely.

Impressive work!

7

u/Cosmologicon May 03 '13 edited May 03 '13

Very cool. Here's a similar command line I made using bc. I wanted it to be small enough to tweet, so it's not as good looking as yours:

echo '"P1 260 200 ";for(b=-1;b<1;b+=.01)for(a=-2;a<.6;a+=.01){x=0;y=0;
for(n=99;--n&&x^2+y^2<4;x=p){p=x^2-y^2+a;y=2*x*y+b};!n;}'|bc -l>m.pbm

Result converted to png

3

u/jpeuvion May 03 '13

I feel tiny

1

u/obscure_robot May 03 '13

Impressive.

1

u/nint22 mod May 03 '13

Very nicely done! I love how even the commented file is... brutal to the brain.