# Mandelbrot image in every language

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:

Disallowed:

(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.

/* Configuration */

var QUESTION_ID = 23423; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 17419; // This should be the user ID of the challenge author.

/* App */

return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

}

jQuery.ajax({
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
data.items.forEach(function(a) {
});
comment_page = 1;
}
});
}

jQuery.ajax({
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
data.items.forEach(function(c) {
if (c.owner.user_id === OVERRIDE_USER)
});
else process();
}
});
}

var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

function getAuthorName(a) {
return a.owner.display_name;
}

function process() {
var valid = [];

var body = a.body;
if(OVERRIDE_REG.test(c.body))
body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
});

var match = body.match(SCORE_REG);
if (match)
valid.push({
user: getAuthorName(a),
size: +match[2],
language: match[1],
});
else console.log(body);
});

valid.sort(function (a, b) {
var aB = a.size,
bB = b.size;
return aB - bB
});

var languages = {};
var place = 1;
var lastSize = null;
var lastPlace = 1;
valid.forEach(function (a) {
if (a.size != lastSize)
lastPlace = place;
lastSize = a.size;
++place;

.replace("{{NAME}}", a.user)
.replace("{{LANGUAGE}}", a.language)
.replace("{{SIZE}}", a.size)

var lang = a.language;
lang = jQuery('<a>'+lang+'</a>').text();

languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang, user: a.user, size: a.size, link: a.link};
});

var langs = [];
for (var lang in languages)
if (languages.hasOwnProperty(lang))
langs.push(languages[lang]);

langs.sort(function (a, b) {
if (a.lang_raw.toLowerCase() > b.lang_raw.toLowerCase()) return 1;
if (a.lang_raw.toLowerCase() < b.lang_raw.toLowerCase()) return -1;
return 0;
});

for (var i = 0; i < langs.length; ++i)
{
var language = jQuery("#language-template").html();
var lang = langs[i];
language = language.replace("{{LANGUAGE}}", lang.lang)
.replace("{{NAME}}", lang.user)
.replace("{{SIZE}}", lang.size)
language = jQuery(language);
jQuery("#languages").append(language);
}

}
body {
text-align: left !important;
display: block !important;
}

width: 290px;
float: left;
}

#language-list {
width: 290px;
float: left;
}

font-weight: bold;
}

table td {
}
<div id="language-list">
<h2>Shortest Solution by Language</h2>
<table class="language-list">
<tr><td>Language</td><td>User</td><td>Score</td></tr>
<tbody id="languages">

</tbody>
</table>
</div>
<tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>

</tbody>
</table>
</div>
<table style="display: none">
</tbody>
</table>
<table style="display: none">
<tbody id="language-template">
</tbody>
</table>

• "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 Mar 7 '14 at 21:50
• 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 Mar 7 '14 at 22:44
• 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 Mar 9 '14 at 2:00
• Great idea to ask a question which requires a combination of mathematical and aesthetic sensitivities, then impose all the the design decisions in advance. – jwg Mar 10 '14 at 8:25
• Anyone manages to make one in brainfuck WINS, I'd say :D – MadTux Mar 10 '14 at 18:45

# 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:

• Me too, but my NV memory went blank after years of shelf-time. – Mark Jeronimus Mar 8 '14 at 9:10
• zx²+zy²>4 couldn't that be Abs(x)>2? – Mark Jeronimus Mar 8 '14 at 9:31
• Maybe you should get a new battery... – NothingsImpossible Mar 8 '14 at 17:48
• Interesting. So you've been a nerd for quite a while. – devnull Mar 9 '14 at 3:34
• Nice "Screenshot" – meawoppl Mar 9 '14 at 10:01

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

Python 2:

_                                      =   (
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)
)   )
• Seems to be disallowed: the regions are not easily distinguishable, or even at all. – primo Mar 8 '14 at 13:32
• Also, this writes to a file. – Lie Ryan Mar 8 '14 at 21:49
• disallowed or not, this is pretty awesome :D – Navin Mar 9 '14 at 2:28
• @DigitalTrauma, heck, +1 for most beautiful input! – Brian S Mar 10 '14 at 15:26
• Does this count as a quine? ;-) – Blazemonger Mar 10 '14 at 21:04

