Generate a mandelbrot fractal
Assuming machine code counts, I wrote a prod a while back that generates a 320x200 color Mandelbrot in 64 bytes - http://www.pouet.net/prod.php?which=53287
Here is the code:
; "Microbrot" by Sir_Lagsalot
org 100h
mov al,13h
int 10h
les ax,[bx]
FillLoop:
cwd
mov ax,di
mov cx,320
div cx
sub ax,100
dec dh
xor bx,bx
xor si,si
MandelLoop:
mov bp,si
imul si,bx
add si,si
imul bx,bx
jo MandelBreak
imul bp,bp
jo MandelBreak
add bx,bp
jo MandelBreak
sub bx,bp
sub bx,bp
sar bx,6
add bx,dx
sar si,6
add si,ax
loop MandelLoop
MandelBreak:
xchg ax,cx
stosb
jmp FillLoop
Compiled version in base64:
sBPNEMQHmYn4uUAB9/GD6GT+zjHbMfaJ9Q+v8wH2D6/bcBkPr+1wFAHrcBAp6ynrwfsGAdPB/gYBxuLbkarrxg==
C, 988 chars
Here's mine, which does an ASCII mandelbrot, written as an ASCII mandelbrot, in C.
Oh.. and it also has interactive zoom functionality. (press the keypad numbers 1-9 to zoom in on the respective area)
int main(int argc, char* argv[]){ unsigned
char c='r';double x1,y,y1,t=0,q=78,r=22,x,
x2,y2,a,b,v;do{(c=='r')?(y2=-(y1=-1.6),x1=
-2.0f,x2=0.8):(c=='?')? c=0, printf("%f\
,%f:%f,%f",x1,y1,x2,y2):(c <':'&&c>48)
?x=x1,y=y1,*(c>'3'&&c<':' ?&y1: &t)
+=(y2-y1)/3,*(c>'6'&&c< ':'?&y1
:&t)+=(y2-y1)/3, *((c == '8'
||c+3=='8'||c+3 +3== '8'?&x1
:&t))+=(x2-x1 )/ 3,*((c
=='9'||c+3== '9'||c
+6=='9' ?&x1: &t)
)+=2*(x2-x1) /3,x2=
x1+(x2-x)/3, y2 =y1+(
y2-y)/3:(c=0);for(y= y2;y>=
y1&&c;c=1,y-=(y2-y1)/r, putchar
('\n')) for(x=x1;x<=x2; x+=(x2-
x1)/q){a=b=c=0; while ( ++c&&(a=(t
=a)*a)<4&&(v=b*b)<4)a-=v-x ,b=y+b*2*t;
putchar("#@XMW*N&KPBQYKG$R" "STEEVxHOUV"
"CT()[]%JL={}eou?/\\|Ili+~<>_-^\"!;:`,. "[
c?c>>2:63]);}} while((c=getchar ())!='x');
return 0;/* Mandelbrot - S.Goodwin.2001*/}
Originally posted here http://marquisdegeek.com/rnd_obs.php
Common lisp -- 195 chars
(loop for y from -1 to 1 by 1/15 do
(loop for x from -2 to 1 by .04 do
(let*((c 126) (z (complex x y)) (a z))
(loop while (< (abs (setq z (+ (* z z) a))) 2)
while (> (decf c) 32))
(princ (code-char c))))
(terpri))
Tested with sbcl and clisp. Result:
~~~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}||||||||{{{zyvrwum{|||||}}}}}}~~~~~~~~~~~~~
~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}|||||||||{{{zyxvptwyz{{|||||}}}}}}~~~~~~~~~~~
~~~~~~~~~}}}}}}}}}}}}}}}}}}}}|||||||||{{{{zwLtb huwx{{{{||||}}}}}}}~~~~~~~~~
~~~~~~~~}}}}}}}}}}}}}}}}}}}|||||||||{{zzzyxvn Knwyz{{{{||||}}}}}}~~~~~~~~
~~~~~~~}}}}}}}}}}}}}}}}}}||||||||{{zzzzyyywuk qwxyzzzz{{|||}}}}}}~~~~~~~
~~~~~}}}}}}}}}}}}}}}}}}|||||||{{{zxjnpwwtjsqpi lqrujnxyyxrz{|}}}}}}}}~~~~~
~~~~}}}}}}}}}}}}}}}}}|||||{{{{{zzzxt> qf pttfqeqz{|}}}}}}}}~~~~
~~~~}}}}}}}}}}}}}}}|||{{{{{{{{zzzxwup sxz{||}}}}}}}~~~~
~~~}}}}}}}}}}}}|||{z{{{{{{{zzzzywkmo rwyz{{||}}}}}}}~~~
~~}}}}}}}}}||||{{zwvyyyyyyyyyyyxvsP swvz{||}}}}}}}}~~
~~}}}}|||||||{{{zzwrtsww^uwwxxwvr iz{|||}}}}}}}~~
~}}}|||||||{{{{{zyxws mj Ubhuutl sxz{|||}}}}}}}}~
~}||||||||{{{{{zyytun qq avz{|||}}}}}}}}~
~|||||||{{zzzyxsvvum j Sz{{|||}}}}}}}}~
~{{{{{yyzzzyyxwtbUP qyz{{||||}}}}}}}~
~ pvxyz{{||||}}}}}}}}
~{{{{{yyzzzyyxwtbUP qyz{{||||}}}}}}}~
~|||||||{{zzzyxsvvum j Sz{{|||}}}}}}}}~
~}||||||||{{{{{zyytun qq avz{|||}}}}}}}}~
~}}}|||||||{{{{{zyxws mj Ubhuutl sxz{|||}}}}}}}}~
~~}}}}|||||||{{{zzwrtsww^uwwxxwvr iz{|||}}}}}}}~~
~~}}}}}}}}}||||{{zwvyyyyyyyyyyyxvsP swvz{||}}}}}}}}~~
~~~}}}}}}}}}}}}|||{z{{{{{{{zzzzywkmo rwyz{{||}}}}}}}~~~
~~~~}}}}}}}}}}}}}}}|||{{{{{{{{zzzxwup sxz{||}}}}}}}~~~~
~~~~}}}}}}}}}}}}}}}}}|||||{{{{{zzzxt> qf pttfqeqz{|}}}}}}}}~~~~
~~~~~}}}}}}}}}}}}}}}}}}|||||||{{{zxjnpwwtjsqpi lqrujnxyyxrz{|}}}}}}}}~~~~~
~~~~~~~}}}}}}}}}}}}}}}}}}||||||||{{zzzzyyywuk qwxyzzzz{{|||}}}}}}~~~~~~~
~~~~~~~~}}}}}}}}}}}}}}}}}}}|||||||||{{zzzyxvn Knwyz{{{{||||}}}}}}~~~~~~~~
~~~~~~~~~}}}}}}}}}}}}}}}}}}}}|||||||||{{{{zwLtb huwx{{{{||||}}}}}}}~~~~~~~~~
~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}|||||||||{{{zyxvptwyz{{|||||}}}}}}~~~~~~~~~~~
~~~~~~~~~~~~~}}}}}}}}}}}}}}}}}}}}||||||||{{{zyvrwum{|||||}}}}}}~~~~~~~~~~~~~
Slightly modified from B. Clementson blog.