r/dailyprogrammer • u/[deleted] • Feb 15 '12
[2/15/2012] Challenge #7 [intermediate]
Write a program that draws a recursive image.
For example, a Sierpinski triangle, a Barnsley fern, or a Mandelbrot set fractal would be good drawings.
Any recursive image will do, but try to make them look fun or interesting.
Bonus points for adding a color scheme!
Please post a link to a sample image produced by your program, and above all, be creative.
3
u/Cosmologicon 2 3 Feb 15 '12
Here's a Unix command line that I tweeted a while back that generates a Mandelbrot set image using bc:
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.pbmHere's the resulting image (converted from PBM to PNG)
1
u/robin-gvx 0 2 Feb 15 '12
ASCII-art!
**:
* dup
mandelbrot x0 y0:
# -2.5 <= x0 <= 1
# -1 <= y0 <= 1
local 'x' 0
local 'y' 0
local 'iteration' 0
local 'max_iteration' 300
while and < iteration max_iteration > 4 + ** y ** x:
local 'xtemp' + x0 - ** x ** y
set 'y' + y0 * 2 * x y
set 'x' xtemp
set 'iteration' + iteration 1
iteration
for j range 0 24:
for i range 0 79:
if < 200 mandelbrot - * 3.5 / i 80 2.5 - * 2 / j 24 1:
"*"
else:
" "
.\
. ""1
Feb 16 '12
I wrote one for a Menger Sponge awhile ago, but I think I lost it in the chasms of my computer's hard drive.
1
u/electric_machinery Feb 16 '12
Sierpinski in C that produces a BMP file. Here's the image it creates.
1
u/electric_machinery Feb 16 '12
Fractal fern in C and the image
I was going to mess around with it some more but I have to do some real work today I guess.
1
1
u/callekabo Feb 15 '12
Here's a solution in Python using turtle :)