## LaTeX, 673 bytes

\@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

(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
}
\d0%
\Loop\c{\numexpr\iterations+1\relax}{%
\expandafter\edef\csname\the\c\endcsname{%
\hbox{\noexpand\color[Hsb]{\the\d,1,1}\noexpand\pixel}%
}%
}
\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

## x86 DOS Assembly, 208177 173 bytes

The full binary, in HEX, that I created by hand, is:

The sample image is:

The full source in readable ASM is fairly long (I used this to figure out how I was coding this sucker):

.286
CODE SEGMENT
ASSUME CS:code, DS:code
ORG 0100h

; *****************************************************************************
start:
; Mandlebrot coordinates
zr   = DWORD PTR [SI+0]
zi   = DWORD PTR [SI+4]
cr   = DWORD PTR [SI+8]
ci   = DWORD PTR [SI+12]
zrsq = DWORD PTR [SI+16]
zisq = DWORD PTR [SI+20]

; Temp int
Temp = WORD PTR  [SI+28]

; ===========================================================================
; Initialize

; Initialize the FPU
FNINIT

; SI points to our memory
mov si, 0A000h ; So we can push it

; Shave off some bytes by reusing 100
mov dx, 100

; Switch to MCGA
mov ax, 013h
int 010h

; ES:DI is the end of our drawing area
push si
pop es
mov di, 63879
std ; We're using stosb backwards

; Initialize our X and Y
mov bp, 199
mov cx, bp

; ===========================================================================
; Main draw loop

MainLoop:
; Get our next mandelbrot value
call GMV

; Store it
mov al, bl
stosb

; Decrement our X
dec cx
jns MainLoop

; Decrement our Y
mov cx, 199
sub di, 120
dec bp
jns MainLoop

; ===========================================================================
; Done

; Wait for a key press
xor ax, ax
int 016h

; Change back to text mode
mov ax, 3
int 010h

; Exit to DOS
int 020h

; *****************************************************************************
; GMV: Get Mandelbrot Value
; Gets the value for the next Mandelbrot pixel
; Returns:
;   BL - The color to use
GMV:
; ===========================================================================
; Initialize

; cr = (x - 100) / 50;
mov ax, cx
sub ax, dx                  ; \
mov Temp, ax                ;  > ST0 = Current X - 100
FILD Temp                   ; /
FILD Divisor                ; ST0 = 50, ST1 = Current X - 100
FDIVP                       ; ST0 = (Current X - 100) / 50
FSTP cr                     ; Store the result in cr

; ci = (y - 100) / 50;
mov ax, bp
sub ax, dx                  ; \
mov Temp, ax                ;  > ST0 = Current Y - 100
FILD Temp                   ; /
FILD Divisor                ; ST0 = 50, ST1 = Current Y - 100
FDIVP                       ; ST0 = (Current Y - 100) / 50
FSTP ci                     ; Store the result in ci

; zr = zi = zrsq = zisq = 0;
FLDZ
FST zr
FST zi
FST zrsq
FSTP zisq

; numiteration = 1;
mov bl, 1

; ===========================================================================
; Our main loop

; do {
GMVLoop:

; zi = 2 * zr * zi + ci;
FLD zr
FMUL zi
FIMUL TwoValue
FST zi ; Reusing this later

; zr = zrsq - zisq + cr;
FLD zrsq
FSUB zisq
FST zr ; Reusing this since it already is zr

; zrsq = zr * zr;
;FLD zr ; Reused from above
FMUL zr
FSTP zrsq

; zisq = zi * zi;
;FLD zi ; Reused from above
FMUL zi
FST zisq ; Reusing this for our comparison

; if ((zrsq + zisq) < 4)
;   return numiteration;
FILD FourValue
FCOMPP
FSTSW ax
FWAIT
sahf
jb GMVDone

;} while (numiteration++ < 200);
inc bx
cmp bl, dl
jb GMVLoop

;return 0;
xor bl, bl

GMVDone:
ret
;GMV

; *****************************************************************************
; Data

; Divisor
Divisor DW 50
; Two Value
TwoValue DW 2
; 4 Value
FourValue DW 4

