Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

I always used a Mandelbrot image as the 'graphical' version of Hello World in any graphical application I got my hands on. Now it's your guys' turn.

  • Language must be capable of graphical output or drawing charts (saving files disallowed)
  • Render a square image or graph. The size at least 128 and at most 640 across*
  • The fractal coordinates range from approximately -2-2i to 2+2i
  • The pixels outside of the Mandelbrot set should be colored according to the number of iterations before the magnitude exceeds 2 (excluding* black & white)
  • Each iteration count must have a unique color*, and neighboring colors should preferably be easily distinguishable by the eye
  • The other pixels (presumably inside the Mandelbrot set) must be colored either black or white
  • At least 99 iterations
  • ASCII art not allowed

*) unless limited by the platform, e.g. graphical calculator

Allowed:
enter image description here
Disallowed:
enter image description here
(shrunken images)

Winning conditions:
Shortest version (size in bytes) for each language will get a mention in this post, ordered by size.
No answer will ever be 'accepted' with the button.

share|improve this question
2  
"Easily distinguished by the eye" is hard to make objective. ...Also, apart from your personal association of the two, the Mandelbrot set has nothing to do with Hello World, so it's best to omit that from the title unless you are deliberately trolling the search engines. –  Jonathan Van Matre 2 days ago
 
I'm just trying to discourage using sequential rgb indices. Thx about the title. I forgot to double-check that after finishing writing. –  Mark Jeronimus 2 days ago
1  
Related: ASCII Mandelbrot (although some of the answers posted there aren't ASCII and could probably fit better as answers to this question). –  Peter Taylor 2 days ago
 
Why do you require that neighboring colors be easily distinguishable? Making them vary continuously (but still be distinct) is actually much harder. –  Charles Staats yesterday
 
I've seen a few people now mentioning that they render the Mandelbrot as a "Hello World". I've done that too, for something like 30 years. The Mandelbrot is the perfect "Hello World" because it shows both that you have pixel access to the display and gives a good feel for compute bound performance on the new platform. –  Roger Dahl 20 hours ago
add comment

19 Answers

Sharp EL-9300 Graphics Calculator, 296 bytes

This was my secondary school graphing calculator, getting on for 20 years ago! I remember writing a mandelbrot generator for it way back then. And sure enough, its still sitting there in the NV memory:

ClrG
DispG
Range -2.35,2.35,.5,-1.55,1.55,0.5
y=-1.55
Label ly
x=-2.35
Label lx
n=1
zx=0
zy=0
Label ln
tzx=zx²-zy²+x
zy=(2*zx*zy)+y
zx=tzx
If zx²+zy²>4Goto esc
n=n+1
If n<20Goto ln
Label esc
If fpart (n/2)=0Goto npl
Plot x,y
Label npl
x=x+.05
If x<=2.35Goto lx
y=y+.05
If y<=1.55Goto ly
Wait

It took about 90 minutes to render.

This is totally ungolfed. I'm sure I could save a bit of space, but I just wanted to share this historical curiosity!

I love that the only control statements available are gotos.

Here's a photo. I don't have any other means to get the graphical output out: enter image description here

share|improve this answer
 
Me too, but my NV memory went blank after years of shelf-time. –  Mark Jeronimus yesterday
 
zx²+zy²>4 couldn't that be Abs(x)>2? –  Mark Jeronimus yesterday
 
Maybe you should get a new battery... –  NothingsImpossible yesterday
 
I had a program just like that on my old TI-95, it took about 2 hours to run. Unfortunately, I no longer have that old calculator... –  Mark Ormston yesterday
 
Interesting. So you've been a nerd for quite a while. –  devnull 19 hours ago
show 6 more comments

LaTeX, 673 bytes

\countdef\!1\!129\documentclass{article}\usepackage[margin=0pt,papersize=\!bp]{geometry}\usepackage{xcolor,pgf}\topskip0pt\offinterlineskip\def~{99}\let\rangeHsb~\countdef\c2\countdef\d3\countdef\e4\begin{document}\let\a\advance\let\p\pgfmathsetmacro\makeatletter\def\x#1#2#3{#10
\@whilenum#1<#2\do{#3\a#11}}\d0\x\c{\numexpr~+1}{\expandafter\edef\csname\the\c\endcsname{\hbox{\noexpand\color[Hsb]{\the\d,1,1}\/}}\a\d23
\ifnum\d>~\a\d-~\fi}\def\/{\rule{1bp}{1bp}}\x\c\!{\hbox{\x\d\!{\p\k{4*\d/(\!-1)-2}\p\K{2-4*\c/(\!-1)}\def\z{0}\def\Z{0}\x\e~{\p\:{\z*\z-\Z*\Z+\k}\p\Z{2*\z*\Z+\K}\let\z\:\p\:{\z*\z+\Z*\Z}\ifdim\:pt>4pt\csname\the\e\endcsname\e~\fi}\ifnum\e=~\/\fi}}}\stop