CODE ENDS
END start

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!

EDIT 2: To assuage the OP, I have recreated the binary by hand. By doing so, I also shaved another 4 bytes off. I documented every single step of the process, showing all of my work so anybody can follow along if they really want to, here (warning, it's boring and very long): http://lightning.memso.com/media/perm/mandelbrot2.txt

I used a couple regex's in EditPadPro, to find all the ; Final: ... entries in the file and dump them as hex binary to a .com file. The resulting binary is what you see at the top of this post.

• Machine-code doesn't count. If that counts, then any language producing byte-code or machine-code should be shorter. I count 820 after changing everything to 1-character long names. – Mark Jeronimus Mar 10 '14 at 6:32
• I could hand code the entire thing in binary if it makes it easier for you, but that would be like asking anybody using a high level language to avoid using automatic constructs, macros, etc. That's ALL that assembly really is, just a bunch of macros. The resulting binary to run a full JavaScript, Perl, etc. includes the binary of the library. With ASM, the final hex value is everything, libraries, ALL CODE, included. – Mark Ormston Mar 10 '14 at 18:50
• No. I can hand convert ASM to binary if really necessary. It will come out with the exact same 177 bytes that my assembler helped with. The resulting code can be pasted by anybody with a binary editor into a new file, saved out, 177 bytes, and it will work as expected. Apparently SO is divided on ASM submissions, so maybe you should clarify if you feel it does not count: meta.codegolf.stackexchange.com/questions/260/… – Mark Ormston Mar 10 '14 at 19:14
• Alright, so, to prove this a valid entry, I spent the time it took to hand translate this to binary. I have updated my answer accordingly. – Mark Ormston Mar 12 '14 at 5:34
• The thing is, there is no compiler with assembly. You just use macros. Saying that it doesn't count is like saying you can't use any predefined #define statements in C. It's just time consuming to manually replace it all. – Mark Ormston Mar 12 '14 at 16:33

## Java, 505405 324 bytes

Just a standard calculation, with golfitude now with extra golfitude.

Golfed:

import java.awt.*;class M{public static void main(String[]v){new Frame(){public void paint(Graphics g){for(int t,s,n=640,i=n*n;--i>0;g.setColor(new Color(s*820)),g.drawLine(i/n,i%n+28,i/n,i%n),setSize(n,668)){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);}}}.show();}}

With line breaks:

import java.awt.*;
class M{
public static void main(String[]v){
new Frame(){
public void paint(Graphics g){
for(int t,s,n=640,i=n*n;--i>0;g.setColor(new Color(s*820)),g.drawLine(i/n,i%n+28,i/n,i%n),setSize(n,668)){
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);
}
}
}.show();
}
}
• f.setSize(n,668); - depends heavily on the used Theme, but I'll accept it. – Mark Jeronimus Mar 8 '14 at 9:11
• You can drop the imports in Java because they're auto-generated anyway. – Mark Jeronimus Mar 8 '14 at 9:23
• I also see double where float could be used if you tried – Mark Jeronimus Mar 8 '14 at 9:29
• JFrame => Frame shaves off 2 chars. Although you can't close the window anymore. ;) – EthanB Mar 8 '14 at 15:01
• Your class do not need to be public. Further, use Java 8 to get rid of the final modifier. And you must not omit the imports in order to be a complete submission. – Victor Stafusa Mar 10 '14 at 4:53

# 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)

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);:

• Nice. d=document would save you a few more. (Also, Is there a reason for creating the canvas? Does codegolf assume a certain level of HTML available?) – Matthew Wilcoxson Mar 10 '14 at 15:47

# J, 73 bytes

(0,?$~99 3)viewmat+/2<|(j./~i:2j479)(+*:) ::(3:)"0^:(i.99)0 Edit, some explaining: x (+*:) y NB. is x + (y^2) x (+*:) ::(3:) y NB. returns 3 when (+*:) fails (NaNs) j./~i:2j479 NB. a 480x480 table of complex numbers in required range v =: (j./~i:2j479)(+*:) ::(3:)"0 ] NB. (rewrite the above as one verb) v z0 NB. one iteration of the mandelbrot operation (z0 = 0) v v z0 NB. one iteration on top of the other (v^:n) z0 NB. the result of the mandelbrot operation, after n iterations i.99 NB. 0 1 2 3 4 ... 98 (v^:(i.99))0 NB. returns 99 tables, one for each number of iterations 2<| y NB. returns 1 if 2 < norm(y), 0 otherwise 2<| (v^:(i.99))0 NB. 99 tables of 1s and 0s +/... NB. add the tables together, element by element. NB. we now have one 480x480 table, representing how many times each element exceeded norm-2. colors viewmat M NB. draw table 'M' using 'colors'; 'colors' are rgb triplets for each level of 'M'.$~99 3              NB. 99 triplets of the numbers 99,3
?$~99 3 NB. 99 random triplets in the range 0 - 98 and 0 - 2 0,?$~99 3           NB. prepend the triplet (0,0,0): black
• +1 but would it be possible for you to explain a little how that code work? In particular i m curious to know how (where in the code) does it pick the colors? – plannapus Mar 10 '14 at 8:40
• @MarkJeronimus, I can make it 70 but I kept some things for clarity. I, thus, took the liberty to ignore the LF when counting. – Eelvex Mar 10 '14 at 12:39
• @plannapus, OK, added some comments. The color picking is done with (0,?$~99 3) which produces 100 rgb triplets, one for each level. Because of the randomness, you might get less than 100 triplets so some levels will have a smoother transition (but still have different colors). – Eelvex Mar 10 '14 at 13:07 # 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! • 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 Mar 9 '14 at 14:02 • Weird. Does wc include the eof? Fixed and slightly smaller. Just a moment. – meawoppl Mar 9 '14 at 17:46 • I get 151 with wc. First golf, so not sure how to score it. – meawoppl Mar 9 '14 at 18:01 • 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 Mar 9 '14 at 18:09 • You can save 1 character by using from numpy import* instead of import numpy as n and mgrid instead of n.mgrid. – nyuszika7h Jun 15 '14 at 15:15 # C + Allegro 4.2.2 - 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: • You should mention that this is Allegro 4 (which is quite different from Allegro 5). Which exact version is this? – Victor Stafusa Mar 10 '14 at 4:57 • it's either 246 or 249 long – Mark Jeronimus Mar 10 '14 at 6:42 • @Victor Allegro 4.2.2. – Oberon Mar 10 '14 at 14:34 • @MarkJeronimus Isn't there supposed to be a newline between ... allegro.h> and x=-1, ...? I suppose Notepad++ counts it as \r\n = 0D 0A. – Oberon Mar 10 '14 at 21:05 • I think 0.01 can be typed as .01. – Yytsi Jun 21 '16 at 9:53 # Mathematica, 21419121519 30 Since version 10.0 there is a built-in: (19 bytes) MandelbrotSetPlot[] To conform to the coordinate range requirements, 11 additional bytes are required. (30 bytes) MandelbrotSetPlot@{-2-2I,2+2I} A hand-rolled case: 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,#]]&)] • {b, -2, 2, .01}, {a, -2, 2, .01} is shorter and closer to the rules – Mark Jeronimus Mar 7 '14 at 23:50 • @MarkJeronimus Thanks. I used the suggested range for the iterating picture. – DavidC Mar 8 '14 at 3:20 • 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 Mar 8 '14 at 9:20 • I missed the point about being black. The count increased because some single characters became two characters in the cut-and-paste to SE. – DavidC Mar 8 '14 at 13:34 • Your built-in solution uses a very loose interpretation of The fractal coordinates range from approximately -2-2i to 2+2i. – Jonathan Frech Sep 25 '17 at 12:58 ## Python + 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): • 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 Mar 8 '14 at 16:15 • @Geobits the idea actually saved 10, thanks! – primo Mar 8 '14 at 16:28 • 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 Mar 9 '14 at 3:10 • @meawoppl another 7 :D – primo Mar 9 '14 at 5:07 • Technically disallowed: this doesn't any graphical output feature of Python itself (and Image.show() implicitly saves a temporary file). – nneonneo Mar 9 '14 at 5:51 # 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 > symbol on image is prompt, and it's automatically generated after running the program. • No need to plot twice, just go with a more inefficient version. Doesn;t it support NEXT Y,X? – Mark Jeronimus Mar 9 '14 at 11:59 ### Windows PowerShell (v4), 299 bytes # Linewrapped here for show:$M='System.Windows.Forms';nal n New-Object;Add-Type -A System.Drawing,$M;($a=n "$M.Form").backgroundimage=($b=n Drawing.Bitmap 300,300);0..299|%{
$r=$_;0..299|%{$i=99;$k=$C=n numerics.complex($_/75-2),($r/75-2);while((($k=$k*$k).Magnitude-lt4)-and$i--){$k+=$C}$b.SetPixel($_,$r,-5e6*++$i)}};$a.Show()