Result 129x129 (129 × 129)

The PDF image consists of colored square units with size 1bp × 1bp.

Ungolfed

% count register \size contains the width and height of the square
\countdef\size=1
\size=31
\documentclass{article}
\usepackage[margin=0pt,papersize=\size bp]{geometry}
\usepackage{xcolor,pgf}
\topskip0pt
\offinterlineskip
\def\iterations{99}
\let\rangeHsb\iterations
\countdef\c2
\countdef\d3
\countdef\e4
\begin{document}
\let\p\pgfmathsetmacro
\makeatletter
% \Loop: for (#1 = 0; #1 < #2; #1++) {#3}
\def\Loop#1#2#3{%
  #1=0
  \@whilenum#1<#2\do{#3\advance#11}%
}
\d0%
\Loop\c{\numexpr\iterations+1\relax}{%
  \expandafter\edef\csname\the\c\endcsname{%
    \hbox{\noexpand\color[Hsb]{\the\d,1,1}\noexpand\pixel}%
  }%
  \advance\d23 \ifnum\d>\iterations\advance\d-\iterations\fi
}
\def\pixel{\rule{1bp}{1bp}}
% \c: row
% \d: column
% \e: iteration
\Loop\c\size{%
  \typeout{c: \the\c}%
  \hbox{%
    \Loop\d\size{%
      \pgfmathsetmacro\k@re{4*\d/(\size-1)-2}%
      \pgfmathsetmacro\K@im{2-4*\c/(\size-1)}%
      \def\z@re{0}%
      \def\Z@im{0}%
      \Loop\e\iterations{%
         % calculate z(n+1) = z^2(n) + k
         \pgfmathsetmacro\temp{\z@re*\z@re-\Z@im*\Z@im+\k@re}%
         \pgfmathsetmacro\Z@im{2*\z@re*\Z@im+\K@im}%
         \let\z@re\temp
         % calculate abs(z)^2
         \pgfmathsetmacro\temp{\z@re*\z@re+\Z@im*\Z@im}%
         \ifdim\temp pt>4pt\csname\the\e\endcsname\e\iterations\fi
      }%   
      \ifnum\e=\iterations\pixel\fi
    }%
  }%
}
\stop
share|improve this answer
add comment

I came across this the other day. I don't take credit for it, but damn, is it awesome:

Python:

_                                      =   (
                                        255,
                                      lambda
                               V       ,B,c
                             :c   and Y(V*V+B,B,  c
                               -1)if(abs(V)<6)else
               (              2+c-4*abs(V)**-0.4)/i
                 )  ;v,      x=1500,1000;C=range(v*x
                  );import  struct;P=struct.pack;M,\
            j  ='<QIIHHHH',open('M.bmp','wb').write