# The single line 299 char entry version:

if [s b [expr 2*$a*$b+$y$f]]*$b+[s a$A]*$a>4 break incr n}$p p [format #%06x [expr $n*16777215/99]] -t$x $y} 640} 640 Presentation: • Nice. You can reduce a few characters (down to 380, I think) by adding rename set s at the top and then replacing all the set by s – Rolazaro Azeveires Apr 4 '17 at 0:00 ## 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

Golfed from this code

• Nominated: most ugly color scheme. – meawoppl Mar 9 '14 at 9:41

# Excel VBA, 251246224 223 bytes

Saved 5 bytes thanks to ceilingcat Saved 23 bytes thanks to Taylor Scott

Sub m
D=99
For x=1To 4*D
For y=1To 4*D
p=0
q=0
For j=1To 98
c=2*p*q
p=p^2-q^2-2+(x-1)/D
q=c+2+(1-y)/D
If p^2+q^2>=4Then Exit For
Next
j=-j*(j<D)
Cells(y,x).Interior.Color=Rnd(-j)*1E6*j/D
Next
Next
Cells.RowHeight=48
End Sub

Output:

I made a version that did this a long time ago but it had a lot of extras like letting the user pick the basic color and easy-to-follow math. Golfing it way down was an interesting challenge. The Color method uses 1E6 as a means to get a wide range of colors since the valid colors are 0 to 2^24. Setting it to 10^6 gave nice contrast areas.

Explanation / Auto-Formatting:

Sub m()

'D determines the number of pixels and is factored in a few times throughout
D = 99
For x = 1 To 4 * D
For y = 1 To 4 * D
'Test to see if it escapes
'Use p for the real part and q for the imaginary
p = 0
q = 0
For j = 1 To 98
'This is a golfed down version of complex number math that started as separate generic functions for add, multiple, and modulus
c = 2 * p * q
p = p ^ 2 - q ^ 2 - 2 + (x - 1) / D
q = c + 2 + (1 - y) / D
If p ^ 2 + q ^ 2 >= 4 Then Exit For
Next

'Correct for no escape
j = -j * (j < D)

'Store the results
'Rnd() with a negative input is deterministic
'This is what gives us the distinct color bands
Cells(y, x).Interior.Color = Rnd(-j) * 1000000# * j / D

Next
Next

'Resize for pixel art
Cells.RowHeight = 48

End Sub

I also played around with D=999 and j=1 to 998 to get a much larger and more precise image. The results are irrelevant to the challenge because they're way too large but they are neat.

• @ceilingcat Thanks. That was a carryover from my original which had specialized functions for complex number math. – Engineer Toast Sep 27 '17 at 12:07
• Does it really need to be >=4 or can you get away with >4? Also, can replace j<99 with j<D. – ceilingcat Sep 27 '17 at 22:38
• @EngineerToast you can drop the () from the sub name,you should change (j<99) to (j<d) and you can, for the purpose of making square cells use only Cells.RowHeight=48 in place of the Cells.RowHeight=9,Cells.ColumnWidth=1 - this does making messing around with your output more difficult but has been accepted as valid by the community - – Taylor Scott Sep 28 '17 at 5:03
• @TaylorScott I remember the RowHeight trick from the VBA tips post and had meant to integrate it after I got all my pretty pictures. That was a nice chunk'o'bytes, thanks. – Engineer Toast Sep 28 '17 at 12:31
• I believe that you can get away with removing another byte by swapping 2^20 with 1E6 – Taylor Scott Oct 8 '17 at 17:55