for X in j('BM'+P(M,v*x*3+26,26,12,v,x,1,24))or C:
            i  ,Y=_;j(P('BBB',*(lambda T:(T*80+T**9
                  *i-950*T  **99,T*70-880*T**18+701*
                 T  **9     ,T*i**(1-T**45*2)))(sum(
               [              Y(0,(A%3/3.+X%v+(X/v+
                               A/3/3.-x/2)/1j)*2.5
                             /x   -2.7,i)**2 for  \
                               A       in C
                                      [:9]])
                                        /9)
                                       )   )

enter image description here http://preshing.com/20110926/high-resolution-mandelbrot-in-obfuscated-python/

share|improve this answer
5  
Seems to be disallowed: the regions are not easily distinguishable, or even at all. –  primo yesterday
3  
Also, this writes to a file. –  Lie Ryan yesterday
3  
disallowed or not, this is pretty awesome :D –  Navin 20 hours ago
1  
+1 for the most beautiful output –  DigitalTrauma 18 hours ago
 
@DigitalTrauma I guess we'd see more of this output if it was allowed. –  Eelvex 2 hours ago
add comment

Java - 505...383 370

Just a standard calculation, with golfitude added.

mandelbrot-java

Golfed:

public class M{public static void main(String[]v){int n=640,t,s,i=n*n;final BufferedImage z=new BufferedImage(n,n,1);Frame f=new Frame(){public void paint(Graphics g){g.drawImage(z,0,28,null);}};for(f.setSize(n,668);--i>0;z.setRGB(i/n,i%n,s*820)){float c=4f/n,a=c*i/n-2,b=i%n*c-2,r=a,e=b,p;for(s=t=99;t-->0&&r*r+e*e<4;s=t,p=r*r-e*e+a,e=r*e*2+b,r=p);}f.setVisible(1>0);}}

With line breaks:

public class M{
    public static void main(String[]v){
        int n=640,t,s,i=n*n;
        final BufferedImage z=new BufferedImage(n,n,1);
        Frame f=new Frame(){
            public void paint(Graphics g){
                g.drawImage(z,0,28,null);
            }
        };      
        for(f.setSize(n,668);--i>0;z.setRGB(i/n,i%n,s*820)){
            float c=4f/n,a=c*i/n-2,b=i%n*c-2,r=a,e=b,p;
            for(s=t=99;t-->0&&r*r+e*e<4;s=t,p=r*r-e*e+a,e=r*e*2+b,r=p);
        }
        f.setVisible(1>0);
    }
}
share|improve this answer
 
f.setSize(n,668); - depends heavily on the used Theme, but I'll accept it. –  Mark Jeronimus yesterday
 
You can drop the imports in Java because they're auto-generated anyway. –  Mark Jeronimus yesterday
 
I also see double where float could be used if you tried –  Mark Jeronimus yesterday
 
JFrame => Frame shaves off 2 chars. Although you can't close the window anymore. ;) –  EthanB yesterday
 
@MarkJeronimus Thanks for the advice, especially about imports. New to golf, so it helps. I'll be coming back to this later today, had to get some sleep ;) –  Geobits yesterday
add comment

x86 DOS Assembly - 208 177

The full binary, in HEX, is:

9BDBE3BE0010B81300CD106800A007BF87F9FDBAC7008BCAE81A008AC3AA4979F7B9C70083EF784A79EE33C0CD16B80300CD10CD208BC12D640089441CDF441CDF06AB01DEF9D95C088BC22D640089441CDF441CDF06AB01DEF9D95C0CD9EED914D95404D95410D95C14B301D904D84C04DE0EAD01D8440CD95404D94410D86414D84408D914D80CD95C10D84C04D95414D84410DF06AF01DED99BDFE09B9E7209FEC380FBC872C432DBC3320002000400

The sample image is:

Mandlebrot screen shot with black cropped

The full source in readable ASM is fairly long. I have put it up at: Full Source

This is designed for compiling with TASM, runs in MCGA, and waits for a keypress before ending the program. The colors are just the default MCGA palette.

EDIT: Optimized it, now it draws backwards (same image though), and saved 31 bytes!

share|improve this answer
 
Someone had edited my response to say you can use Python to create the file (I guess if you don't have a hex editor). I don't use Python, but their method was: python.exe -c "open('mandel.exe', 'wb').write('[ Paste Hex Here ]'.decode('hex_codec'))" –  Mark Ormston 14 hours ago
add comment

Mathematica 214 191 215

Back to Black

My earlier submission did not meet the requirement to leave the inside all black (or white). This does.

m=Compile[{{c,_Complex}},Length[FixedPointList[#^2+c&,0,99,SameTest→(Abs@#>=2&)]]];
ArrayPlot[Table[m[a+I b],{b,-2,2,.01},{a,-2,2,.01}],DataRange→{{-2,2},{-2,2}},
ColorRules→{100→Black},ColorFunction→(Hue[Log[34,#]]&)]

green

share|improve this answer
 
{b, -2, 2, .01}, {a, -2, 2, .01} is shorter and closer to the rules –  Mark Jeronimus yesterday
 
@MarkJeronimus Thanks. I used the suggested range for the iterating picture. –  David Carraher yesterday
 
You had it almost right, then you made the inside non-black. The last frame in the GIF is black inside and an allowed answer. EDIT: and I count 195 bytes. –  Mark Jeronimus yesterday
 
I missed the point about being black. The count increased because some single characters became two characters in the cut-and-paste to SE. –  David Carraher yesterday
add comment

Javascript (ECMAScript 6) - 315 Characters

document.body.appendChild(e=document.createElement("canvas"));v=e.getContext("2d");i=v.createImageData(e.width=e.height=n=600,n);j=0;k=i.data;f=r=>k[j++]=(n-c)*r%256;for(y=n;y--;)for(x=0;x++<n;){c=s=a=b=0;while(c++<n&&a*a+b*b<5){t=a*a-b*b;b=2*a*b+y*4/n-2;a=t+x*4/n-2}f(87);f(0);f(0);k[j++]=255}v.putImageData(i,0,0)

Default Output

JSFIDDLE - Requires Firefox (as the only browser to have, so far, implemented ECMAScript 6 arrow functions)

  • Change n to vary the image size (and number of iterations).
  • Change the values passed in the f(87);f(0);f(0); calls (near the end) to change the RGB colour values. (f(8);f(8);f(8); is greyscale.)

With f(8);f(23);f(87);:

enter image description here

share|improve this answer
add comment

R, 199 211 characters

Old solution at 199 characters:

r=seq(-2,2,l=500);c=t(sapply(r,function(x)x+1i*r));d=z=array(0,dim(c));a=1:25e4;for(i in 1:99){z[a]=c[a]+z[a]^2;s=abs(z[a])<=2;d[a[!s]]=i;a=a[s]};image(d,b=0:99,c=c(1,sample(rainbow(98))),ax=F,asp=1)

With indentation:

r=seq(-2,2,l=500)
c=t(sapply(r,function(x)x+1i*r)) #Produces the initial imaginary number matrix
d=z=array(0,dim(c)) #empty matrices of same size as c 
a=1:25e4            #(z will store the magnitude, d the number of iterations before it reaches 2)
for(i in 1:99){     #99 iterations
    z[a]=c[a]+z[a]^2
    s=abs(z[a])<=2
    d[a[!s]]=i
    a=a[s]
    }
image(d,b=0:99,c=c(1,sample(rainbow(98))),ax=F,asp=1) #Colors are randomly ordered (except for value 0)

enter image description here

Edit: Solution at 211 characters that colors the inside of the set and the outside of the first layer differently:

r=seq(-2,2,l=500);c=t(sapply(r,function(x)x+1i*r));d=z=array(0,dim(c));a=1:25e4;for(i in 1:99){z[a]=c[a]+z[a]^2;s=abs(z[a])<=2;d[a[!s]]=i;a=a[s]};d[a[s]]=-1;image(d,b=-1:99,c=c(1:0,sample(rainbow(98))),ax=F,asp=1)

With indentation:

r=seq(-2,2,l=500)
c=t(sapply(r,function(x)x+1i*r))
d=z=array(0,dim(c))
a=1:25e4
for(i in 1:99){
    z[a]=c[a]+z[a]^2
    s=abs(z[a])<=2
    d[a[!s]]=i
    a=a[s]
    }
d[a[s]]=-1 #Gives the inside of the set the value -1 to differenciate it from value 0.
image(d,b=-1:99,c=c(1,sample(rainbow(99))),ax=F,asp=1)

enter image description here

share|improve this answer
 
technically black on the outside is disallowed. Did you miss that or is it difficult to implement? –  Mark Jeronimus yesterday
 
@MarkJeronimus both actually :) I'll try to have a look of how to do that but i m not 100% confident that I ll find a way to do that cleanly. –  plannapus yesterday
 
@MarkJeronimus Done! –  plannapus yesterday
 
Second place in the hideous colors division. –  meawoppl 12 hours ago
add comment

Python w/ PIL - 166 bytes

import Image
d=600;i=Image.new('RGB',(d,d))
for x in range(d*d):
 z=o=x/9e4-2-x%d/150.j-2j;c=99
 while(abs(z)<2)*c:z=z*z+o;c-=1
 i.putpixel((x/d,x%d),5**8*c)
i.show()

Output (will open in the default *.bmp viewer):

share|improve this answer
1  
You can shave off 3 if you get rid of the y loop. r=range(d*d), use x/d and x%d for x and y. –  Geobits yesterday
 
@Geobits the idea actually saved 10, thanks! –  primo yesterday
1  
Complex types can be initialized like: c=1+2j, which I think would save you a couple characters with: z=o=x/9e4-2+(x%d/150.-2)*1j;c=99 –  meawoppl 19 hours ago
 
@meawoppl another 7 :D –  primo 17 hours ago
 
Technically disallowed: this doesn't any graphical output feature of Python itself (and Image.show() implicitly saves a temporary file). –  nneonneo 16 hours ago
show 1 more comment

Java - Processing (271 bytes)

void setup(){int h=100,e=5*h,i;float d,v,w,a,b,c;size(e,e);colorMode(HSB,h);loadPixels();d=4./e;v=2;for(int x=1;x<=e;x++){v-=d;w=2;for(int y=0;y<e;){w-=d;a=b=c=0;i=-1;while(a*a+b*b<4&&++i<h){c=a*a-b*b+v;b=2*a*b+w;a=c;}pixels[e*++y-x]=color(i*9%h,h,h-i);}}updatePixels();}

Expanded:

void setup(){
  int h=100, e=5*h, i; //init of size "e", max hue "h", iterator "i"
  float d,v,w,a,b,c; //init of stepwidth "d", y-coord "v", x-coord "w", Re(z) "a", Im(z) "b", temp_a "c"
  size(e,e);
  colorMode(HSB,h);
  loadPixels();
  d = 4./e;
  v = 2;
  for(int x = 1; x <= e; x++){
    v -= d;
    w = 2;
    for(int y = 0; y < e;){
      w -= d;
      a = b = c = 0;
      i = -1;
      while(a*a + b*b < 4 && ++i < h){
        c = a*a - b*b + v;
        b = 2*a*b + w;
        a = c;
      }
      pixels[e * ++y - x] = color(i*9 % h, h, h-i);
    }
  }
  updatePixels();
}

share|improve this answer
add comment

JavaScript + HTML5 (356B)

(Note: lines ending with '//' are added here for some readability)

Performant version (375B):

<body onload='var
w,h=w=C.width=C.height=500,X=C.getContext("2d"),I=X.createImageData(w,h),D=I.data, //
y=0,f=255,T=setInterval(function(x,i,j,k,l,c,o){for(x=0;x<w;){                     //
for(i=x*4/w-2,j=y*4/h-2,k=l=0,c=f;--c&&k*k+l*l<4;)t=k*k-l*l+i,l=2*k*l+j,k=t
D[o=(y*w+x++)*4]=(c*=0xc0ffeeee)&f
D[++o]=c>>8&f
D[++o]=c>>16&f
D[++o]=f}X.putImageData(I,0,0)
++y-h||clearInterval(T)},0)'><canvas id=C>

Slow version (356B): remove the 'var' and parameters in the inner function so that the global scope is used.

Try it out: http://jsfiddle.net/neuroburn/Bc8Rh/

enter image description here

share|improve this answer
 
Forgive me if I don't understand your instructions on making the short version. –  Mark Jeronimus yesterday
 
No problem. Remove var w, at the beginning, and change function(x,i,j,k,l,c,o) to function(). –  ɲeuroburɳ yesterday
add comment

C + Allegro - 248 bytes

#include<allegro.h>
x=-1,y,K=400;float a,h,c,d,k;main(i){set_gfx_mode('SAFE',K,K,allegro_init(),0);while(x++<K)
for(y=0;y<K;y++){for(a=h=i=0;a*a+h*h<4&&++i<256;k=a,a=a*a-h*h+x*0.01-2,h=2*k*h+y*0.01-2);
putpixel(screen,x,y,i);}while(1);}END_OF_MAIN()

Output:

MSet 1

share|improve this answer
add comment

Octave (212 143 bytes)

[x,y]=meshgrid(-2:.01:2);z=c=x+i*y;m=0*e(401);for n=0:99;m+=abs(z)<2;z=z.^2+c;end;imagesc(m);colormap([hsv(128)(1+mod(0:79:7900,128),:);0,0,0])

With whitespace:

[x,y] = meshgrid(-2:.01:2);
z = c = x + i*y;
m = 0*e(401);
for n=0:99
    m += abs(z)<2;
    z = z.^2 + c;
end
imagesc(m)
colormap([hsv(128)(1+mod(0:79:7900,128),:);
          0,0,0])

Output:

Mandelbrot steps to abs(z)>2

This would likely work on Matlab too. (Last time I used Matlab, it did not support +=, so fixing that might add one byte. But that was a long time ago.)

My first answer (212 bytes):

[x,y]=meshgrid(-2:.01:2);z=c=x+i*y;m=0*e(401);for n=0:99;m+=abs(z)<2;z=z.^2+c;endfor;t=[0*e(1,7);2.^[6:-1:0]];[s{1:7}]=ndgrid(num2cell(t,1){:});t=1+sum(cat(8,s{:}),8);imagesc(m);colormap([hsv(128)(t(:),:);0,0,0])
share|improve this answer
 
There's probably a shorter way to get a discontinuous colormap.... –  aschepler yesterday
 
Yes, much better now. –  aschepler 21 hours ago
add comment

BBC Basic (228 bytes)

What about languages that nobody ever heard of in code golf? Most likely could be optimized, but I'm not quite where - improvements possible. Based of http://rosettacode.org/wiki/Mandelbrot_set#BBC_BASIC, but I tried to code golf it as much as possible.

VDU23,22,300;300;8,8,8,8
ORIGIN0,300
GCOL1
FORX=0TO600STEP2
i=X/200-2
FORY=0TO300STEP2
j=Y/200
x=0
y=0
FORI=1TO128
IFx*x+y*y>4EXIT FOR
t=i+x*x-y*y
y=j+2*x*y
x=t
NEXT
COLOUR1,I*8,I*4,0
PLOTX,Y:PLOTX,-Y
NEXT
NEXT

The generated Mandelbrot set

The > symbol on image is prompt, and it's automatically generated after running the program.

share|improve this answer
 
No need to plot twice, just go with a more inefficient version. Doesn;t it support NEXT Y,X? –  Mark Jeronimus 10 hours ago
add comment

Python with Pylab+Numpy 151 Bytes

I couldn't bear to see a non-DQ'ed Python entry, but I think I really outdid myself on this one, and I made it down to 153 characters!

import numpy as n
from pylab import*
i=99
x,y=n.mgrid[-2:2:999j,-2:2:999j]
c=r=x*1j+y
x-=x
while i:x[(abs(r)>2)&(x==0)]=i;r=r*r+c;i-=1
show(imshow(x))

Also, notably, the second to last line raises 4 distinct runtime warnings, a new personal record!

enter image description here

share|improve this answer
 
I count 152. No space is required between import and *, and not defining f at all should be shorter, unless i've misunderstood something, which is possible. You should also change it around such that 0 iterations and 1 iterations are distiguished (they're currently both grey). –  primo 8 hours ago
 
Weird. Does wc include the eof? Fixed and slightly smaller. Just a moment. –  meawoppl 5 hours ago
 
I get 151 with wc. First golf, so not sure how to score it. –  meawoppl 4 hours ago
 
I count 150, without trailing newline. Some interpreters/compilers demand one, but the python interpreter does fine without. Not sure about wc, but maybe try stat -c %s instead. Are the black upper and lower borders part of the image? –  primo 4 hours ago
add comment

GLSL - 225 bytes:

void main(){vec2 c=gl_FragCoord.xy/iResolution.y*4.-2.,z=c,v;for(int i=0;i<99;i++){z=vec2(z.x*z.x-z.y*z.y,2.*z.x*z.y)+c;if(length(z)>2.&&v.y<1.)v=vec2(float(i)/99.,1.);}gl_FragColor=(v.y<1.)?vec4(v,v):texture2D(iChannel0,v);}

See it in ShaderToy

Mandelbrot Golf

This requires a suitable palette texture be loaded as iChannel0. (The colouring here is from the "random pixel" texture on ShaderToy).

share|improve this answer
add comment

Perl + GD, 264

$I=new GD::Image $s=499,$s;Z(0,0,0);Z(map rand 256,1..3)for
0..99;for$x(0..$s){for$y(0..$s){for($H=$K=$c=$t=0;$c++<99&&$H*$H+$K*$K<4;){sub
Z{$I->colorAllocate(@_)}($H,$K)=($H*$H-$K*$K+4*$x/$s-2,2*$H*$K+4*$y/$s-2)}use
GD;$I->setPixel($x,$y,$c<99&&$c)}}print $I->png

Mandelbrot fractal from Perl+GD

Golfed from this code

share|improve this answer
 
Nominated: most ugly color scheme. –  meawoppl 13 hours ago
add comment

gnuplot 116 (111 without newlines)

Obligatory gnuplot entry. It's been done countless times but this one is from scratch (not that it's difficult). I like how gnuplot golfs its commands intrinsically :)

f(z,w,n)=abs(z)>2||!n?n:f(z*z+w,w,n-1)
se vi map
se si sq
se isos 256
sp [-2:2] [-2:2] f(0,x*{1,0}+y*{0,1},99) w pm

ungolfed:

f(z,w,n)=abs(z)>2||n==0?n:f(z*z+w,w,n-1)
set view map
set size square
set isosamples 256
splot [-2:2] [-2:2] f(0,x*{1,0}+y*{0,1},99) with pm3d

However, I'm DEEPLY disappointed at the entry of complex numbers. x*{1,0}+y*{0,1} must be the saddest existing way of constructing a complex number.

Oops, the image: gnuplot mandelbrot

Set isosamples higher for better resolution. We could also say unset tics and unset colorbox for a pure image, but I think this version qualifies just fine.

share|improve this answer
add comment

J, 72

load'viewmat'
(0,?$~99 3)viewmat+/2<|(j./~i:2j479)(+*:) ::(3:)"0^:(i.99)0

mandelbrot set

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.