Mandelbrot set: Difference between revisions
Content added Content deleted
m (Remove unused import.) |
(Convert <lang> elements to <syntaxhighlight>) |
||
Line 13: | Line 13: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang=11l>F mandelbrot(a) |
||
R (0.<50).reduce(0i, (z, _) -> z * z + @a) |
R (0.<50).reduce(0i, (z, _) -> z * z + @a) |
||
Line 20: | Line 20: | ||
V rows = (step(1, -0.05, 41).map(y -> (step(-2.0, 0.0315, 80).map(x -> (I abs(mandelbrot(x + 1i * @y)) < 2 {‘*’} E ‘ ’))))) |
V rows = (step(1, -0.05, 41).map(y -> (step(-2.0, 0.0315, 80).map(x -> (I abs(mandelbrot(x + 1i * @y)) < 2 {‘*’} E ‘ ’))))) |
||
print(rows.map(row -> row.join(‘’)).join("\n"))</ |
print(rows.map(row -> row.join(‘’)).join("\n"))</syntaxhighlight> |
||
=={{header|ACL2}}== |
=={{header|ACL2}}== |
||
< |
<syntaxhighlight lang=Lisp>(defun abs-sq (z) |
||
(+ (expt (realpart z) 2) |
(+ (expt (realpart z) 2) |
||
(expt (imagpart z) 2))) |
(expt (imagpart z) 2))) |
||
Line 77: | Line 77: | ||
(defun draw-mandelbrot (width iters) |
(defun draw-mandelbrot (width iters) |
||
(let ((height (floor (* 1000 width) 3333))) |
(let ((height (floor (* 1000 width) 3333))) |
||
(draw-mandel 1 height width height iters)))</ |
(draw-mandel 1 height width height iters)))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 103: | Line 103: | ||
{{libheader|Lumen}} |
{{libheader|Lumen}} |
||
mandelbrot.adb: |
mandelbrot.adb: |
||
< |
<syntaxhighlight lang=Ada>with Lumen.Binary; |
||
package body Mandelbrot is |
package body Mandelbrot is |
||
function Create_Image (Width, Height : Natural) return Lumen.Image.Descriptor is |
function Create_Image (Width, Height : Natural) return Lumen.Image.Descriptor is |
||
Line 142: | Line 142: | ||
end Create_Image; |
end Create_Image; |
||
end Mandelbrot;</ |
end Mandelbrot;</syntaxhighlight> |
||
mandelbrot.ads: |
mandelbrot.ads: |
||
< |
<syntaxhighlight lang=Ada>with Lumen.Image; |
||
package Mandelbrot is |
package Mandelbrot is |
||
Line 151: | Line 151: | ||
function Create_Image (Width, Height : Natural) return Lumen.Image.Descriptor; |
function Create_Image (Width, Height : Natural) return Lumen.Image.Descriptor; |
||
end Mandelbrot;</ |
end Mandelbrot;</syntaxhighlight> |
||
test_mandelbrot.adb: |
test_mandelbrot.adb: |
||
< |
<syntaxhighlight lang=Ada>with System.Address_To_Access_Conversions; |
||
with Lumen.Window; |
with Lumen.Window; |
||
with Lumen.Image; |
with Lumen.Image; |
||
Line 308: | Line 308: | ||
when Program_End => |
when Program_End => |
||
null; |
null; |
||
end Test_Mandelbrot;</ |
end Test_Mandelbrot;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 318: | Line 318: | ||
Plot part of the Mandelbrot set as a pseudo-gif image. |
Plot part of the Mandelbrot set as a pseudo-gif image. |
||
< |
<syntaxhighlight lang=algol68> |
||
INT pix = 300, max iter = 256, REAL zoom = 0.33 / pix; |
INT pix = 300, max iter = 256, REAL zoom = 0.33 / pix; |
||
[-pix : pix, -pix : pix] INT plane; |
[-pix : pix, -pix : pix] INT plane; |
||
Line 357: | Line 357: | ||
OD; |
OD; |
||
close (plot) |
close (plot) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|ALGOL W}}== |
=={{header|ALGOL W}}== |
||
Generates an ASCII Mandelbrot Set. Translated from the sample program in the Compiler/AST Interpreter task. |
Generates an ASCII Mandelbrot Set. Translated from the sample program in the Compiler/AST Interpreter task. |
||
< |
<syntaxhighlight lang=algolw>begin |
||
% This is an integer ascii Mandelbrot generator, translated from the % |
% This is an integer ascii Mandelbrot generator, translated from the % |
||
% Compiler/AST Interpreter Task's ASCII Mandelbrot Set example program % |
% Compiler/AST Interpreter Task's ASCII Mandelbrot Set example program % |
||
Line 400: | Line 400: | ||
end for_y0 |
end for_y0 |
||
end. |
end. |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 452: | Line 452: | ||
Hopper-code & macros Version: |
Hopper-code & macros Version: |
||
< |
<syntaxhighlight lang=Amazing Hopper> |
||
#!/usr/bin/hopper |
#!/usr/bin/hopper |
||
Line 501: | Line 501: | ||
{mandel,"mandel.dat"}save |
{mandel,"mandel.dat"}save |
||
{0}return |
{0}return |
||
</syntaxhighlight> |
|||
</lang> |
|||
Hopper-Basic high level language version: |
Hopper-Basic high level language version: |
||
< |
<syntaxhighlight lang=Amazing Hopper> |
||
#!/usr/bin/hopper |
#!/usr/bin/hopper |
||
Line 552: | Line 552: | ||
{mandel,"mandel.dat"}save |
{mandel,"mandel.dat"}save |
||
{0}return |
{0}return |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 559: | Line 559: | ||
{{trans|Nim}} |
{{trans|Nim}} |
||
< |
<syntaxhighlight lang=rebol>inMandelbrot?: function [c][ |
||
z: to :complex [0 0] |
z: to :complex [0 0] |
||
do.times: 50 [ |
do.times: 50 [ |
||
Line 586: | Line 586: | ||
mandelbrot #[ yStart: 1.0 yStep: neg 0.05 |
mandelbrot #[ yStart: 1.0 yStep: neg 0.05 |
||
xStart: neg 2.0 xStep: 0.0315 |
xStart: neg 2.0 xStep: 0.0315 |
||
height: 40 width: 80 ]</ |
height: 40 width: 80 ]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 627: | Line 627: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
< |
<syntaxhighlight lang=autohotkey>Max_Iteration := 256 |
||
Width := Height := 400 |
Width := Height := 400 |
||
Line 743: | Line 743: | ||
;--------------------------------------------------------------------------- |
;--------------------------------------------------------------------------- |
||
Return, (r&0xFF)<<16 | g<<8 | b |
Return, (r&0xFF)<<16 | g<<8 | b |
||
}</ |
}</syntaxhighlight> |
||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
< |
<syntaxhighlight lang=AWK>BEGIN { |
||
XSize=59; YSize=21; |
XSize=59; YSize=21; |
||
MinIm=-1.0; MaxIm=1.0;MinRe=-2.0; MaxRe=1.0; |
MinIm=-1.0; MaxIm=1.0;MinRe=-2.0; MaxRe=1.0; |
||
Line 767: | Line 767: | ||
} |
} |
||
exit; |
exit; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 796: | Line 796: | ||
This implements a 16bit fixed point arithmetic Mandelbrot set calculation. |
This implements a 16bit fixed point arithmetic Mandelbrot set calculation. |
||
{{works with|The Amsterdam Compiler Kit - B|V6.1pre1}} |
{{works with|The Amsterdam Compiler Kit - B|V6.1pre1}} |
||
< |
<syntaxhighlight lang=B>main() { |
||
auto cx,cy,x,y,x2,y2; |
auto cx,cy,x,y,x2,y2; |
||
auto iter; |
auto iter; |
||
Line 838: | Line 838: | ||
return(0); |
return(0); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 873: | Line 873: | ||
{{trans|QBasic}} |
{{trans|QBasic}} |
||
< |
<syntaxhighlight lang=amigabasic>SCREEN 1,320,200,5,1 |
||
WINDOW 2,"Mandelbrot",,0,1 |
WINDOW 2,"Mandelbrot",,0,1 |
||
Line 920: | Line 920: | ||
' endless loop, use Run -> Stop from the menu to stop program |
' endless loop, use Run -> Stop from the menu to stop program |
||
WHILE (1) |
WHILE (1) |
||
WEND</ |
WEND</syntaxhighlight> |
||
==={{header|Applesoft BASIC}}=== |
==={{header|Applesoft BASIC}}=== |
||
This version takes into account the Apple II's funky 280×192 6-color display, which has an effective resolution of only 140×192 in color. |
This version takes into account the Apple II's funky 280×192 6-color display, which has an effective resolution of only 140×192 in color. |
||
< |
<syntaxhighlight lang=basic> |
||
10 HGR2 |
10 HGR2 |
||
20 XC = -0.5 : REM CENTER COORD X |
20 XC = -0.5 : REM CENTER COORD X |
||
Line 962: | Line 962: | ||
330 NEXT YS |
330 NEXT YS |
||
340 NEXT YI |
340 NEXT YI |
||
</syntaxhighlight> |
|||
</lang> |
|||
By making the following modifications, the same code will render the Mandelbrot set in monochrome at full 280×192 resolution. |
By making the following modifications, the same code will render the Mandelbrot set in monochrome at full 280×192 resolution. |
||
< |
<syntaxhighlight lang=basic> |
||
150 FOR XS = 0 TO 279 |
150 FOR XS = 0 TO 279 |
||
301 C = (C - INT(C/2)*2)*3 |
301 C = (C - INT(C/2)*2)*3 |
||
310 HCOLOR = C: HPLOT XS, YS |
310 HCOLOR = C: HPLOT XS, YS |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 978: | Line 978: | ||
This can be run in BeebEm. Select BBC model as Master 128 with ARM Second Processor. Load disc armdisc3.adl and switch to ADFS. At the prompt load ARM Basic by running the AB command. |
This can be run in BeebEm. Select BBC model as Master 128 with ARM Second Processor. Load disc armdisc3.adl and switch to ADFS. At the prompt load ARM Basic by running the AB command. |
||
< |
<syntaxhighlight lang=bbcbasic> |
||
10MODE5:VDU5 |
10MODE5:VDU5 |
||
20D%=100 : REM adjust for speed/precision |
20D%=100 : REM adjust for speed/precision |
||
Line 988: | Line 988: | ||
70PLOT69,X%,Y% |
70PLOT69,X%,Y% |
||
80NEXT |
80NEXT |
||
90NEXT</ |
90NEXT</syntaxhighlight> |
||
[[File:Mandelbrot_armbasic.png]] |
[[File:Mandelbrot_armbasic.png]] |
||
==={{header|BASIC256}}=== |
==={{header|BASIC256}}=== |
||
< |
<syntaxhighlight lang=basic-256>fastgraphics |
||
graphsize 384,384 |
graphsize 384,384 |
||
Line 1,027: | Line 1,027: | ||
next x |
next x |
||
imgsave "Mandelbrot_BASIC-256.png", "PNG" |
imgsave "Mandelbrot_BASIC-256.png", "PNG" |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out|Image generated by the script}} |
{{out|Image generated by the script}} |
||
[[File:Mandelbrot BASIC-256.jpg|220px]] |
[[File:Mandelbrot BASIC-256.jpg|220px]] |
||
Line 1,033: | Line 1,033: | ||
==={{header|BBC BASIC}}=== |
==={{header|BBC BASIC}}=== |
||
{{works with|BBC BASIC for Windows}} |
{{works with|BBC BASIC for Windows}} |
||
< |
<syntaxhighlight lang=bbcbasic> sizex% = 300 : sizey% = 300 |
||
maxiter% = 128 |
maxiter% = 128 |
||
VDU 23,22,sizex%;sizey%;8,8,16,128 |
VDU 23,22,sizex%;sizey%;8,8,16,128 |
||
Line 1,054: | Line 1,054: | ||
PLOT X%,Y% : PLOT X%,-Y% |
PLOT X%,Y% : PLOT X%,-Y% |
||
NEXT |
NEXT |
||
NEXT X%</ |
NEXT X%</syntaxhighlight> |
||
[[File:Mandelbrot_bbc.gif]] |
[[File:Mandelbrot_bbc.gif]] |
||
==={{header|Commander X16 BASIC}}=== |
==={{header|Commander X16 BASIC}}=== |
||
< |
<syntaxhighlight lang=X16BASIC> |
||
10 CLS |
10 CLS |
||
20 SCREEN $80 |
20 SCREEN $80 |
||
Line 1,080: | Line 1,080: | ||
190 PSET X,YR,I |
190 PSET X,YR,I |
||
200 :NEXT:NEXT |
200 :NEXT:NEXT |
||
</syntaxhighlight> |
|||
</lang> |
|||
==={{header|Commodore BASIC}}=== |
==={{header|Commodore BASIC}}=== |
||
Line 1,090: | Line 1,090: | ||
Runs in about 90 minutes. |
Runs in about 90 minutes. |
||
< |
<syntaxhighlight lang=basic>100 TH=20:REM ESCAPE THRESHOLD IN ITERATIONS |
||
110 COLOR 1,3,0,0:GRAPHIC 2:TH=20 |
110 COLOR 1,3,0,0:GRAPHIC 2:TH=20 |
||
120 FOR PY=0 TO 80 |
120 FOR PY=0 TO 80 |
||
Line 1,110: | Line 1,110: | ||
280 NEXT PY |
280 NEXT PY |
||
290 GET K$:IF K$="" THEN 290 |
290 GET K$:IF K$="" THEN 290 |
||
300 GRAPHIC 4</ |
300 GRAPHIC 4</syntaxhighlight> |
||
===={{header|C-64 with Super Expander 64}}==== |
===={{header|C-64 with Super Expander 64}}==== |
||
Runs in about 4.5 hours. |
Runs in about 4.5 hours. |
||
< |
<syntaxhighlight lang=basic>100 TH=20:REM ESCAPE THRESHOLD IN ITERATIONS |
||
110 COLOR 6,0,0,0,6:GRAPHIC 2,1 |
110 COLOR 6,0,0,0,6:GRAPHIC 2,1 |
||
120 FOR PY=0 TO 100 |
120 FOR PY=0 TO 100 |
||
Line 1,133: | Line 1,133: | ||
280 NEXT PY |
280 NEXT PY |
||
290 GET K$:IF K$="" THEN 290 |
290 GET K$:IF K$="" THEN 290 |
||
300 GRAPHIC 0</ |
300 GRAPHIC 0</syntaxhighlight> |
||
===={{header|Commodore-16 / 116 / Plus/4}}==== |
===={{header|Commodore-16 / 116 / Plus/4}}==== |
||
{{works with|Commodore BASIC|3.5}} |
{{works with|Commodore BASIC|3.5}} |
||
Despite the faster clock on the TED systems compared to the C-64, this takes almost six hours to run. |
Despite the faster clock on the TED systems compared to the C-64, this takes almost six hours to run. |
||
< |
<syntaxhighlight lang=basic>100 TH=20:REM ESCAPE THRESHOLD IN ITERATIONS |
||
110 COLOR 0,2:COLOR 1,1:GRAPHIC 1,1 |
110 COLOR 0,2:COLOR 1,1:GRAPHIC 1,1 |
||
120 FOR PY=0 TO 100 |
120 FOR PY=0 TO 100 |
||
Line 1,155: | Line 1,155: | ||
250 NEXT PY |
250 NEXT PY |
||
260 GETKEY K$ |
260 GETKEY K$ |
||
270 GRAPHIC 0</ |
270 GRAPHIC 0</syntaxhighlight> |
||
===={{header|Commodore 128 (40-column display)}}==== |
===={{header|Commodore 128 (40-column display)}}==== |
||
Line 1,164: | Line 1,164: | ||
64 and Plus/4 versions. |
64 and Plus/4 versions. |
||
< |
<syntaxhighlight lang=basic>100 TH=20:REM ESCAPE THRESHOLD IN ITERATIONS |
||
110 COLOR 0,12:GRAPHIC 1,1:COLOR 1,1:GRAPHIC0:FAST |
110 COLOR 0,12:GRAPHIC 1,1:COLOR 1,1:GRAPHIC0:FAST |
||
120 FOR PY=0 TO 100 |
120 FOR PY=0 TO 100 |
||
Line 1,182: | Line 1,182: | ||
260 SLOW:GRAPHIC 1 |
260 SLOW:GRAPHIC 1 |
||
270 GETKEY K$ |
270 GETKEY K$ |
||
280 GRAPHIC 0</ |
280 GRAPHIC 0</syntaxhighlight> |
||
===={{header|Commodore 128 (80-column display)}}==== |
===={{header|Commodore 128 (80-column display)}}==== |
||
Line 1,189: | Line 1,189: | ||
This uses BASIC 8 to create a 640x200 render on the C-128's 80-column display. The doubled resolution comes with a commensurate increase in run time; this takes about 5h20m using FAST 2MHz mode. |
This uses BASIC 8 to create a 640x200 render on the C-128's 80-column display. The doubled resolution comes with a commensurate increase in run time; this takes about 5h20m using FAST 2MHz mode. |
||
< |
<syntaxhighlight lang=basic>100 TH=20:REM ESCAPE THRESHOLD IN ITERATIONS |
||
110 @MODE,0:@COLOR,15,0,0:@SCREEN,0,0:@CLEAR,0:FAST |
110 @MODE,0:@COLOR,15,0,0:@SCREEN,0,0:@CLEAR,0:FAST |
||
120 FOR PY=0 TO 100 |
120 FOR PY=0 TO 100 |
||
Line 1,207: | Line 1,207: | ||
250 NEXT PY |
250 NEXT PY |
||
260 GETKEY K$ |
260 GETKEY K$ |
||
270 @TEXT</ |
270 @TEXT</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
Line 1,215: | Line 1,215: | ||
===={{header|Commodore PET}}==== |
===={{header|Commodore PET}}==== |
||
Here's a version using mostly ASCII and some PETSCII (could probably improve the tile set for PETSCII) inspired by the Perl solution. Designed for a PET with an 80-column display. |
Here's a version using mostly ASCII and some PETSCII (could probably improve the tile set for PETSCII) inspired by the Perl solution. Designed for a PET with an 80-column display. |
||
< |
<syntaxhighlight lang=basic>100 TH=20:REM ESCAPE THRESHOLD IN ITERATIONS |
||
110 CH$=" .:-=+*#@"+CHR$(255) |
110 CH$=" .:-=+*#@"+CHR$(255) |
||
120 FOR Y=1 TO -1 STEP -0.08 |
120 FOR Y=1 TO -1 STEP -0.08 |
||
Line 1,234: | Line 1,234: | ||
270 NEXT I |
270 NEXT I |
||
280 IF I>TH THEN I=TH |
280 IF I>TH THEN I=TH |
||
290 RETURN</ |
290 RETURN</syntaxhighlight> |
||
{{Out}} VICE screenshot [https://i.imgur.com/y4zYmyD.png here]. |
{{Out}} VICE screenshot [https://i.imgur.com/y4zYmyD.png here]. |
||
Line 1,257: | Line 1,257: | ||
160 NEXT Y |
160 NEXT Y |
||
170 END |
170 END |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>>>>>>>=====<<<<<<<<<<<<<<<;;;;;;:::96032:;;;;<<<<=========== |
<pre>>>>>>>=====<<<<<<<<<<<<<<<;;;;;;:::96032:;;;;<<<<=========== |
||
Line 1,283: | Line 1,283: | ||
==={{header|FreeBASIC}}=== |
==={{header|FreeBASIC}}=== |
||
< |
<syntaxhighlight lang=freebasic>#define pix 1./120 |
||
#define zero_x 320 |
#define zero_x 320 |
||
#define zero_y 240 |
#define zero_y 240 |
||
Line 1,338: | Line 1,338: | ||
while inkey="" |
while inkey="" |
||
wend |
wend |
||
end</ |
end</syntaxhighlight> |
||
==={{header|GW-BASIC}}=== |
==={{header|GW-BASIC}}=== |
||
< |
<syntaxhighlight lang=gwbasic>10 SCALE# = 1/60 : ZEROX = 160 |
||
20 ZEROY = 100 : MAXIT = 32 |
20 ZEROY = 100 : MAXIT = 32 |
||
30 SCREEN 1 |
30 SCREEN 1 |
||
Line 1,360: | Line 1,360: | ||
180 PSET (X, 2*ZEROY-Y), 1+(I MOD 3) |
180 PSET (X, 2*ZEROY-Y), 1+(I MOD 3) |
||
190 NEXT Y |
190 NEXT Y |
||
200 NEXT X</ |
200 NEXT X</syntaxhighlight> |
||
==={{header|Liberty BASIC}}=== |
==={{header|Liberty BASIC}}=== |
||
Any words of description go outside of lang tags. |
Any words of description go outside of lang tags. |
||
< |
<syntaxhighlight lang=lb>nomainwin |
||
WindowWidth =440 |
WindowWidth =440 |
||
Line 1,419: | Line 1,419: | ||
close #w |
close #w |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
==={{header|Locomotive Basic}}=== |
==={{header|Locomotive Basic}}=== |
||
{{trans|QBasic}} |
{{trans|QBasic}} |
||
This program is meant for use in [https://benchmarko.github.io/CPCBasic/cpcbasic.html CPCBasic] specifically, where it draws a 16-color 640x400 image in less than a minute. (Real CPC hardware would take far longer than that and has lower resolution.) |
This program is meant for use in [https://benchmarko.github.io/CPCBasic/cpcbasic.html CPCBasic] specifically, where it draws a 16-color 640x400 image in less than a minute. (Real CPC hardware would take far longer than that and has lower resolution.) |
||
< |
<syntaxhighlight lang=locobasic>1 MODE 3 ' Note the CPCBasic-only screen mode! |
||
2 FOR xp = 0 TO 639 |
2 FOR xp = 0 TO 639 |
||
3 FOR yp = 0 TO 399 |
3 FOR yp = 0 TO 399 |
||
Line 1,440: | Line 1,440: | ||
15 PLOT xp, yp, c MOD 16 |
15 PLOT xp, yp, c MOD 16 |
||
16 NEXT |
16 NEXT |
||
17 NEXT</ |
17 NEXT</syntaxhighlight> |
||
==={{header|Microsoft Small Basic}}=== |
==={{header|Microsoft Small Basic}}=== |
||
< |
<syntaxhighlight lang=Small BASIC> |
||
GraphicsWindow.Show() |
GraphicsWindow.Show() |
||
size = 500 |
size = 500 |
||
Line 1,473: | Line 1,473: | ||
EndFor |
EndFor |
||
EndFor |
EndFor |
||
</syntaxhighlight> |
|||
</lang> |
|||
==={{header|Microsoft Super Extended Color BASIC (Tandy Color Computer 3)}}=== |
==={{header|Microsoft Super Extended Color BASIC (Tandy Color Computer 3)}}=== |
||
< |
<syntaxhighlight lang=COCO3BASIC> |
||
1 REM MANDELBROT SET - TANDY COCO 3 |
1 REM MANDELBROT SET - TANDY COCO 3 |
||
2 POKE 65497,1 |
2 POKE 65497,1 |
||
Line 1,498: | Line 1,498: | ||
170 NEXT Y |
170 NEXT Y |
||
180 GOTO 180 |
180 GOTO 180 |
||
</syntaxhighlight> |
|||
</lang> |
|||
==={{header|Nascom BASIC}}=== |
==={{header|Nascom BASIC}}=== |
||
Line 1,508: | Line 1,508: | ||
Only a fragment of the shape is drawn because of low resolution of block graphics. Like in the ZX81 version, you can adjust the constants in lines 40 and 70 to zoom in on a particular area, if you like. |
Only a fragment of the shape is drawn because of low resolution of block graphics. Like in the ZX81 version, you can adjust the constants in lines 40 and 70 to zoom in on a particular area, if you like. |
||
{{works with|Nascom ROM BASIC|4.7}} |
{{works with|Nascom ROM BASIC|4.7}} |
||
< |
<syntaxhighlight lang=basic> |
||
10 REM Mandelbrot set |
10 REM Mandelbrot set |
||
20 CLS |
20 CLS |
||
Line 1,547: | Line 1,547: | ||
510 DATA 27085,14336,-13564,6399,18178,10927 |
510 DATA 27085,14336,-13564,6399,18178,10927 |
||
520 DATA -8179,233 |
520 DATA -8179,233 |
||
</syntaxhighlight> |
|||
</lang> |
|||
==={{header|OS/8 BASIC}}=== |
==={{header|OS/8 BASIC}}=== |
||
Works under BASIC on a PDP-8 running OS/8. Various emulators exist including simh's PDP-8 emulator and the [http://www.bernhard-baehr.de/pdp8e/pdp8e.html PDP-8/E Simulator] for Classic Macintosh and OS X. |
Works under BASIC on a PDP-8 running OS/8. Various emulators exist including simh's PDP-8 emulator and the [http://www.bernhard-baehr.de/pdp8e/pdp8e.html PDP-8/E Simulator] for Classic Macintosh and OS X. |
||
< |
<syntaxhighlight lang=qbasic>10 X1=59\Y1=21 |
||
20 I1=-1.0\I2=1.0\R1=-2.0\R2=1.0 |
20 I1=-1.0\I2=1.0\R1=-2.0\R2=1.0 |
||
30 S1=(R2-R1)/X1\S2=(I2-I1)/Y1 |
30 S1=(R2-R1)/X1\S2=(I2-I1)/Y1 |
||
Line 1,567: | Line 1,567: | ||
150 PRINT |
150 PRINT |
||
160 NEXT Y |
160 NEXT Y |
||
170 END</ |
170 END</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>>>>>>>=====<<<<<<<<<<<<<<<;;;;;;:::96032:;;;;<<<<=========== |
<pre>>>>>>>=====<<<<<<<<<<<<<<<;;;;;;:::96032:;;;;<<<<=========== |
||
Line 1,594: | Line 1,594: | ||
==={{header|PureBasic}}=== |
==={{header|PureBasic}}=== |
||
PureBasic forum: [http://www.purebasic.fr/german/viewtopic.php?f=4&t=22107 discussion] |
PureBasic forum: [http://www.purebasic.fr/german/viewtopic.php?f=4&t=22107 discussion] |
||
< |
<syntaxhighlight lang=PureBasic>EnableExplicit |
||
#Window1 = 0 |
#Window1 = 0 |
||
Line 1,651: | Line 1,651: | ||
Event = WaitWindowEvent() |
Event = WaitWindowEvent() |
||
Until Event = #PB_Event_CloseWindow |
Until Event = #PB_Event_CloseWindow |
||
EndIf</ |
EndIf</syntaxhighlight>Example:<br> |
||
[[File:Mandelbrot-PureBasic.png]] |
[[File:Mandelbrot-PureBasic.png]] |
||
Line 1,657: | Line 1,657: | ||
This is almost exactly the same as the pseudocode from [[wp:Mandelbrot set#For_programmers|the Wikipedia entry's "For programmers" section]] (which it's closely based on, of course). The image generated is very blocky ("low-res") due to the selected video mode, but it's fairly accurate. |
This is almost exactly the same as the pseudocode from [[wp:Mandelbrot set#For_programmers|the Wikipedia entry's "For programmers" section]] (which it's closely based on, of course). The image generated is very blocky ("low-res") due to the selected video mode, but it's fairly accurate. |
||
< |
<syntaxhighlight lang=qbasic>SCREEN 13 |
||
WINDOW (-2, 1.5)-(2, -1.5) |
WINDOW (-2, 1.5)-(2, -1.5) |
||
FOR x0 = -2 TO 2 STEP .01 |
FOR x0 = -2 TO 2 STEP .01 |
||
Line 1,684: | Line 1,684: | ||
PSET (x0, y0), c + 32 |
PSET (x0, y0), c + 32 |
||
NEXT |
NEXT |
||
NEXT</ |
NEXT</syntaxhighlight> |
||
==={{header|Quite BASIC}}=== |
==={{header|Quite BASIC}}=== |
||
< |
<syntaxhighlight lang=Quite BASIC> |
||
1000 REM Mandelbrot Set Project |
1000 REM Mandelbrot Set Project |
||
1010 REM Quite BASIC Math Project |
1010 REM Quite BASIC Math Project |
||
Line 1,731: | Line 1,731: | ||
3090 LET P[8] = "white" |
3090 LET P[8] = "white" |
||
3100 RETURN |
3100 RETURN |
||
</syntaxhighlight> |
|||
</lang> |
|||
==={{header|Run BASIC}}=== |
==={{header|Run BASIC}}=== |
||
< |
<syntaxhighlight lang=Runbasic>'Mandelbrot V4 for RunBasic |
||
'Based on LibertyBasic solution |
'Based on LibertyBasic solution |
||
'copy the code and go to runbasic.com |
'copy the code and go to runbasic.com |
||
Line 1,824: | Line 1,824: | ||
print "All done, good bye." |
print "All done, good bye." |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
==={{header|Sinclair ZX81 BASIC}}=== |
==={{header|Sinclair ZX81 BASIC}}=== |
||
Line 1,831: | Line 1,831: | ||
Glacially slow, but does eventually produce a tolerable low-resolution image (screenshot [http://edmundgriffiths.com/zxmandelbrot.jpg here]). You can adjust the constants in lines 30 and 40 to zoom in on a particular area, if you like. |
Glacially slow, but does eventually produce a tolerable low-resolution image (screenshot [http://edmundgriffiths.com/zxmandelbrot.jpg here]). You can adjust the constants in lines 30 and 40 to zoom in on a particular area, if you like. |
||
< |
<syntaxhighlight lang=zxbasic> 10 FOR I=0 TO 63 |
||
20 FOR J=43 TO 0 STEP -1 |
20 FOR J=43 TO 0 STEP -1 |
||
30 LET X=(I-52)/31 |
30 LET X=(I-52)/31 |
||
Line 1,845: | Line 1,845: | ||
130 IF ITER=200 THEN PLOT I, J |
130 IF ITER=200 THEN PLOT I, J |
||
140 NEXT J |
140 NEXT J |
||
150 NEXT I</ |
150 NEXT I</syntaxhighlight> |
||
==={{Header|SmileBASIC}}=== |
==={{Header|SmileBASIC}}=== |
||
Generates the points at random, gradually building up the image. |
Generates the points at random, gradually building up the image. |
||
< |
<syntaxhighlight lang=smilebasic>X = RNDF()*4-2 |
||
Y = RNDF()*4-2@N |
Y = RNDF()*4-2@N |
||
N = N+16 |
N = N+16 |
||
Line 1,858: | Line 1,858: | ||
IF N < #L&&S*S+T*T < 4 GOTO @N |
IF N < #L&&S*S+T*T < 4 GOTO @N |
||
GPSET X*50+99, Y*50+99, RGB(99 XOR N,N,N) |
GPSET X*50+99, Y*50+99, RGB(99 XOR N,N,N) |
||
EXEC.</ |
EXEC.</syntaxhighlight> |
||
Alternative, based on the QBasic and other BASIC samples. |
Alternative, based on the QBasic and other BASIC samples. |
||
<br> |
<br> |
||
The 3DS screen is 400 x 240 pixels. SmileBASIC doesn't have +=, -=, etc. but there are INC and DEC statements. |
The 3DS screen is 400 x 240 pixels. SmileBASIC doesn't have +=, -=, etc. but there are INC and DEC statements. |
||
< |
<syntaxhighlight lang=basic>OPTION STRICT |
||
VAR XP, YP, X, Y, X0, Y0, X2, Y2 |
VAR XP, YP, X, Y, X0, Y0, X2, Y2 |
||
VAR NEXT_X, IT, C |
VAR NEXT_X, IT, C |
||
Line 1,882: | Line 1,882: | ||
GPSET XP + 200, YP + 120, RGB((C * 3) MOD 200 + 50, FLOOR(C * 1.2) + 20, C) |
GPSET XP + 200, YP + 120, RGB((C * 3) MOD 200 + 50, FLOOR(C * 1.2) + 20, C) |
||
NEXT |
NEXT |
||
NEXT</ |
NEXT</syntaxhighlight> |
||
==={{header|TI-Basic Color}}=== |
==={{header|TI-Basic Color}}=== |
||
{{works with|TI-84 Plus CSE, TI-83 Premium CE, TI-84 Plus CE}} |
{{works with|TI-84 Plus CSE, TI-83 Premium CE, TI-84 Plus CE}} |
||
< |
<syntaxhighlight lang=TI-BASIC> |
||
ClrDraw |
ClrDraw |
||
~2->Xmin:1->Xmax:~1->Ymin:1->Ymax |
~2->Xmin:1->Xmax:~1->Ymin:1->Ymax |
||
Line 1,902: | Line 1,902: | ||
End |
End |
||
End |
End |
||
</syntaxhighlight> |
|||
</lang> |
|||
==={{header|Visual BASIC for Applications on Excel}}=== |
==={{header|Visual BASIC for Applications on Excel}}=== |
||
{{works with|Excel 2013}} |
{{works with|Excel 2013}} |
||
Based on the BBC BASIC version. Create a spreadsheet with -2 to 2 in row 1 and -2 to 2 in the A column (in steps of your choosing). In the cell B2, call the function with =mandel(B$1,$A2) and copy the cell to all others in the range. Conditionally format the cells to make the colours pleasing (eg based on values, 3-color scale, min value 2 [colour red], midpoint number 10 [green] and highest value black. Then format the cells with the custom type "";"";"" to remove the numbers. |
Based on the BBC BASIC version. Create a spreadsheet with -2 to 2 in row 1 and -2 to 2 in the A column (in steps of your choosing). In the cell B2, call the function with =mandel(B$1,$A2) and copy the cell to all others in the range. Conditionally format the cells to make the colours pleasing (eg based on values, 3-color scale, min value 2 [colour red], midpoint number 10 [green] and highest value black. Then format the cells with the custom type "";"";"" to remove the numbers. |
||
< |
<syntaxhighlight lang=VBA> |
||
Function mandel(xi As Double, yi As Double) |
Function mandel(xi As Double, yi As Double) |
||
Line 1,923: | Line 1,923: | ||
mandel = i |
mandel = i |
||
End Function |
End Function |
||
</syntaxhighlight> |
|||
</lang> |
|||
[[File:vbamandel.png]] |
[[File:vbamandel.png]] |
||
Edit: I don't seem to be able to upload the screenshot, so I've shared it here: https://goo.gl/photos/LkezpuQziJPAtdnd9 |
Edit: I don't seem to be able to upload the screenshot, so I've shared it here: https://goo.gl/photos/LkezpuQziJPAtdnd9 |
||
==={{header|Yabasic}}=== |
==={{header|Yabasic}}=== |
||
< |
<syntaxhighlight lang=Yabasic>open window 640, 320 |
||
wid = 4 |
wid = 4 |
||
xcenter = -1: ycenter = 0 |
xcenter = -1: ycenter = 0 |
||
Line 1,964: | Line 1,964: | ||
next ycoord |
next ycoord |
||
next xcoord |
next xcoord |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Befunge}}== |
=={{header|Befunge}}== |
||
Line 1,971: | Line 1,971: | ||
X scale is (-2.0, 0.5); Y scale is (-1, 1); Max iterations 94 with the ASCII character set as the "palette". |
X scale is (-2.0, 0.5); Y scale is (-1, 1); Max iterations 94 with the ASCII character set as the "palette". |
||
< |
<syntaxhighlight lang=Befunge>0>:00p58*`#@_0>:01p78vv$$< |
||
@^+1g00,+55_v# !`\+*9<>4v$ |
@^+1g00,+55_v# !`\+*9<>4v$ |
||
@v30p20"?~^"< ^+1g10,+*8<$ |
@v30p20"?~^"< ^+1g10,+*8<$ |
||
Line 1,981: | Line 1,981: | ||
>*%03 p58*:*/01g"3"* v>::^ |
>*%03 p58*:*/01g"3"* v>::^ |
||
\_^#!:-1\+-*2*:*85<^ |
\_^#!:-1\+-*2*:*85<^ |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 2,028: | Line 2,028: | ||
=={{header|Brace}}== |
=={{header|Brace}}== |
||
This is a simple Mandelbrot plotter. A longer version based on this smooths colors, and avoids calculating the time-consuming black pixels: http://sam.ai.ki/brace/examples/mandelbrot.d/1 |
This is a simple Mandelbrot plotter. A longer version based on this smooths colors, and avoids calculating the time-consuming black pixels: http://sam.ai.ki/brace/examples/mandelbrot.d/1 |
||
< |
<syntaxhighlight lang=brace>#!/usr/bin/env bx |
||
use b |
use b |
||
Line 2,044: | Line 2,044: | ||
w = w*w + c |
w = w*w + c |
||
*px++ = i < max_i ? rainbow(i*359 / rb_i % 360) : black |
*px++ = i < max_i ? rainbow(i*359 / rb_i % 360) : black |
||
c += d</ |
c += d</syntaxhighlight> |
||
An example plot from the longer version: |
An example plot from the longer version: |
||
Line 2,051: | Line 2,051: | ||
=={{header|Brainf***}}== |
=={{header|Brainf***}}== |
||
< |
<syntaxhighlight lang=Brainf***> |
||
A mandelbrot set fractal viewer in brainf*ck written by Erik Bosman |
A mandelbrot set fractal viewer in brainf*ck written by Erik Bosman |
||
+++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[ |
+++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[ |
||
Line 2,197: | Line 2,197: | ||
+[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<< |
+[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<< |
||
<<<<<]]>>>] |
<<<<<]]>>>] |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 2,253: | Line 2,253: | ||
===PPM non interactive=== |
===PPM non interactive=== |
||
Here is one file program. It directly creates ppm file. |
Here is one file program. It directly creates ppm file. |
||
< |
<syntaxhighlight lang=C> /* |
||
c program: |
c program: |
||
-------------------------------- |
-------------------------------- |
||
Line 2,342: | Line 2,342: | ||
fclose(fp); |
fclose(fp); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
===PPM Interactive=== |
===PPM Interactive=== |
||
Line 2,351: | Line 2,351: | ||
{{libheader|GLUT}} |
{{libheader|GLUT}} |
||
< |
<syntaxhighlight lang=c>#include <stdio.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
#include <math.h> |
#include <math.h> |
||
Line 2,590: | Line 2,590: | ||
glutMainLoop(); |
glutMainLoop(); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
===ASCII=== |
===ASCII=== |
||
Not mine, found it on Ken Perlin's homepage, this deserves a place here to illustrate how awesome C can be: |
Not mine, found it on Ken Perlin's homepage, this deserves a place here to illustrate how awesome C can be: |
||
<syntaxhighlight lang=C> |
|||
<lang C> |
|||
main(k){float i,j,r,x,y=-16;while(puts(""),y++<15)for(x |
main(k){float i,j,r,x,y=-16;while(puts(""),y++<15)for(x |
||
=0;x++<84;putchar(" .:-;!/>)|&IH%*#"[k&15]))for(i=k=r=0; |
=0;x++<84;putchar(" .:-;!/>)|&IH%*#"[k&15]))for(i=k=r=0; |
||
j=r*r-i*i-2+x/25,i=2*r*i+y/10,j*j+i*i<11&&k++<111;r=j);} |
j=r*r-i*i-2+x/25,i=2*r*i+y/10,j*j+i*i<11&&k++<111;r=j);} |
||
</syntaxhighlight> |
|||
</lang> |
|||
There may be warnings on compiling but disregard them, the output will be produced nevertheless. Such programs are called obfuscated and C excels when it comes to writing such cryptic programs. Google IOCCC for more. |
There may be warnings on compiling but disregard them, the output will be produced nevertheless. Such programs are called obfuscated and C excels when it comes to writing such cryptic programs. Google IOCCC for more. |
||
<pre> |
<pre> |
||
Line 2,635: | Line 2,635: | ||
===Fixed point 16 bit arithmetic=== |
===Fixed point 16 bit arithmetic=== |
||
<syntaxhighlight lang=C> |
|||
<lang C> |
|||
/** |
/** |
||
ascii Mandelbrot using 16 bits of fixed point integer maths with a selectable fractional precision in bits. |
ascii Mandelbrot using 16 bits of fixed point integer maths with a selectable fractional precision in bits. |
||
Line 2,738: | Line 2,738: | ||
</syntaxhighlight> |
|||
</lang> |
|||
<pre> |
<pre> |
||
Line 2,813: | Line 2,813: | ||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
< |
<syntaxhighlight lang=csharp>using System; |
||
using System.Drawing; |
using System.Drawing; |
||
using System.Drawing.Imaging; |
using System.Drawing.Imaging; |
||
Line 2,950: | Line 2,950: | ||
return Re * Re + Im * Im; |
return Re * Re + Im * Im; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
This generic function assumes that the image can be accessed like a two-dimensional array of colors. It may be passed a true array (in which case the Mandelbrot set will simply be drawn into that array, which then might be saved as image file), or a class which maps the subscript operator to the pixel drawing routine of some graphics library. In the latter case, there must be functions get_first_dimension and get_second_dimension defined for that type, to be found by argument dependent lookup. The code provides those functions for built-in arrays. |
This generic function assumes that the image can be accessed like a two-dimensional array of colors. It may be passed a true array (in which case the Mandelbrot set will simply be drawn into that array, which then might be saved as image file), or a class which maps the subscript operator to the pixel drawing routine of some graphics library. In the latter case, there must be functions get_first_dimension and get_second_dimension defined for that type, to be found by argument dependent lookup. The code provides those functions for built-in arrays. |
||
< |
<syntaxhighlight lang=cpp>#include <cstdlib> |
||
#include <complex> |
#include <complex> |
||
Line 2,992: | Line 2,992: | ||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
Note this code has not been executed. |
Note this code has not been executed. |
||
Line 2,999: | Line 2,999: | ||
<br> |
<br> |
||
A Simple version in CPP. Definitely not as crazy good as the ASCII one in C above. |
A Simple version in CPP. Definitely not as crazy good as the ASCII one in C above. |
||
< |
<syntaxhighlight lang=cpp>#include <stdio.h> |
||
int f(float X, float Y, float x, float y, int n){ |
int f(float X, float Y, float x, float y, int n){ |
||
Line 3,009: | Line 3,009: | ||
for(float i=-2, x; i<=.5; i+=.015, x=f(i, j, 0, 0, 0)) |
for(float i=-2, x; i<=.5; i+=.015, x=f(i, j, 0, 0, 0)) |
||
printf("%c%s", x<10?' ':x<20?'.':x<50?':':x<80?'*':'#', i>-2?" ":"\n"); |
printf("%c%s", x<10?' ':x<20?'.':x<50?':':x<80?'*':'#', i>-2?" ":"\n"); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C3}}== |
=={{header|C3}}== |
||
This program produces a BMP as output. |
This program produces a BMP as output. |
||
< |
<syntaxhighlight lang=c3>module mandelbrot; |
||
extern fn int atoi(char *s); |
extern fn int atoi(char *s); |
||
Line 3,070: | Line 3,070: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Cixl}}== |
=={{header|Cixl}}== |
||
Displays a zooming Mandelbrot using ANSI graphics. |
Displays a zooming Mandelbrot using ANSI graphics. |
||
< |
<syntaxhighlight lang=cixl> |
||
use: cx; |
use: cx; |
||
Line 3,145: | Line 3,145: | ||
#out show-cursor |
#out show-cursor |
||
normal-mode |
normal-mode |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
{{trans|Perl}} |
{{trans|Perl}} |
||
< |
<syntaxhighlight lang=lisp>(ns mandelbrot |
||
(:refer-clojure :exclude [+ * <]) |
(:refer-clojure :exclude [+ * <]) |
||
(:use (clojure.contrib complex-numbers) |
(:use (clojure.contrib complex-numbers) |
||
Line 3,170: | Line 3,170: | ||
(println (interpose \newline (map #(apply str %) (partition 80 (mandelbrot))))) |
(println (interpose \newline (map #(apply str %) (partition 80 (mandelbrot))))) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|COBOL}}== |
=={{header|COBOL}}== |
||
EBCDIC art. |
EBCDIC art. |
||
< |
<syntaxhighlight lang=cobol>IDENTIFICATION DIVISION. |
||
PROGRAM-ID. MANDELBROT-SET-PROGRAM. |
PROGRAM-ID. MANDELBROT-SET-PROGRAM. |
||
DATA DIVISION. |
DATA DIVISION. |
||
Line 3,224: | Line 3,224: | ||
ADD X-A-SQUARED TO Y-A-SQUARED GIVING SUM-OF-SQUARES. |
ADD X-A-SQUARED TO Y-A-SQUARED GIVING SUM-OF-SQUARES. |
||
MOVE FUNCTION SQRT (SUM-OF-SQUARES) TO ROOT. |
MOVE FUNCTION SQRT (SUM-OF-SQUARES) TO ROOT. |
||
IF ROOT IS GREATER THAN 2 THEN MOVE '#' TO PLOT-CHARACTER.</ |
IF ROOT IS GREATER THAN 2 THEN MOVE '#' TO PLOT-CHARACTER.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,253: | Line 3,253: | ||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
< |
<syntaxhighlight lang=lisp>(defpackage #:mandelbrot |
||
(:use #:cl)) |
(:use #:cl)) |
||
Line 3,297: | Line 3,297: | ||
for pixel = (round (* 255 (/ (- *iteration-max* iteration) *iteration-max*))) |
for pixel = (round (* 255 (/ (- *iteration-max* iteration) *iteration-max*))) |
||
do (setf (aref image y x) pixel))) |
do (setf (aref image y x) pixel))) |
||
(write-pgm image filespec)))</ |
(write-pgm image filespec)))</syntaxhighlight> |
||
=={{header|Cowgol}}== |
=={{header|Cowgol}}== |
||
{{trans|B}} |
{{trans|B}} |
||
< |
<syntaxhighlight lang=cowgol>include "cowgol.coh"; |
||
const xmin := -8601; |
const xmin := -8601; |
||
Line 3,335: | Line 3,335: | ||
print_nl(); |
print_nl(); |
||
cy := cy + dy; |
cy := cy + dy; |
||
end loop;</ |
end loop;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>!!!!!!!!!!!!!!!"""""""""""""####################################"""""""""""""""" |
<pre>!!!!!!!!!!!!!!!"""""""""""""####################################"""""""""""""""" |
||
Line 3,365: | Line 3,365: | ||
===Textual Version=== |
===Textual Version=== |
||
This uses <code>std.complex</code> because D built-in complex numbers are deprecated. |
This uses <code>std.complex</code> because D built-in complex numbers are deprecated. |
||
< |
<syntaxhighlight lang=d>void main() { |
||
import std.stdio, std.complex; |
import std.stdio, std.complex; |
||
Line 3,377: | Line 3,377: | ||
writeln; |
writeln; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>....................................................................................... |
<pre>....................................................................................... |
||
Line 3,431: | Line 3,431: | ||
===More Functional Textual Version=== |
===More Functional Textual Version=== |
||
The output is similar. |
The output is similar. |
||
< |
<syntaxhighlight lang=d>void main() { |
||
import std.stdio, std.complex, std.range, std.algorithm; |
import std.stdio, std.complex, std.range, std.algorithm; |
||
Line 3,438: | Line 3,438: | ||
.recurrence!((a, n) => a[n - 1] ^^ 2 + complex(x, y)) |
.recurrence!((a, n) => a[n - 1] ^^ 2 + complex(x, y)) |
||
.drop(100).front.abs < 2 ? '#' : '.').writeln; |
.drop(100).front.abs < 2 ? '#' : '.').writeln; |
||
}</ |
}</syntaxhighlight> |
||
===Graphical Version=== |
===Graphical Version=== |
||
{{libheader|QD}} {{libheader|SDL}} {{libheader|Phobos}} |
{{libheader|QD}} {{libheader|SDL}} {{libheader|Phobos}} |
||
< |
<syntaxhighlight lang=d>import qd; |
||
double lensqr(cdouble c) { return c.re * c.re + c.im * c.im; } |
double lensqr(cdouble c) { return c.re * c.re + c.im * c.im; } |
||
Line 3,468: | Line 3,468: | ||
} |
} |
||
while (true) { flip; events; } |
while (true) { flip; events; } |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Dart}}== |
=={{header|Dart}}== |
||
Line 3,508: | Line 3,508: | ||
print(line); |
print(line); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Dc}}== |
=={{header|Dc}}== |
||
Line 3,517: | Line 3,517: | ||
This can be done in a more Dc-ish way, e.g. by moving the loop macros' definitions to the initialisations in the top instead of saving the macro definition of inner loops over and over again in outer loops. |
This can be done in a more Dc-ish way, e.g. by moving the loop macros' definitions to the initialisations in the top instead of saving the macro definition of inner loops over and over again in outer loops. |
||
< |
<syntaxhighlight lang=dc> _2.1 sx # xmin = -2.1 |
||
0.7 sX # xmax = 0.7 |
0.7 sX # xmax = 0.7 |
||
Line 3,585: | Line 3,585: | ||
l2 x # loop |
l2 x # loop |
||
] s2 |
] s2 |
||
l2 x</ |
l2 x</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,617: | Line 3,617: | ||
===PGM (P5) output=== |
===PGM (P5) output=== |
||
This is a condensed version of the ASCII output variant modified to generate a PGM (P5) image. |
This is a condensed version of the ASCII output variant modified to generate a PGM (P5) image. |
||
< |
<syntaxhighlight lang=dc>_2.1 sx 0.7 sX _1.2 sy 1.2 sY |
||
32 sM |
32 sM |
||
640 sW 480 sH |
640 sW 480 sH |
||
Line 3,653: | Line 3,653: | ||
l2 x |
l2 x |
||
] s2 |
] s2 |
||
l2 x</ |
l2 x</syntaxhighlight> |
||
Line 3,660: | Line 3,660: | ||
=={{header|DWScript}}== |
=={{header|DWScript}}== |
||
{{trans|D}} |
{{trans|D}} |
||
< |
<syntaxhighlight lang=delphi>const maxIter = 256; |
||
var x, y, i : Integer; |
var x, y, i : Integer; |
||
Line 3,676: | Line 3,676: | ||
end; |
end; |
||
PrintLn(''); |
PrintLn(''); |
||
end;</ |
end;</syntaxhighlight> |
||
=={{header|EasyLang}}== |
=={{header|EasyLang}}== |
||
Line 3,701: | Line 3,701: | ||
rect 0.4 0.4 |
rect 0.4 0.4 |
||
. |
. |
||
.</ |
.</syntaxhighlight> |
||
=={{header|eC}}== |
=={{header|eC}}== |
||
Line 3,709: | Line 3,709: | ||
Drawing code: |
Drawing code: |
||
< |
<syntaxhighlight lang=eC>void drawMandelbrot(Bitmap bmp, float range, Complex center, ColorAlpha * palette, int nPalEntries, int nIterations, float scale) |
||
{ |
{ |
||
int x, y; |
int x, y; |
||
Line 3,759: | Line 3,759: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
Interactive class with Rubberband Zoom: |
Interactive class with Rubberband Zoom: |
||
< |
<syntaxhighlight lang=eC>class Mandelbrot : Window |
||
{ |
{ |
||
caption = $"Mandelbrot"; |
caption = $"Mandelbrot"; |
||
Line 3,895: | Line 3,895: | ||
} |
} |
||
Mandelbrot mandelbrotForm {};</ |
Mandelbrot mandelbrotForm {};</syntaxhighlight> |
||
=={{header|EchoLisp}}== |
=={{header|EchoLisp}}== |
||
< |
<syntaxhighlight lang=scheme> |
||
(lib 'math) ;; fractal function |
(lib 'math) ;; fractal function |
||
(lib 'plot) |
(lib 'plot) |
||
Line 3,910: | Line 3,910: | ||
;; result here [http://www.echolalie.org/echolisp/help.html#fractal] |
;; result here [http://www.echolalie.org/echolisp/help.html#fractal] |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Elixir}}== |
=={{header|Elixir}}== |
||
< |
<syntaxhighlight lang=elixir>defmodule Mandelbrot do |
||
def set do |
def set do |
||
xsize = 59 |
xsize = 59 |
||
Line 3,941: | Line 3,941: | ||
end |
end |
||
Mandelbrot.set</ |
Mandelbrot.set</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,971: | Line 3,971: | ||
=={{header|Emacs Lisp}}== |
=={{header|Emacs Lisp}}== |
||
===Text mode=== |
===Text mode=== |
||
< |
<syntaxhighlight lang=lisp>; === Mandelbrot ============================================ |
||
(setq mandel-size (cons 76 34)) |
(setq mandel-size (cons 76 34)) |
||
Line 4,012: | Line 4,012: | ||
(insert(format "%s" (mandel-iter (mandel-pos x y)))))))) |
(insert(format "%s" (mandel-iter (mandel-pos x y)))))))) |
||
(mandel)</ |
(mandel)</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
<pre>---------------------------------------------------------------------------- |
<pre>---------------------------------------------------------------------------- |
||
Line 4,051: | Line 4,051: | ||
===Graphical version=== |
===Graphical version=== |
||
With a few modifications (mandel-size, mandel-iter, string-to-image, mandel-pic), the code above can also render the Mandelbrot fractal to an XPM image and display it directly in the buffer. (You might have to scroll up in Emacs after the function has run to see its output.) |
With a few modifications (mandel-size, mandel-iter, string-to-image, mandel-pic), the code above can also render the Mandelbrot fractal to an XPM image and display it directly in the buffer. (You might have to scroll up in Emacs after the function has run to see its output.) |
||
< |
<syntaxhighlight lang=lisp>; === Graphical Mandelbrot ============================================ |
||
(setq mandel-size (cons 320 300)) |
(setq mandel-size (cons 320 300)) |
||
Line 4,104: | Line 4,104: | ||
(insert-image (string-to-image all))) |
(insert-image (string-to-image all))) |
||
(mandel-pic)</ |
(mandel-pic)</syntaxhighlight> |
||
=={{header|Erlang}}== |
=={{header|Erlang}}== |
||
Line 4,115: | Line 4,115: | ||
[https://github.com/ghulette/mandelbrot-erlang Geoff Hulette's GitHub repository] provides two alternative implementations which are very interesting. |
[https://github.com/ghulette/mandelbrot-erlang Geoff Hulette's GitHub repository] provides two alternative implementations which are very interesting. |
||
< |
<syntaxhighlight lang=erlang> |
||
-module(mandelbrot). |
-module(mandelbrot). |
||
Line 4,166: | Line 4,166: | ||
% ************************************************** |
% ************************************************** |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
Line 4,215: | Line 4,215: | ||
=={{header|ERRE}}== |
=={{header|ERRE}}== |
||
< |
<syntaxhighlight lang=ERRE> |
||
PROGRAM MANDELBROT |
PROGRAM MANDELBROT |
||
Line 4,252: | Line 4,252: | ||
END FOR |
END FOR |
||
END PROGRAM |
END PROGRAM |
||
</syntaxhighlight> |
|||
</lang> |
|||
Note: This is a PC version which uses EGA 16-color 320x200. Graphic commands are taken from |
Note: This is a PC version which uses EGA 16-color 320x200. Graphic commands are taken from |
||
PC.LIB library. |
PC.LIB library. |
||
=={{header|F Sharp|F#}}== |
=={{header|F Sharp|F#}}== |
||
< |
<syntaxhighlight lang=fsharp>open System.Drawing |
||
open System.Windows.Forms |
open System.Windows.Forms |
||
type Complex = |
type Complex = |
||
Line 4,316: | Line 4,316: | ||
let f = new Mandel() |
let f = new Mandel() |
||
do Application.Run(f)</ |
do Application.Run(f)</syntaxhighlight> |
||
=== Alternate version, applicable to text and GUI === |
=== Alternate version, applicable to text and GUI === |
||
''' Basic generation code ''' |
''' Basic generation code ''' |
||
< |
<syntaxhighlight lang=fsharp> |
||
let getMandelbrotValues width height maxIter ((xMin,xMax),(yMin,yMax)) = |
let getMandelbrotValues width height maxIter ((xMin,xMax),(yMin,yMax)) = |
||
let mandIter (cr:float,ci:float) = |
let mandIter (cr:float,ci:float) = |
||
Line 4,333: | Line 4,333: | ||
fun y x -> mandIter ((xMin + dx * float(x)), (yMin + dy * float(y))) |
fun y x -> mandIter ((xMin + dx * float(x)), (yMin + dy * float(y))) |
||
[0..height-1] |> List.map(fun y->[0..width-1] |> List.map (forPos y)) |
[0..height-1] |> List.map(fun y->[0..width-1] |> List.map (forPos y)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
''' Text display ''' |
''' Text display ''' |
||
< |
<syntaxhighlight lang=fsharp> |
||
getMandelbrotValues 80 25 50 ((-2.0,1.0),(-1.0,1.0)) |
getMandelbrotValues 80 25 50 ((-2.0,1.0),(-1.0,1.0)) |
||
|> List.map(fun row-> row |> List.map (function | 0 ->" " |_->".") |> String.concat "") |
|> List.map(fun row-> row |> List.map (function | 0 ->" " |_->".") |> String.concat "") |
||
|> List.iter (printfn "%s") |
|> List.iter (printfn "%s") |
||
</syntaxhighlight> |
|||
</lang> |
|||
Results: |
Results: |
||
Line 4,373: | Line 4,373: | ||
''' Graphics display ''' |
''' Graphics display ''' |
||
< |
<syntaxhighlight lang=fsharp> |
||
open System.Drawing |
open System.Drawing |
||
open System.Windows.Forms |
open System.Windows.Forms |
||
Line 4,394: | Line 4,394: | ||
showGraphic toColor 640 480 5000 ((-2.0,1.0),(-1.0,1.0)) |
showGraphic toColor 640 480 5000 ((-2.0,1.0),(-1.0,1.0)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang=Factor> |
||
! with ("::") or without (":") generalizations: |
! with ("::") or without (":") generalizations: |
||
! : [a..b] ( steps a b -- a..b ) 2dup swap - 4 nrot 1 - / <range> ; |
! : [a..b] ( steps a b -- a..b ) 2dup swap - 4 nrot 1 - / <range> ; |
||
Line 4,431: | Line 4,431: | ||
70 25 1000 mandel |
70 25 1000 mandel |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 4,466: | Line 4,466: | ||
=={{header|Fennel}}== |
=={{header|Fennel}}== |
||
< |
<syntaxhighlight lang=Fennel> |
||
#!/usr/bin/env fennel |
#!/usr/bin/env fennel |
||
Line 4,497: | Line 4,497: | ||
max (arg-def 3 1e5)] |
max (arg-def 3 1e5)] |
||
(mandel width height max)) |
(mandel width height max)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|FOCAL}}== |
=={{header|FOCAL}}== |
||
< |
<syntaxhighlight lang=FOCAL>1.1 S I1=-1.2; S I2=1.2; S R1=-2; S R2=.5 |
||
1.2 S MIT=30 |
1.2 S MIT=30 |
||
1.3 F Y=1,24; D 2 |
1.3 F Y=1,24; D 2 |
||
Line 4,524: | Line 4,524: | ||
5.1 S T=MIT; T "*"; R |
5.1 S T=MIT; T "*"; R |
||
6.1 T " "; R</ |
6.1 T " "; R</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
<pre> |
<pre> |
||
Line 4,555: | Line 4,555: | ||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
This uses [[grayscale image]] utilities. |
This uses [[grayscale image]] utilities. |
||
< |
<syntaxhighlight lang=Forth>500 value max-iter |
||
: mandel ( gmp F: imin imax rmin rmax -- ) |
: mandel ( gmp F: imin imax rmin rmax -- ) |
||
Line 4,578: | Line 4,578: | ||
80 24 graymap |
80 24 graymap |
||
dup -1e 1e -2e 1e mandel</ |
dup -1e 1e -2e 1e mandel</syntaxhighlight> |
||
{{works with|4tH v3.64}} |
{{works with|4tH v3.64}} |
||
This is a completely integer version without local variables, which uses 4tH's native graphics library. |
This is a completely integer version without local variables, which uses 4tH's native graphics library. |
||
< |
<syntaxhighlight lang=Forth>include lib/graphics.4th \ graphics support is needed |
||
640 pic_width ! \ width of the image |
640 pic_width ! \ width of the image |
||
Line 4,624: | Line 4,624: | ||
s" mandelbt.ppm" save_image \ done, save the image |
s" mandelbt.ppm" save_image \ done, save the image |
||
dup gshow |
dup gshow |
||
free bye</ |
free bye</syntaxhighlight> |
||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
{{Works with|Fortran|90 and later}} |
{{Works with|Fortran|90 and later}} |
||
< |
<syntaxhighlight lang=fortran>program mandelbrot |
||
implicit none |
implicit none |
||
Line 4,683: | Line 4,683: | ||
close (10) |
close (10) |
||
end program mandelbrot</ |
end program mandelbrot</syntaxhighlight>bs |
||
=={{header|Frink}}== |
=={{header|Frink}}== |
||
This draws a graphical Mandelbrot set using Frink's built-in graphics and complex arithmetic. |
This draws a graphical Mandelbrot set using Frink's built-in graphics and complex arithmetic. |
||
< |
<syntaxhighlight lang=Frink> |
||
// Maximum levels for each pixel. |
// Maximum levels for each pixel. |
||
levels = 60 |
levels = 60 |
||
Line 4,722: | Line 4,722: | ||
g.show[] |
g.show[] |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Furor}}== |
=={{header|Furor}}== |
||
< |
<syntaxhighlight lang=Furor> |
||
###sysinclude X.uh |
###sysinclude X.uh |
||
$ff0000 sto szin |
$ff0000 sto szin |
||
Line 4,771: | Line 4,771: | ||
{ „XRES” } |
{ „XRES” } |
||
{ „myscreen” } |
{ „myscreen” } |
||
</syntaxhighlight> |
|||
</lang> |
|||
Line 4,778: | Line 4,778: | ||
Computes escapes for each pixel, but not the colour. |
Computes escapes for each pixel, but not the colour. |
||
< |
<syntaxhighlight lang=Futhark> |
||
default(f32) |
default(f32) |
||
Line 4,819: | Line 4,819: | ||
fun main(screenX: int, screenY: int, depth: int, xmin: f32, ymin: f32, xmax: f32, ymax: f32): [screenX][screenY]int = |
fun main(screenX: int, screenY: int, depth: int, xmin: f32, ymin: f32, xmax: f32, ymax: f32): [screenX][screenY]int = |
||
mandelbrot(screenX, screenY, depth, (xmin, ymin, xmax, ymax)) |
mandelbrot(screenX, screenY, depth, (xmin, ymin, xmax, ymax)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|FutureBasic}}== |
=={{header|FutureBasic}}== |
||
< |
<syntaxhighlight lang=futurebasic> |
||
_xmin = -8601 |
_xmin = -8601 |
||
_xmax = 2867 |
_xmax = 2867 |
||
Line 4,866: | Line 4,866: | ||
HandleEvents |
HandleEvents |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{output}} |
{{output}} |
||
<pre> |
<pre> |
||
Line 4,909: | Line 4,909: | ||
=={{header|GLSL}}== |
=={{header|GLSL}}== |
||
Uses smooth coloring. |
Uses smooth coloring. |
||
< |
<syntaxhighlight lang=glsl> |
||
const int MaxIterations = 1000; |
const int MaxIterations = 1000; |
||
const vec2 Focus = vec2(-0.51, 0.54); |
const vec2 Focus = vec2(-0.51, 0.54); |
||
Line 4,960: | Line 4,960: | ||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|gnuplot}}== |
=={{header|gnuplot}}== |
||
The output from gnuplot is controlled by setting the appropriate values for the options <code>terminal</code> and <code>output</code>. |
The output from gnuplot is controlled by setting the appropriate values for the options <code>terminal</code> and <code>output</code>. |
||
< |
<syntaxhighlight lang=gnuplot>set terminal png |
||
set output 'mandelbrot.png'</ |
set output 'mandelbrot.png'</syntaxhighlight> |
||
The following script draws an image of the number of iterations it takes to escape the circle with radius <code>rmax</code> with a maximum of <code>nmax</code>. |
The following script draws an image of the number of iterations it takes to escape the circle with radius <code>rmax</code> with a maximum of <code>nmax</code>. |
||
< |
<syntaxhighlight lang=gnuplot>rmax = 2 |
||
nmax = 100 |
nmax = 100 |
||
complex (x, y) = x * {1, 0} + y * {0, 1} |
complex (x, y) = x * {1, 0} + y * {0, 1} |
||
Line 4,975: | Line 4,975: | ||
set pm3d map |
set pm3d map |
||
set size square |
set size square |
||
splot [-2 : .8] [-1.4 : 1.4] mandelbrot (complex (0, 0), complex (x, y), 0) notitle</ |
splot [-2 : .8] [-1.4 : 1.4] mandelbrot (complex (0, 0), complex (x, y), 0) notitle</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[[File:mandelbrot.png]] |
[[File:mandelbrot.png]] |
||
Line 4,982: | Line 4,982: | ||
;Text |
;Text |
||
Prints an 80-char by 41-line depiction. |
Prints an 80-char by 41-line depiction. |
||
< |
<syntaxhighlight lang=go>package main |
||
import "fmt" |
import "fmt" |
||
Line 5,005: | Line 5,005: | ||
fmt.Println("") |
fmt.Println("") |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
;Graphical |
;Graphical |
||
[[File:GoMandelbrot.png|thumb|right|.png image]] |
[[File:GoMandelbrot.png|thumb|right|.png image]] |
||
< |
<syntaxhighlight lang=go>package main |
||
import ( |
import ( |
||
Line 5,067: | Line 5,067: | ||
fmt.Println(err) |
fmt.Println(err) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Golfscript}}== |
=={{header|Golfscript}}== |
||
Código sacado de https://codegolf.stackexchange.com/ |
Código sacado de https://codegolf.stackexchange.com/ |
||
< |
<syntaxhighlight lang=golfscript>20{40{0.1{.{;..*2$.*\- |
||
20/3$-@@*10/3$-..*2$.*+1600<}*}32*' |
20/3$-@@*10/3$-..*2$.*+1600<}*}32*' |
||
*'=\;\;@@(}60*;(n\}40*;]''+</ |
*'=\;\;@@(}60*;(n\}40*;]''+</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>000000000000000000000000000000000000000010000000000000000000 |
<pre>000000000000000000000000000000000000000010000000000000000000 |
||
Line 5,119: | Line 5,119: | ||
=={{header|Hare}}== |
=={{header|Hare}}== |
||
{{trans|D}} |
{{trans|D}} |
||
< |
<syntaxhighlight lang=hare>use fmt; |
||
use math; |
use math; |
||
Line 5,148: | Line 5,148: | ||
fn abs(z: complex) f64 = { |
fn abs(z: complex) f64 = { |
||
return math::sqrtf64(z.re*z.re + z.im*z.im); |
return math::sqrtf64(z.re*z.re + z.im*z.im); |
||
};</ |
};</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 5,203: | Line 5,203: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
{{trans|Ruby}} |
{{trans|Ruby}} |
||
< |
<syntaxhighlight lang=haskell>import Data.Bool ( bool ) |
||
import Data.Complex (Complex ((:+)), magnitude) |
import Data.Complex (Complex ((:+)), magnitude) |
||
Line 5,217: | Line 5,217: | ||
] |
] |
||
| y <- [1, 0.95 .. -1] |
| y <- [1, 0.95 .. -1] |
||
]</ |
]</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre> |
<pre> |
||
Line 5,257: | Line 5,257: | ||
'''haskell one-liners :''' |
'''haskell one-liners :''' |
||
< |
<syntaxhighlight lang=haskell> |
||
-- first attempt |
-- first attempt |
||
Line 5,272: | Line 5,272: | ||
-- open GHCI > Copy and paste any of above one-liners > Hit enter |
-- open GHCI > Copy and paste any of above one-liners > Hit enter |
||
</syntaxhighlight> |
|||
</lang> |
|||
A legible variant of the first of the "one-liner" contributions above: |
A legible variant of the first of the "one-liner" contributions above: |
||
< |
<syntaxhighlight lang=haskell>main :: IO () |
||
main = |
main = |
||
putStrLn $ |
putStrLn $ |
||
Line 5,307: | Line 5,307: | ||
) |
) |
||
[".", "\'", ":", "!", "|", "}", "#", " "] |
[".", "\'", ":", "!", "|", "}", "#", " "] |
||
)</ |
)</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre> # |
<pre> # |
||
Line 5,400: | Line 5,400: | ||
and a legible variant of the last of the "one-liner" contributions above: |
and a legible variant of the last of the "one-liner" contributions above: |
||
< |
<syntaxhighlight lang=haskell>main :: IO () |
||
main = |
main = |
||
mapM_ |
mapM_ |
||
Line 5,419: | Line 5,419: | ||
else ' ' |
else ' ' |
||
] |
] |
||
]</ |
]</syntaxhighlight> |
||
=={{header|Haxe}}== |
=={{header|Haxe}}== |
||
This version compiles for flash version 9 or greater. |
This version compiles for flash version 9 or greater. |
||
The compilation command is |
The compilation command is |
||
< |
<syntaxhighlight lang=haxe>haxe -swf mandelbrot.swf -main Mandelbrot</syntaxhighlight> |
||
< |
<syntaxhighlight lang=haxe>class Mandelbrot extends flash.display.Sprite |
||
{ |
{ |
||
inline static var MAX_ITER = 255; |
inline static var MAX_ITER = 255; |
||
Line 5,474: | Line 5,474: | ||
image.setPixel(x, y, color); |
image.setPixel(x, y, color); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Huginn}}== |
=={{header|Huginn}}== |
||
< |
<syntaxhighlight lang=huginn>#! /bin/sh |
||
exec huginn -E "${0}" "${@}" |
exec huginn -E "${0}" "${@}" |
||
#! huginn |
#! huginn |
||
Line 5,531: | Line 5,531: | ||
columns -= 1; |
columns -= 1; |
||
return ( ( lines, columns ) ); |
return ( ( lines, columns ) ); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 5,580: | Line 5,580: | ||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
< |
<syntaxhighlight lang=Icon>link graphics |
||
procedure main() |
procedure main() |
||
Line 5,625: | Line 5,625: | ||
procedure cAbs(x) |
procedure cAbs(x) |
||
return sqrt(x.r*x.r+x.i*x.i) |
return sqrt(x.r*x.r+x.i*x.i) |
||
end</ |
end</syntaxhighlight> |
||
{{libheader|Icon Programming Library}} |
{{libheader|Icon Programming Library}} |
||
Line 5,636: | Line 5,636: | ||
(free implementation: GDL - GNU Data Language |
(free implementation: GDL - GNU Data Language |
||
http://gnudatalanguage.sourceforge.net) |
http://gnudatalanguage.sourceforge.net) |
||
< |
<syntaxhighlight lang=IDL> |
||
PRO Mandelbrot,xRange,yRange,xPixels,yPixels,iterations |
PRO Mandelbrot,xRange,yRange,xPixels,yPixels,iterations |
||
Line 5,683: | Line 5,683: | ||
END |
END |
||
</syntaxhighlight> |
|||
</lang> |
|||
from the command line: |
from the command line: |
||
< |
<syntaxhighlight lang=IDL> |
||
GDL>.run mandelbrot |
GDL>.run mandelbrot |
||
</syntaxhighlight> |
|||
</lang> |
|||
or |
or |
||
< |
<syntaxhighlight lang=IDL> |
||
GDL> Mandelbrot,[-1.,2.3],[-1.3,1.3],640,512,200 |
GDL> Mandelbrot,[-1.,2.3],[-1.3,1.3],640,512,200 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Inform 7}}== |
=={{header|Inform 7}}== |
||
{{libheader|Glimmr Drawing Commands by Erik Temple}} |
{{libheader|Glimmr Drawing Commands by Erik Temple}} |
||
{{works with|Glulx virtual machine}} |
{{works with|Glulx virtual machine}} |
||
< |
<syntaxhighlight lang=inform7>"Mandelbrot" |
||
The story headline is "A Non-Interactive Set". |
The story headline is "A Non-Interactive Set". |
||
Line 5,881: | Line 5,881: | ||
[ fneg n; @bitxor n $80000000 n; return n; ]; |
[ fneg n; @bitxor n $80000000 n; return n; ]; |
||
#endif; |
#endif; |
||
-).</ |
-).</syntaxhighlight> |
||
Newer Glulx interpreters provide 32-bit floating-point operations, but this solution also supports fixed-point math which is more widely supported and accurate enough for a zoomed-out view. Inform 6 inclusions are used for the low-level math functions in either case. The rendering process is extremely slow, since the graphics system is not optimized for pixel-by-pixel drawing, so this solution includes an optimization for vertical symmetry (as in the default view) and also includes extra logic to draw the lines in a more immediately useful order. |
Newer Glulx interpreters provide 32-bit floating-point operations, but this solution also supports fixed-point math which is more widely supported and accurate enough for a zoomed-out view. Inform 6 inclusions are used for the low-level math functions in either case. The rendering process is extremely slow, since the graphics system is not optimized for pixel-by-pixel drawing, so this solution includes an optimization for vertical symmetry (as in the default view) and also includes extra logic to draw the lines in a more immediately useful order. |
||
Line 5,889: | Line 5,889: | ||
=={{header|J}}== |
=={{header|J}}== |
||
The characteristic function of the Mandelbrot can be defined as follows: |
The characteristic function of the Mandelbrot can be defined as follows: |
||
< |
<syntaxhighlight lang=j>mcf=. (<: 2:)@|@(] ((*:@] + [)^:((<: 2:)@|@])^:1000) 0:) NB. 1000 iterations test</syntaxhighlight> |
||
The Mandelbrot set can be drawn as follows: |
The Mandelbrot set can be drawn as follows: |
||
< |
<syntaxhighlight lang=j>domain=. |.@|:@({.@[ + ] *~ j./&i.&>/@+.@(1j1 + ] %~ -~/@[))&>/ |
||
load 'viewmat' |
load 'viewmat' |
||
viewmat mcf "0 @ domain (_2j_1 1j1) ; 0.01 NB. Complex interval and resolution</ |
viewmat mcf "0 @ domain (_2j_1 1j1) ; 0.01 NB. Complex interval and resolution</syntaxhighlight> |
||
A smaller version, based on a black&white implementation of viewmat (and paraphrased, from html markup to wiki markup), is shown [[Mandelbrot_set/J/Output|here]] (The output is HTML-heavy and was split out to make editing this page easier): |
A smaller version, based on a black&white implementation of viewmat (and paraphrased, from html markup to wiki markup), is shown [[Mandelbrot_set/J/Output|here]] (The output is HTML-heavy and was split out to make editing this page easier): |
||
< |
<syntaxhighlight lang=j> viewmat mcf "0 @ domain (_2j_1 1j1) ; 0.1 NB. Complex interval and resolution</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{libheader|Swing}} {{libheader|AWT}} |
{{libheader|Swing}} {{libheader|AWT}} |
||
< |
<syntaxhighlight lang=java>import java.awt.Graphics; |
||
import java.awt.image.BufferedImage; |
import java.awt.image.BufferedImage; |
||
import javax.swing.JFrame; |
import javax.swing.JFrame; |
||
Line 5,944: | Line 5,944: | ||
new Mandelbrot().setVisible(true); |
new Mandelbrot().setVisible(true); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=== Interactive === |
=== Interactive === |
||
{{libheader|AWT}} {{libheader|Swing}} |
{{libheader|AWT}} {{libheader|Swing}} |
||
< |
<syntaxhighlight lang=java>import static java.awt.Color.HSBtoRGB; |
||
import static java.awt.Color.black; |
import static java.awt.Color.black; |
||
import static java.awt.event.KeyEvent.VK_BACK_SLASH; |
import static java.awt.event.KeyEvent.VK_BACK_SLASH; |
||
Line 6,240: | Line 6,240: | ||
; |
; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
Line 6,249: | Line 6,249: | ||
The code can be run directly from the Javascript console in modern browsers by copying and pasting it. |
The code can be run directly from the Javascript console in modern browsers by copying and pasting it. |
||
< |
<syntaxhighlight lang=javascript>function mandelIter(cx, cy, maxIter) { |
||
var x = 0.0; |
var x = 0.0; |
||
var y = 0.0; |
var y = 0.0; |
||
Line 6,317: | Line 6,317: | ||
document.body.insertBefore(canvas, document.body.childNodes[0]); |
document.body.insertBefore(canvas, document.body.childNodes[0]); |
||
mandelbrot(canvas, -2, 1, -1, 1, 1000);</ |
mandelbrot(canvas, -2, 1, -1, 1, 1000);</syntaxhighlight> |
||
{{out}} with default parameters: |
{{out}} with default parameters: |
||
Line 6,327: | Line 6,327: | ||
one for instance with the [https://mbebenita.github.io/WasmExplorer/ WebAssembly explorer] |
one for instance with the [https://mbebenita.github.io/WasmExplorer/ WebAssembly explorer] |
||
< |
<syntaxhighlight lang=javascript>var mandelIter; |
||
fetch("./mandelIter.wasm") |
fetch("./mandelIter.wasm") |
||
.then(res => { |
.then(res => { |
||
Line 6,348: | Line 6,348: | ||
mandelbrot(canvas, -2, 1, -1, 1, 1000); |
mandelbrot(canvas, -2, 1, -1, 1, 1000); |
||
// ... |
// ... |
||
}</ |
}</syntaxhighlight> |
||
=={{header|jq}}== |
=={{header|jq}}== |
||
Line 6,358: | Line 6,358: | ||
'''Preliminaries''' |
'''Preliminaries''' |
||
< |
<syntaxhighlight lang=jq># SVG STUFF |
||
def svg(id; width; height): |
def svg(id; width; height): |
||
"<svg width='\(width // "100%")' height='\(height // "100%") ' |
"<svg width='\(width // "100%")' height='\(height // "100%") ' |
||
Line 6,372: | Line 6,372: | ||
def u: if condition then . else (next|u) end; |
def u: if condition then . else (next|u) end; |
||
u; |
u; |
||
</ |
</syntaxhighlight><syntaxhighlight lang=jq> |
||
def Mandeliter( cx; cy; maxiter ): |
def Mandeliter( cx; cy; maxiter ): |
||
# [i, x, y, x^2+y^2] |
# [i, x, y, x^2+y^2] |
||
Line 6,412: | Line 6,412: | ||
svg("mandelbrot"; "100%"; "100%"), |
svg("mandelbrot"; "100%"; "100%"), |
||
pixies, |
pixies, |
||
"</svg>";</ |
"</svg>";</syntaxhighlight> |
||
'''Example''': |
'''Example''': |
||
< |
<syntaxhighlight lang=jq> Mandelbrot( {"xmin": -2, "xmax": 1, "ymin": -1, "ymax":1}; 900; 600; 1000 ) </syntaxhighlight> |
||
'''Execution:''' |
'''Execution:''' |
||
Line 6,426: | Line 6,426: | ||
Generates an ASCII representation: |
Generates an ASCII representation: |
||
< |
<syntaxhighlight lang=python>function mandelbrot(a) |
||
z = 0 |
z = 0 |
||
for i=1:50 |
for i=1:50 |
||
Line 6,439: | Line 6,439: | ||
end |
end |
||
println() |
println() |
||
end</ |
end</syntaxhighlight> |
||
This generates a PNG image file: |
This generates a PNG image file: |
||
< |
<syntaxhighlight lang=python>using Images |
||
@inline function hsv2rgb(h, s, v) |
@inline function hsv2rgb(h, s, v) |
||
Line 6,481: | Line 6,481: | ||
img = mandelbrot() |
img = mandelbrot() |
||
save("mandelbrot.png", img)</ |
save("mandelbrot.png", img)</syntaxhighlight> |
||
===Mandelbrot Set with Julia Animation=== |
===Mandelbrot Set with Julia Animation=== |
||
This is an extension of the corresponding R section: e^(-|z|)-smoothing was added. |
This is an extension of the corresponding R section: e^(-|z|)-smoothing was added. |
||
< |
<syntaxhighlight lang=julia>using Plots |
||
gr(aspect_ratio=:equal, legend=false, axis=false, ticks=false, dpi=100) |
gr(aspect_ratio=:equal, legend=false, axis=false, ticks=false, dpi=100) |
||
Line 6,511: | Line 6,511: | ||
gif(animation, "Mandelbrot_animation.gif", fps=2) |
gif(animation, "Mandelbrot_animation.gif", fps=2) |
||
gif(smoothing, "Mandelbrot_smoothing.gif", fps=2)</ |
gif(smoothing, "Mandelbrot_smoothing.gif", fps=2)</syntaxhighlight> |
||
===Normalized Counting, Distance Estimation, Mercator Maps and Perturbation Theory === |
===Normalized Counting, Distance Estimation, Mercator Maps and Perturbation Theory === |
||
This is an extension of the corresponding Python section to include higher precision calculations for larger zoom depths. The ''e^(-|z|)-smoothing'', ''normalized iteration count'' and ''exterior distance estimation'' algorithms are used. |
This is an extension of the corresponding Python section to include higher precision calculations for larger zoom depths. The ''e^(-|z|)-smoothing'', ''normalized iteration count'' and ''exterior distance estimation'' algorithms are used. |
||
< |
<syntaxhighlight lang=julia>using Plots |
||
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200) |
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200) |
||
Line 6,549: | Line 6,549: | ||
heatmap(D .^ 0.1, c=:jet) |
heatmap(D .^ 0.1, c=:jet) |
||
savefig("Mandelbrot_set_3.png")</ |
savefig("Mandelbrot_set_3.png")</syntaxhighlight> |
||
A small change in the code above creates Mercator maps and zoom images of the Mandelbrot set. The abs2 function is used to speed up the calculations inside the loop. See also the album [https://www.flickr.com/photos/arenamontanus/albums/72157615740829949 Mercator Mandelbrot Maps] by Anders Sandberg. |
A small change in the code above creates Mercator maps and zoom images of the Mandelbrot set. The abs2 function is used to speed up the calculations inside the loop. See also the album [https://www.flickr.com/photos/arenamontanus/albums/72157615740829949 Mercator Mandelbrot Maps] by Anders Sandberg. |
||
< |
<syntaxhighlight lang=julia>using Plots |
||
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200) |
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200) |
||
Line 6,587: | Line 6,587: | ||
p4 = scatter(X[4*z+1:4*z+c,:], Y[4*z+1:4*z+c,:], markersize=R[1:c,:], marker_z=D[4*z+1:4*z+c,:].^0.2, c=:nipy_spectral) |
p4 = scatter(X[4*z+1:4*z+c,:], Y[4*z+1:4*z+c,:], markersize=R[1:c,:], marker_z=D[4*z+1:4*z+c,:].^0.2, c=:nipy_spectral) |
||
plot(p1, p2, p3, p4, layout=(2, 2)) |
plot(p1, p2, p3, p4, layout=(2, 2)) |
||
savefig("Mercator_Mandelbrot_plot.png")</ |
savefig("Mercator_Mandelbrot_plot.png")</syntaxhighlight> |
||
For deep zoom images it is sufficient to calculate a single point with high accuracy. A good approximation can then be found for all other points by means of a perturbation calculation with standard accuracy. Placing the iteration in a separate function speeds up the calculation. See [https://en.wikipedia.org/wiki/Plotting_algorithms_for_the_Mandelbrot_set#Perturbation_theory_and_series_approximation Perturbation theory] (Wikipedia) and [https://gbillotey.github.io/Fractalshades-doc/math.html Mathematical background] (Fractalshades) for more details. |
For deep zoom images it is sufficient to calculate a single point with high accuracy. A good approximation can then be found for all other points by means of a perturbation calculation with standard accuracy. Placing the iteration in a separate function speeds up the calculation. See [https://en.wikipedia.org/wiki/Plotting_algorithms_for_the_Mandelbrot_set#Perturbation_theory_and_series_approximation Perturbation theory] (Wikipedia) and [https://gbillotey.github.io/Fractalshades-doc/math.html Mathematical background] (Fractalshades) for more details. |
||
< |
<syntaxhighlight lang=julia>using Plots |
||
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200) |
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200) |
||
Line 6,636: | Line 6,636: | ||
heatmap(D .^ 0.25, c=:nipy_spectral) |
heatmap(D .^ 0.25, c=:nipy_spectral) |
||
savefig("Mandelbrot_deep_zoom.png")</ |
savefig("Mandelbrot_deep_zoom.png")</syntaxhighlight> |
||
Of course, deep Mercator maps can also be created. See also the image [https://www.flickr.com/photos/arenamontanus/3430921497/in/album-72157615740829949/ Deeper Mercator Mandelbrot] by Anders Sandberg. To reduce glitches, an additional reference sequence for the derivation (dS) is recorded with high precision. |
Of course, deep Mercator maps can also be created. See also the image [https://www.flickr.com/photos/arenamontanus/3430921497/in/album-72157615740829949/ Deeper Mercator Mandelbrot] by Anders Sandberg. To reduce glitches, an additional reference sequence for the derivation (dS) is recorded with high precision. |
||
< |
<syntaxhighlight lang=julia>using Plots |
||
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200) |
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200) |
||
Line 6,685: | Line 6,685: | ||
heatmap(D' .^ 0.025, c=:nipy_spectral) |
heatmap(D' .^ 0.025, c=:nipy_spectral) |
||
savefig("Mercator_Mandelbrot_deep_map.png")</ |
savefig("Mercator_Mandelbrot_deep_map.png")</syntaxhighlight> |
||
Due to abs(z - epsilon) < 2 and the second reference sequence, Z and dZ can be calculated after the loop. This massively reduces the computing time. |
Due to abs(z - epsilon) < 2 and the second reference sequence, Z and dZ can be calculated after the loop. This massively reduces the computing time. |
||
< |
<syntaxhighlight lang=julia>Z, dZ, E, dE = zero(C), zero(C), zero(C), zero(C) |
||
D, I = zeros(size(C)), ones(Int64, size(C)) |
D, I = zeros(size(C)), ones(Int64, size(C)) |
||
Line 6,701: | Line 6,701: | ||
N = abs.(Z) .> 2 # exterior distance estimation |
N = abs.(Z) .> 2 # exterior distance estimation |
||
D[N] = 0.5 .* log.(abs.(Z[N])) .* abs.(Z[N]) ./ abs.(dZ[N])</ |
D[N] = 0.5 .* log.(abs.(Z[N])) .* abs.(Z[N]) ./ abs.(dZ[N])</syntaxhighlight> |
||
Another approach to reducing glitches is rebasing. See [https://gbillotey.github.io/Fractalshades-doc/math.html#avoiding-loss-of-precision Avoiding loss of precision] (Fractalshades) and [https://fractalforums.org/fractal-mathematics-and-new-theories/28/another-solution-to-perturbation-glitches/4360 Another solution to perturbation glitches] (Fractalforums) for details. |
Another approach to reducing glitches is rebasing. See [https://gbillotey.github.io/Fractalshades-doc/math.html#avoiding-loss-of-precision Avoiding loss of precision] (Fractalshades) and [https://fractalforums.org/fractal-mathematics-and-new-theories/28/another-solution-to-perturbation-glitches/4360 Another solution to perturbation glitches] (Fractalforums) for details. |
||
< |
<syntaxhighlight lang=julia>Z, dZ, E = zero(C), zero(C), zero(C) |
||
D, I, J = zeros(size(C)), ones(Int64, size(C)), ones(Int64, size(C)) |
D, I, J = zeros(size(C)), ones(Int64, size(C)), ones(Int64, size(C)) |
||
Line 6,718: | Line 6,718: | ||
N = abs.(Z) .> 2 # exterior distance estimation |
N = abs.(Z) .> 2 # exterior distance estimation |
||
D[N] = 0.5 .* log.(abs.(Z[N])) .* abs.(Z[N]) ./ abs.(dZ[N])</ |
D[N] = 0.5 .* log.(abs.(Z[N])) .* abs.(Z[N]) ./ abs.(dZ[N])</syntaxhighlight> |
||
The rebasing condition abs(z) < abs(epsilon) does not define a circular area but a half-plane. If you insert a factor, the condition abs(z) < gamma * abs(epsilon) for 0 < gamma < 1 defines a circular area containing the origin. For example, if the reference point is at S(1, 0), the equation abs(z) = abs(epsilon) defines the set of all points that are equidistant from O(0, 0) and S(1, 0). This is exactly the perpendicular bisector x = 1/2. Considering instead the equation abs(z) = 1/2 * abs(epsilon), one finds all points half as far from O(0, 0) as from S(1, 0). All these points lie on a circle, which has center M(-1/3, 0) and radius R = 2/3. If you choose a factor gamma > 1, you get corresponding circles containing the reference point S. However, the condition abs(z) < abs(epsilon) is optimal because it keeps the differences epsilon to the reference sequence as small as possible. Rebasing occurs if and only if the distance abs(epsilon) to the reference sequence becomes smaller as a result. You can only rebase to the beginning of the reference sequence. If you want to rebase to the reference point S[m], the difference epsilon = z - S[m] must be calculated. With this subtraction, however, the entire precision is lost due to cancellation. Only at the first reference point there is no cancellation due to S[1] = 0, because epsilon = z - S[1] = z - 0 = z. The images can be verified by a (slow) calculation with BigFloats. |
The rebasing condition abs(z) < abs(epsilon) does not define a circular area but a half-plane. If you insert a factor, the condition abs(z) < gamma * abs(epsilon) for 0 < gamma < 1 defines a circular area containing the origin. For example, if the reference point is at S(1, 0), the equation abs(z) = abs(epsilon) defines the set of all points that are equidistant from O(0, 0) and S(1, 0). This is exactly the perpendicular bisector x = 1/2. Considering instead the equation abs(z) = 1/2 * abs(epsilon), one finds all points half as far from O(0, 0) as from S(1, 0). All these points lie on a circle, which has center M(-1/3, 0) and radius R = 2/3. If you choose a factor gamma > 1, you get corresponding circles containing the reference point S. However, the condition abs(z) < abs(epsilon) is optimal because it keeps the differences epsilon to the reference sequence as small as possible. Rebasing occurs if and only if the distance abs(epsilon) to the reference sequence becomes smaller as a result. You can only rebase to the beginning of the reference sequence. If you want to rebase to the reference point S[m], the difference epsilon = z - S[m] must be calculated. With this subtraction, however, the entire precision is lost due to cancellation. Only at the first reference point there is no cancellation due to S[1] = 0, because epsilon = z - S[1] = z - 0 = z. The images can be verified by a (slow) calculation with BigFloats. |
||
< |
<syntaxhighlight lang=julia>using Plots |
||
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200) |
gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200) |
||
Line 6,753: | Line 6,753: | ||
heatmap(D' .^ 0.025, c=:nipy_spectral) |
heatmap(D' .^ 0.025, c=:nipy_spectral) |
||
savefig("Mercator_Mandelbrot_big_map.png")</ |
savefig("Mercator_Mandelbrot_big_map.png")</syntaxhighlight> |
||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
< |
<syntaxhighlight lang=scala>// version 1.1.2 |
||
import java.awt.Graphics |
import java.awt.Graphics |
||
Line 6,801: | Line 6,801: | ||
fun main(args: Array<String>) { |
fun main(args: Array<String>) { |
||
Mandelbrot().isVisible = true |
Mandelbrot().isVisible = true |
||
}</ |
}</syntaxhighlight> |
||
=={{header|LabVIEW}}== |
=={{header|LabVIEW}}== |
||
Line 6,809: | Line 6,809: | ||
=={{header|Lang5}}== |
=={{header|Lang5}}== |
||
< |
<syntaxhighlight lang=Lang5> |
||
: d2c(*,*) 2 compress 'c dress ; # Make a complex number. |
: d2c(*,*) 2 compress 'c dress ; # Make a complex number. |
||
Line 6,823: | Line 6,823: | ||
iterate abs int 5 min 'print_line apply # Compute & print |
iterate abs int 5 min 'print_line apply # Compute & print |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Lambdatalk}}== |
=={{header|Lambdatalk}}== |
||
Line 6,832: | Line 6,832: | ||
Here we show a pure lambdatalk code, a slow but minimalistic and easy to understand version without the burden of any canvas. We just compute if a point is inside or outside the mandelbrot set and just write "o" or "." directly in the wiki page. |
Here we show a pure lambdatalk code, a slow but minimalistic and easy to understand version without the burden of any canvas. We just compute if a point is inside or outside the mandelbrot set and just write "o" or "." directly in the wiki page. |
||
< |
<syntaxhighlight lang=Scheme> |
||
{def mandel |
{def mandel |
||
Line 6,864: | Line 6,864: | ||
{S.serie 0 40}} // y resolution |
{S.serie 0 40}} // y resolution |
||
</syntaxhighlight> |
|||
</lang> |
|||
<pre> |
<pre> |
||
Line 6,911: | Line 6,911: | ||
=={{header|Lasso}}== |
=={{header|Lasso}}== |
||
< |
<syntaxhighlight lang=Lasso> |
||
define mandelbrotBailout => 16 |
define mandelbrotBailout => 16 |
||
define mandelbrotMaxIterations => 1000 |
define mandelbrotMaxIterations => 1000 |
||
Line 6,963: | Line 6,963: | ||
mandelbrotTest |
mandelbrotTest |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<small> |
<small> |
||
Line 7,048: | Line 7,048: | ||
=={{header|LIL}}== |
=={{header|LIL}}== |
||
From the source distribution. Produces a PBM, not shown here. |
From the source distribution. Produces a PBM, not shown here. |
||
< |
<syntaxhighlight lang=tcl># |
||
# A mandelbrot generator that outputs a PBM file. This can be used to measure |
# A mandelbrot generator that outputs a PBM file. This can be used to measure |
||
# performance differences between LIL versions and measure performance |
# performance differences between LIL versions and measure performance |
||
Line 7,109: | Line 7,109: | ||
}} |
}} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Logo}}== |
=={{header|Logo}}== |
||
{{works with|UCB Logo}} |
{{works with|UCB Logo}} |
||
< |
<syntaxhighlight lang=logo>to mandelbrot :left :bottom :side :size |
||
cs setpensize [1 1] |
cs setpensize [1 1] |
||
make "inc :side/:size |
make "inc :side/:size |
||
Line 7,147: | Line 7,147: | ||
end |
end |
||
mandelbrot -2 -1.25 2.5 400</ |
mandelbrot -2 -1.25 2.5 400</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
===Graphical=== |
===Graphical=== |
||
Needs LÖVE 2D Engine<br />Zoom in: drag the mouse; zoom out: right click |
Needs LÖVE 2D Engine<br />Zoom in: drag the mouse; zoom out: right click |
||
< |
<syntaxhighlight lang=lua> |
||
local maxIterations = 250 |
local maxIterations = 250 |
||
local minX, maxX, minY, maxY = -2.5, 2.5, -2.5, 2.5 |
local minX, maxX, minY, maxY = -2.5, 2.5, -2.5, 2.5 |
||
Line 7,221: | Line 7,221: | ||
love.graphics.draw( canvas ) |
love.graphics.draw( canvas ) |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
===ASCII=== |
===ASCII=== |
||
< |
<syntaxhighlight lang=lua>-- Mandelbrot set in Lua 6/15/2020 db |
||
local charmap = { [0]=" ", ".", ":", "-", "=", "+", "*", "#", "%", "@" } |
local charmap = { [0]=" ", ".", ":", "-", "=", "+", "*", "#", "%", "@" } |
||
for y = -1.3, 1.3, 0.1 do |
for y = -1.3, 1.3, 0.1 do |
||
Line 7,235: | Line 7,235: | ||
end |
end |
||
print() |
print() |
||
end</ |
end</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>...............::::::::::::::::::---------------:::::::::::::::::::::::::::::::: |
<pre>...............::::::::::::::::::---------------:::::::::::::::::::::::::::::::: |
||
Line 7,268: | Line 7,268: | ||
Console is a bitmap so we can plot on it. A subroutine plot different size of pixels so we get Mandelbrot image at final same size for 32X26 for a big pixel of 16x16 pixels to 512x416 for a 1:1 pixel. Iterations for each pixel set to 25. Module can get left top corner as twips, and the size factor from 1 to 16 (size of output is 512x416 pixels for any factor). |
Console is a bitmap so we can plot on it. A subroutine plot different size of pixels so we get Mandelbrot image at final same size for 32X26 for a big pixel of 16x16 pixels to 512x416 for a 1:1 pixel. Iterations for each pixel set to 25. Module can get left top corner as twips, and the size factor from 1 to 16 (size of output is 512x416 pixels for any factor). |
||
< |
<syntaxhighlight lang=M2000 Interpreter> |
||
Module Mandelbrot(x=0&,y=0&,z=1&) { |
Module Mandelbrot(x=0&,y=0&,z=1&) { |
||
If z<1 then z=1 |
If z<1 then z=1 |
||
Line 7,308: | Line 7,308: | ||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Version 2 without Subroutine. Also there is a screen refresh every 2 seconds. |
Version 2 without Subroutine. Also there is a screen refresh every 2 seconds. |
||
< |
<syntaxhighlight lang=M2000 Interpreter> |
||
Module Mandelbrot(x=0&,y=0&,z=1&) { |
Module Mandelbrot(x=0&,y=0&,z=1&) { |
||
If z<1 then z=1 |
If z<1 then z=1 |
||
Line 7,350: | Line 7,350: | ||
Mandelbrot 250*twipsx,100*twipsy, array(i) |
Mandelbrot 250*twipsx,100*twipsy, array(i) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Maple}}== |
=={{header|Maple}}== |
||
<lang>ImageTools:-Embed(Fractals[EscapeTime]:-Mandelbrot(500, -2.0-1.35*I, .7+1.35*I, output = layer1));</ |
<lang>ImageTools:-Embed(Fractals[EscapeTime]:-Mandelbrot(500, -2.0-1.35*I, .7+1.35*I, output = layer1));</syntaxhighlight> |
||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
The implementation could be better. But this is a start... |
The implementation could be better. But this is a start... |
||
< |
<syntaxhighlight lang=mathematica>eTime[c_, maxIter_Integer: 100] := Length@NestWhileList[#^2 + c &, 0, Abs@# <= 2 &, 1, maxIter] - 1 |
||
DistributeDefinitions[eTime]; |
DistributeDefinitions[eTime]; |
||
mesh = ParallelTable[eTime[x + I*y, 1000], {y, 1.2, -1.2, -0.01}, {x, -1.72, 1, 0.01}]; |
mesh = ParallelTable[eTime[x + I*y, 1000], {y, 1.2, -1.2, -0.01}, {x, -1.72, 1, 0.01}]; |
||
ReliefPlot[mesh, Frame -> False]</ |
ReliefPlot[mesh, Frame -> False]</syntaxhighlight> |
||
Faster version: |
Faster version: |
||
< |
<syntaxhighlight lang=mathematica>cf = With[{ |
||
mandel = Block[{z = #, c = #}, |
mandel = Block[{z = #, c = #}, |
||
Catch@Do[If[Abs[z] > 2, Throw@i]; z = z^2 + c, {i, 100}]] & |
Catch@Do[If[Abs[z] > 2, Throw@i]; z = z^2 + c, {i, 100}]] & |
||
Line 7,369: | Line 7,369: | ||
Compile[{},Table[mandel[y + x I], {x, -1, 1, 0.005}, {y, -2, 0.5, 0.005}]] |
Compile[{},Table[mandel[y + x I], {x, -1, 1, 0.005}, {y, -2, 0.5, 0.005}]] |
||
]; |
]; |
||
ArrayPlot[cf[]] </ |
ArrayPlot[cf[]] </syntaxhighlight> |
||
Built-in function: |
Built-in function: |
||
<lang |
<syntaxhighlight lang=mathematica>MandelbrotSetPlot[]</syntaxhighlight> |
||
==Mathmap == |
==Mathmap == |
||
Line 7,392: | Line 7,392: | ||
This solution uses the escape time algorithm to determine the coloring of the coordinates on the complex plane. The code can be reduced to a single line via vectorization after the Escape Time Algorithm function definition, but the code becomes unnecessarily obfuscated. Also, this code uses a lot of memory. You will need a computer with a lot of memory to compute the set with high resolution. |
This solution uses the escape time algorithm to determine the coloring of the coordinates on the complex plane. The code can be reduced to a single line via vectorization after the Escape Time Algorithm function definition, but the code becomes unnecessarily obfuscated. Also, this code uses a lot of memory. You will need a computer with a lot of memory to compute the set with high resolution. |
||
< |
<syntaxhighlight lang=MATLAB>function [theSet,realAxis,imaginaryAxis] = mandelbrotSet(start,gridSpacing,last,maxIteration) |
||
%Define the escape time algorithm |
%Define the escape time algorithm |
||
Line 7,424: | Line 7,424: | ||
shading flat; |
shading flat; |
||
end</ |
end</syntaxhighlight> |
||
To use this function you must specify the: |
To use this function you must specify the: |
||
Line 7,443: | Line 7,443: | ||
Sample usage: |
Sample usage: |
||
< |
<syntaxhighlight lang=MATLAB>mandelbrotSet(-2.05-1.2i,0.004+0.0004i,0.45+1.2i,500);</syntaxhighlight> |
||
=={{header|Metapost}}== |
=={{header|Metapost}}== |
||
< |
<syntaxhighlight lang=Metapost>prologues:=3; |
||
outputtemplate:="%j-%c.svg"; |
outputtemplate:="%j-%c.svg"; |
||
outputformat:="svg"; |
outputformat:="svg"; |
||
Line 7,489: | Line 7,489: | ||
endfig; |
endfig; |
||
end</ |
end</syntaxhighlight> |
||
Sample usage: |
Sample usage: |
||
< |
<syntaxhighlight lang=Bash>mpost -numbersystem="double" mandelbrot.mp</syntaxhighlight> |
||
=={{header|MiniScript}}== |
=={{header|MiniScript}}== |
||
< |
<syntaxhighlight lang=MiniScript>ZOOM = 100 |
||
MAX_ITER = 40 |
MAX_ITER = 40 |
||
gfx.clear color.black |
gfx.clear color.black |
||
Line 7,514: | Line 7,514: | ||
end if |
end if |
||
end for |
end for |
||
end for</ |
end for</syntaxhighlight> |
||
(Will upload an output image as soon as image uploading is fixed.) |
(Will upload an output image as soon as image uploading is fixed.) |
||
=={{header|Modula-3}}== |
=={{header|Modula-3}}== |
||
< |
<syntaxhighlight lang=modula3>MODULE Mandelbrot EXPORTS Main; |
||
IMPORT Wr, Stdio, Fmt, Word; |
IMPORT Wr, Stdio, Fmt, Word; |
||
Line 7,574: | Line 7,574: | ||
END; |
END; |
||
END; |
END; |
||
END Mandelbrot.</ |
END Mandelbrot.</syntaxhighlight> |
||
=={{header|MySQL}}== |
=={{header|MySQL}}== |
||
Line 7,580: | Line 7,580: | ||
See http://arbitraryscrawl.blogspot.co.uk/2012/06/fractsql.html for an explanation. |
See http://arbitraryscrawl.blogspot.co.uk/2012/06/fractsql.html for an explanation. |
||
< |
<syntaxhighlight lang=mysql> |
||
-- Table to contain all the data points |
-- Table to contain all the data points |
||
CREATE TABLE points ( |
CREATE TABLE points ( |
||
Line 7,677: | Line 7,677: | ||
INTO OUTFILE '/tmp/image.ppm' |
INTO OUTFILE '/tmp/image.ppm' |
||
FROM points; |
FROM points; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
Line 7,685: | Line 7,685: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang=nim>import complex |
||
proc inMandelbrotSet(c: Complex, maxEscapeIterations = 50): bool = |
proc inMandelbrotSet(c: Complex, maxEscapeIterations = 50): bool = |
||
Line 7,704: | Line 7,704: | ||
result.add('\n') |
result.add('\n') |
||
echo mandelbrotImage(1.0, -0.05, -2.0, 0.0315, 40, 80)</ |
echo mandelbrotImage(1.0, -0.05, -2.0, 0.0315, 40, 80)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 7,748: | Line 7,748: | ||
{{trans|Julia}} |
{{trans|Julia}} |
||
{{libheader|imageman}} |
{{libheader|imageman}} |
||
< |
<syntaxhighlight lang=Nim>import math, complex, lenientops |
||
import imageman |
import imageman |
||
Line 7,784: | Line 7,784: | ||
img[x - 1, y - 1] = ColorRGBF64(color) |
img[x - 1, y - 1] = ColorRGBF64(color) |
||
img.savePNG("mandelbrot.png", compression = 9)</ |
img.savePNG("mandelbrot.png", compression = 9)</syntaxhighlight> |
||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
< |
<syntaxhighlight lang=ocaml>#load "graphics.cma";; |
||
let mandelbrot xMin xMax yMin yMax xPixels yPixels maxIter = |
let mandelbrot xMin xMax yMin yMax xPixels yPixels maxIter = |
||
Line 7,814: | Line 7,814: | ||
done;; |
done;; |
||
mandelbrot (-1.5) 0.5 (-1.0) 1.0 500 500 200;;</ |
mandelbrot (-1.5) 0.5 (-1.0) 1.0 500 500 200;;</syntaxhighlight> |
||
=={{header|Octave}}== |
=={{header|Octave}}== |
||
Line 7,820: | Line 7,820: | ||
This code runs rather slowly and produces coloured Mandelbrot set by accident ([[Media:Mandel-Octave.jpg|output image]]). |
This code runs rather slowly and produces coloured Mandelbrot set by accident ([[Media:Mandel-Octave.jpg|output image]]). |
||
< |
<syntaxhighlight lang=octave>#! /usr/bin/octave -qf |
||
global width = 200; |
global width = 200; |
||
global height = 200; |
global height = 200; |
||
Line 7,853: | Line 7,853: | ||
endfor |
endfor |
||
saveimage("mandel.ppm", round(ms .* 255).', "ppm");</ |
saveimage("mandel.ppm", round(ms .* 255).', "ppm");</syntaxhighlight> |
||
A bit faster than the above implementation |
A bit faster than the above implementation |
||
< |
<syntaxhighlight lang=octave> |
||
function z = mandelbrot() |
function z = mandelbrot() |
||
% to view the image call "image(mandelbrot())" |
% to view the image call "image(mandelbrot())" |
||
Line 7,879: | Line 7,879: | ||
z = abs(z); |
z = abs(z); |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Ol}}== |
=={{header|Ol}}== |
||
< |
<syntaxhighlight lang=scheme> |
||
(define x-size 59) |
(define x-size 59) |
||
(define y-size 21) |
(define y-size 21) |
||
Line 7,912: | Line 7,912: | ||
(print))) |
(print))) |
||
(iota y-size)) |
(iota y-size)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
Line 7,940: | Line 7,940: | ||
=={{header|OpenEdge/Progress}}== |
=={{header|OpenEdge/Progress}}== |
||
< |
<syntaxhighlight lang=Progress (OpenEdge ABL)>DEFINE VARIABLE print_str AS CHAR NO-UNDO INIT ''. |
||
DEFINE VARIABLE X1 AS DECIMAL NO-UNDO INIT 50. |
DEFINE VARIABLE X1 AS DECIMAL NO-UNDO INIT 50. |
||
DEFINE VARIABLE Y1 AS DECIMAL NO-UNDO INIT 21. |
DEFINE VARIABLE Y1 AS DECIMAL NO-UNDO INIT 21. |
||
Line 7,984: | Line 7,984: | ||
MESSAGE print_str. |
MESSAGE print_str. |
||
OUTPUT CLOSE. |
OUTPUT CLOSE. |
||
</ |
</syntaxhighlight>Example :<BR> |
||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |
||
Define function mandelbrot(): |
Define function mandelbrot(): |
||
< |
<syntaxhighlight lang=parigp>mandelbrot() = |
||
{ |
{ |
||
forstep(y=-1, 1, 0.05, |
forstep(y=-1, 1, 0.05, |
||
Line 7,994: | Line 7,994: | ||
print1(((c)->my(z=c);for(i=1,20,z=z*z+c;if(abs(z)>2,return(" ")));"#")(x+y*I))); |
print1(((c)->my(z=c);for(i=1,20,z=z*z+c;if(abs(z)>2,return(" ")));"#")(x+y*I))); |
||
print()); |
print()); |
||
}</ |
}</syntaxhighlight> |
||
Output:<pre>gp > mandelbrot() |
Output:<pre>gp > mandelbrot() |
||
Line 8,041: | Line 8,041: | ||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<syntaxhighlight lang=pascal>program mandelbrot; |
||
{$IFDEF FPC} |
{$IFDEF FPC} |
||
Line 8,136: | Line 8,136: | ||
close(outfile); |
close(outfile); |
||
end.</ |
end.</syntaxhighlight> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
translation / optimization of the ruby solution |
translation / optimization of the ruby solution |
||
< |
<syntaxhighlight lang=perl>use Math::Complex; |
||
sub mandelbrot { |
sub mandelbrot { |
||
Line 8,154: | Line 8,154: | ||
{print mandelbrot($x + $y * i) ? ' ' : '#'} |
{print mandelbrot($x + $y * i) ? ' ' : '#'} |
||
print "\n" |
print "\n" |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
;Ascii |
;Ascii |
||
This is included in the distribution (with some extra validation) as demo\mandle.exw |
This is included in the distribution (with some extra validation) as demo\mandle.exw |
||
< |
<syntaxhighlight lang=Phix>-- |
||
-- Mandlebrot set in ascii art demo. |
-- Mandlebrot set in ascii art demo. |
||
-- |
-- |
||
Line 8,183: | Line 8,183: | ||
puts(1,b[remainder(k,16)+1]) |
puts(1,b[remainder(k,16)+1]) |
||
end for |
end for |
||
end for</ |
end for</syntaxhighlight> |
||
;Graphical |
;Graphical |
||
This is included in the distribution as demo\arwendemo\mandel.exw |
This is included in the distribution as demo\arwendemo\mandel.exw |
||
< |
<syntaxhighlight lang=Phix>include arwen.ew |
||
include ..\arwen\dib256.ew |
include ..\arwen\dib256.ew |
||
Line 8,426: | Line 8,426: | ||
WinMain(Main,SW_NORMAL) |
WinMain(Main,SW_NORMAL) |
||
void = deleteDib(0)</ |
void = deleteDib(0)</syntaxhighlight> |
||
=={{header|PHP}}== |
=={{header|PHP}}== |
||
Line 8,434: | Line 8,434: | ||
[[File:Mandel-php.png|thumb|right|Sample output]] |
[[File:Mandel-php.png|thumb|right|Sample output]] |
||
< |
<syntaxhighlight lang=PHP>$min_x=-2; |
||
$max_x=1; |
$max_x=1; |
||
$min_y=-1; |
$min_y=-1; |
||
Line 8,473: | Line 8,473: | ||
imagepng($im); |
imagepng($im); |
||
imagedestroy($im); |
imagedestroy($im); |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Picat}}== |
=={{header|Picat}}== |
||
{{trans|Unicon}} |
{{trans|Unicon}} |
||
Picat has not support for fancy graphics so it's plain 0/1 ASCII. Also, there's no built-in support for complex numbers. |
Picat has not support for fancy graphics so it's plain 0/1 ASCII. Also, there's no built-in support for complex numbers. |
||
< |
<syntaxhighlight lang=Picat>go => |
||
Width = 90, |
Width = 90, |
||
Line 8,507: | Line 8,507: | ||
c_add(X,Y) = complex(X[1]+Y[1],X[2]+Y[2]). |
c_add(X,Y) = complex(X[1]+Y[1],X[2]+Y[2]). |
||
c_mul(X,Y) = complex(X[1]*Y[1]-X[2]*Y[2],X[1]*Y[2]+X[2]*Y[1]). |
c_mul(X,Y) = complex(X[1]*Y[1]-X[2]*Y[2],X[1]*Y[2]+X[2]*Y[1]). |
||
c_abs(X) = sqrt(X[1]*X[1]+X[2]*X[2]).</ |
c_abs(X) = sqrt(X[1]*X[1]+X[2]*X[2]).</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 8,562: | Line 8,562: | ||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
< |
<syntaxhighlight lang=PicoLisp>(scl 6) |
||
(let Ppm (make (do 300 (link (need 400)))) |
(let Ppm (make (do 300 (link (need 400)))) |
||
Line 8,579: | Line 8,579: | ||
(prinl 400 " " 300) |
(prinl 400 " " 300) |
||
(prinl 255) |
(prinl 255) |
||
(for Y Ppm (for X Y (apply wr X))) ) )</ |
(for Y Ppm (for X Y (apply wr X))) ) )</syntaxhighlight> |
||
=={{header|PostScript}}== |
=={{header|PostScript}}== |
||
< |
<syntaxhighlight lang=postscript>%!PS-Adobe-2.0 |
||
%%BoundingBox: 0 0 300 200 |
%%BoundingBox: 0 0 300 200 |
||
%%EndComments |
%%EndComments |
||
Line 8,627: | Line 8,627: | ||
showpage |
showpage |
||
origstate restore |
origstate restore |
||
%%EOF</ |
%%EOF</syntaxhighlight> |
||
=={{header|PowerShell}}== |
=={{header|PowerShell}}== |
||
< |
<syntaxhighlight lang=PowerShell> |
||
$x = $y = $i = $j = $r = -16 |
$x = $y = $i = $j = $r = -16 |
||
$colors = [Enum]::GetValues([System.ConsoleColor]) |
$colors = [Enum]::GetValues([System.ConsoleColor]) |
||
Line 8,651: | Line 8,651: | ||
Write-Host |
Write-Host |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Processing}}== |
=={{header|Processing}}== |
||
Click on an area to zoom in. Choose areas with multiple colors for interesting zooming. |
Click on an area to zoom in. Choose areas with multiple colors for interesting zooming. |
||
< |
<syntaxhighlight lang=java>double x, y, zr, zi, zr2, zi2, cr, ci, n; |
||
double zmx1, zmx2, zmy1, zmy2, f, di, dj; |
double zmx1, zmx2, zmy1, zmy2, f, di, dj; |
||
double fn1, fn2, fn3, re, gr, bl, xt, yt, i, j; |
double fn1, fn2, fn3, re, gr, bl, xt, yt, i, j; |
||
Line 8,714: | Line 8,714: | ||
i = 0; |
i = 0; |
||
j = 0; |
j = 0; |
||
}</ |
}</syntaxhighlight>'''The sketch can be run online''' :<BR> [https://www.openprocessing.org/sketch/794150 here.] |
||
==={{header|Processing Python mode}}=== |
==={{header|Processing Python mode}}=== |
||
Click on an area to zoom in. |
Click on an area to zoom in. |
||
Choose areas with multiple colors for interesting zooming. |
Choose areas with multiple colors for interesting zooming. |
||
< |
<syntaxhighlight lang=python>i = di = dj = 0 |
||
fn1, fn2, fn3 = random(20), random(20), random(20) |
fn1, fn2, fn3 = random(20), random(20), random(20) |
||
f = 10 |
f = 10 |
||
Line 8,769: | Line 8,769: | ||
zmy2 = zmy2 * (1. / f) |
zmy2 = zmy2 * (1. / f) |
||
di, dj = di * f, dj * f |
di, dj = di * f, dj * f |
||
i = j = 0</ |
i = j = 0</syntaxhighlight> |
||
=={{header|Prolog}}== |
=={{header|Prolog}}== |
||
SWI-Prolog has a graphic interface XPCE : |
SWI-Prolog has a graphic interface XPCE : |
||
< |
<syntaxhighlight lang=Prolog>:- use_module(library(pce)). |
||
mandelbrot :- |
mandelbrot :- |
||
Line 8,811: | Line 8,811: | ||
compute_RGB(CX, CY, Tmp, ZY1, Iter1, IterF). |
compute_RGB(CX, CY, Tmp, ZY1, Iter1, IterF). |
||
compute_RGB(_CX, _CY, _ZX, _ZY, Iter, Iter).</ |
compute_RGB(_CX, _CY, _ZX, _ZY, Iter, Iter).</syntaxhighlight>Example :<BR> |
||
[[FILE:Mandelbrot.jpg]] |
[[FILE:Mandelbrot.jpg]] |
||
Line 8,818: | Line 8,818: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
Translation of the ruby solution |
Translation of the ruby solution |
||
< |
<syntaxhighlight lang=python># Python 3.0+ and 2.5+ |
||
try: |
try: |
||
from functools import reduce |
from functools import reduce |
||
Line 8,836: | Line 8,836: | ||
print("\n".join("".join(row) for row in rows)) |
print("\n".join("".join(row) for row in rows)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
A more "Pythonic" version of the code: |
A more "Pythonic" version of the code: |
||
< |
<syntaxhighlight lang=python> |
||
import math |
import math |
||
Line 8,854: | Line 8,854: | ||
for y in [a * 0.05 for a in range(-20, 20)]]) |
for y in [a * 0.05 for a in range(-20, 20)]]) |
||
) |
) |
||
</syntaxhighlight> |
|||
</lang> |
|||
Finally, we can also use Matplotlib to visualize the Mandelbrot set with Python: |
Finally, we can also use Matplotlib to visualize the Mandelbrot set with Python: |
||
{{libheader|matplotlib}} |
{{libheader|matplotlib}} |
||
{{libheader|NumPy}} |
{{libheader|NumPy}} |
||
< |
<syntaxhighlight lang=python>from pylab import * |
||
from numpy import NaN |
from numpy import NaN |
||
Line 8,883: | Line 8,883: | ||
ylabel("Im(c)") |
ylabel("Im(c)") |
||
savefig("mandelbrot_python.svg") |
savefig("mandelbrot_python.svg") |
||
show()</ |
show()</syntaxhighlight> |
||
Another Numpy version using masks to avoid (explicit) nested loops. |
Another Numpy version using masks to avoid (explicit) nested loops. |
||
Runs about 16x faster for the same resolution. |
Runs about 16x faster for the same resolution. |
||
< |
<syntaxhighlight lang=python>import matplotlib.pyplot as plt |
||
import numpy as np |
import numpy as np |
||
Line 8,913: | Line 8,913: | ||
cmap=plt.cm.prism, |
cmap=plt.cm.prism, |
||
extent=(X.min(), X.max(), Y.min(), Y.max())) |
extent=(X.min(), X.max(), Y.min(), Y.max())) |
||
plt.show()</ |
plt.show()</syntaxhighlight> |
||
===Normalized Counting, Distance Estimation, Mercator Maps and Deep Zoom=== |
===Normalized Counting, Distance Estimation, Mercator Maps and Deep Zoom=== |
||
The Mandelbrot set is printed with smooth colors. |
The Mandelbrot set is printed with smooth colors. |
||
The ''e^(-|z|)-smoothing'', ''normalized iteration count'' and ''exterior distance estimation'' algorithms are used with NumPy and complex matrices (see Javier Barrallo & Damien M. Jones: [http://www.mi.sanu.ac.rs/vismath/javier/index.html ''Coloring Algorithms for Dynamical Systems in the Complex Plane''] and Mikael Hvidtfeldt Christensen: [http://blog.hvidtfeldts.net/index.php/2011/09/distance-estimated-3d-fractals-v-the-mandelbulb-different-de-approximations ''Distance Estimated 3D Fractals (V): The Mandelbulb & Different DE Approximations'']). |
The ''e^(-|z|)-smoothing'', ''normalized iteration count'' and ''exterior distance estimation'' algorithms are used with NumPy and complex matrices (see Javier Barrallo & Damien M. Jones: [http://www.mi.sanu.ac.rs/vismath/javier/index.html ''Coloring Algorithms for Dynamical Systems in the Complex Plane''] and Mikael Hvidtfeldt Christensen: [http://blog.hvidtfeldts.net/index.php/2011/09/distance-estimated-3d-fractals-v-the-mandelbulb-different-de-approximations ''Distance Estimated 3D Fractals (V): The Mandelbulb & Different DE Approximations'']). |
||
< |
<syntaxhighlight lang=python>import numpy as np |
||
import matplotlib.pyplot as plt |
import matplotlib.pyplot as plt |
||
Line 8,951: | Line 8,951: | ||
plt.imshow(D ** 0.1, cmap=plt.cm.twilight_shifted) |
plt.imshow(D ** 0.1, cmap=plt.cm.twilight_shifted) |
||
plt.savefig("Mandelbrot_set_3.png", dpi=200)</ |
plt.savefig("Mandelbrot_set_3.png", dpi=200)</syntaxhighlight> |
||
A small change in the code above creates Mercator maps of the Mandelbrot set (see David Madore: [http://www.madore.org/~david/math/mandelbrot.html ''Mandelbrot set images and videos''] and Anders Sandberg: [https://www.flickr.com/photos/arenamontanus/sets/72157615740829949 ''Mercator Mandelbrot Maps'']). |
A small change in the code above creates Mercator maps of the Mandelbrot set (see David Madore: [http://www.madore.org/~david/math/mandelbrot.html ''Mandelbrot set images and videos''] and Anders Sandberg: [https://www.flickr.com/photos/arenamontanus/sets/72157615740829949 ''Mercator Mandelbrot Maps'']). |
||
Line 8,959: | Line 8,959: | ||
With the same pixel density and the same maximum magnification, the difference in height between the maps is only about 10 percent. |
With the same pixel density and the same maximum magnification, the difference in height between the maps is only about 10 percent. |
||
By misusing a scatter plot, it is possible to create zoom images of the Mandelbrot set. |
By misusing a scatter plot, it is possible to create zoom images of the Mandelbrot set. |
||
< |
<syntaxhighlight lang=python>import numpy as np |
||
import matplotlib.pyplot as plt |
import matplotlib.pyplot as plt |
||
Line 8,992: | Line 8,992: | ||
ax[1, 0].scatter(X[3*z:3*z+c], Y[3*z:3*z+c], s=R[0:c]**2, c=D[3*z:3*z+c]**0.3, cmap=plt.cm.nipy_spectral) |
ax[1, 0].scatter(X[3*z:3*z+c], Y[3*z:3*z+c], s=R[0:c]**2, c=D[3*z:3*z+c]**0.3, cmap=plt.cm.nipy_spectral) |
||
ax[1, 1].scatter(X[4*z:4*z+c], Y[4*z:4*z+c], s=R[0:c]**2, c=D[4*z:4*z+c]**0.2, cmap=plt.cm.nipy_spectral) |
ax[1, 1].scatter(X[4*z:4*z+c], Y[4*z:4*z+c], s=R[0:c]**2, c=D[4*z:4*z+c]**0.2, cmap=plt.cm.nipy_spectral) |
||
plt.savefig("Mercator_Mandelbrot_plot.png", dpi=100)</ |
plt.savefig("Mercator_Mandelbrot_plot.png", dpi=100)</syntaxhighlight> |
||
For deep zoom images it is sufficient to calculate a single point with high accuracy. A good approximation can then be found for all other points by means of a perturbation calculation with standard accuracy. See [https://en.wikipedia.org/wiki/Plotting_algorithms_for_the_Mandelbrot_set#Perturbation_theory_and_series_approximation Perturbation theory] (Wikipedia) and [https://gbillotey.github.io/Fractalshades-doc/math.html Mathematical background] (Fractalshades) for more details. Placing the iteration in a separate function speeds up the calculation slightly. |
For deep zoom images it is sufficient to calculate a single point with high accuracy. A good approximation can then be found for all other points by means of a perturbation calculation with standard accuracy. See [https://en.wikipedia.org/wiki/Plotting_algorithms_for_the_Mandelbrot_set#Perturbation_theory_and_series_approximation Perturbation theory] (Wikipedia) and [https://gbillotey.github.io/Fractalshades-doc/math.html Mathematical background] (Fractalshades) for more details. Placing the iteration in a separate function speeds up the calculation slightly. |
||
< |
<syntaxhighlight lang=python>import numpy as np |
||
import matplotlib.pyplot as plt |
import matplotlib.pyplot as plt |
||
Line 9,038: | Line 9,038: | ||
plt.imshow(D ** 0.25, cmap=plt.cm.nipy_spectral) |
plt.imshow(D ** 0.25, cmap=plt.cm.nipy_spectral) |
||
plt.savefig("Mandelbrot_deep_zoom.png", dpi=200)</ |
plt.savefig("Mandelbrot_deep_zoom.png", dpi=200)</syntaxhighlight> |
||
Of course, deep Mercator maps can also be created. See also the image [https://www.flickr.com/photos/arenamontanus/3430921497/in/album-72157615740829949/ Deeper Mercator Mandelbrot] by Anders Sandberg. To reduce glitches, an additional reference sequence for the derivation (dS) is recorded with high precision. Compare the corresponding program examples for the Julia language for more details. |
Of course, deep Mercator maps can also be created. See also the image [https://www.flickr.com/photos/arenamontanus/3430921497/in/album-72157615740829949/ Deeper Mercator Mandelbrot] by Anders Sandberg. To reduce glitches, an additional reference sequence for the derivation (dS) is recorded with high precision. Compare the corresponding program examples for the Julia language for more details. |
||
< |
<syntaxhighlight lang=python>import numpy as np |
||
import matplotlib.pyplot as plt |
import matplotlib.pyplot as plt |
||
Line 9,084: | Line 9,084: | ||
plt.imshow(D.T ** 0.025, cmap=plt.cm.nipy_spectral) |
plt.imshow(D.T ** 0.025, cmap=plt.cm.nipy_spectral) |
||
plt.savefig("Mercator_Mandelbrot_deep_map.png", dpi=200)</ |
plt.savefig("Mercator_Mandelbrot_deep_map.png", dpi=200)</syntaxhighlight> |
||
===Python - "One liner"=== |
===Python - "One liner"=== |
||
< |
<syntaxhighlight lang=python> |
||
print( |
print( |
||
'\n'.join( |
'\n'.join( |
||
Line 9,096: | Line 9,096: | ||
for y in range(-50,50) |
for y in range(-50,50) |
||
)) |
)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|R}}== |
=={{header|R}}== |
||
< |
<syntaxhighlight lang=R>iterate.until.escape <- function(z, c, trans, cond, max=50, response=dwell) { |
||
#we iterate all active points in the same array operation, |
#we iterate all active points in the same array operation, |
||
#and keeping track of which points are still iterating. |
#and keeping track of which points are still iterating. |
||
Line 9,121: | Line 9,121: | ||
function(z,c)z^2+c, function(z)abs(z) <= 2, |
function(z,c)z^2+c, function(z)abs(z) <= 2, |
||
max=100) |
max=100) |
||
image(x)</ |
image(x)</syntaxhighlight> |
||
===Mandelbrot Set with R Animation=== |
===Mandelbrot Set with R Animation=== |
||
Modified Mandelbrot set animation by Jarek Tuszynski, PhD. (see: [https://en.wikipedia.org/wiki/R_(programming_language)#Mandelbrot_set Wikipedia: R (programming_language)] and [https://rtricks.blogspot.com/2007/04/mandelbrot-set-with-r-animation.html R Tricks: Mandelbrot Set with R Animation]) |
Modified Mandelbrot set animation by Jarek Tuszynski, PhD. (see: [https://en.wikipedia.org/wiki/R_(programming_language)#Mandelbrot_set Wikipedia: R (programming_language)] and [https://rtricks.blogspot.com/2007/04/mandelbrot-set-with-r-animation.html R Tricks: Mandelbrot Set with R Animation]) |
||
< |
<syntaxhighlight lang=R>#install.packages("caTools") # install external package (if missing) |
||
library(caTools) # external package providing write.gif function |
library(caTools) # external package providing write.gif function |
||
jet.colors <- colorRampPalette(c("red", "blue", "#007FFF", "cyan", "#7FFF7F", |
jet.colors <- colorRampPalette(c("red", "blue", "#007FFF", "cyan", "#7FFF7F", |
||
Line 9,140: | Line 9,140: | ||
X[, , k] <- exp(-abs(Z)) # capture results |
X[, , k] <- exp(-abs(Z)) # capture results |
||
} |
} |
||
write.gif(X, "Mandelbrot.gif", col = jet.colors, delay = 100)</ |
write.gif(X, "Mandelbrot.gif", col = jet.colors, delay = 100)</syntaxhighlight> |
||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang=racket> |
||
#lang racket |
#lang racket |
||
Line 9,170: | Line 9,170: | ||
(mandelbrot 300 200) |
(mandelbrot 300 200) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
Line 9,180: | Line 9,180: | ||
Converted to a .png file for display here. |
Converted to a .png file for display here. |
||
< |
<syntaxhighlight lang=perl6>constant @color_map = map ~*.comb(/../).map({:16($_)}), < |
||
000000 0000fc 4000fc 7c00fc bc00fc fc00fc fc00bc fc007c fc0040 fc0000 fc4000 |
000000 0000fc 4000fc 7c00fc bc00fc fc00fc fc00bc fc007c fc0040 fc0000 fc4000 |
||
fc7c00 fcbc00 fcfc00 bcfc00 7cfc00 40fc00 00fc00 00fc40 00fc7c 00fcbc 00fcfc |
fc7c00 fcbc00 fcfc00 bcfc00 7cfc00 40fc00 00fc00 00fc40 00fc7c 00fcbc 00fcfc |
||
Line 9,228: | Line 9,228: | ||
put @color_map[|.reverse, |.[1..*]][^$width] given |
put @color_map[|.reverse, |.[1..*]][^$width] given |
||
my @ = map &mandelbrot.assuming(0i, *), $re «+« @im; |
my @ = map &mandelbrot.assuming(0i, *), $re «+« @im; |
||
}</ |
}</syntaxhighlight> |
||
Alternately, a more modern, faster version. |
Alternately, a more modern, faster version. |
||
< |
<syntaxhighlight lang=perl6>use Image::PNG::Portable; |
||
my ($w, $h) = 800, 800; |
my ($w, $h) = 800, 800; |
||
Line 9,279: | Line 9,279: | ||
} ).map: ((*+$m) * 255).Int] |
} ).map: ((*+$m) * 255).Int] |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
See [https://github.com/thundergnat/rc/blob/master/img/Mandelbrot-set-perl6.png Mandelbrot-set-perl6.png] (offsite .png image) |
See [https://github.com/thundergnat/rc/blob/master/img/Mandelbrot-set-perl6.png Mandelbrot-set-perl6.png] (offsite .png image) |
||
Line 9,286: | Line 9,286: | ||
{{trans|AWK}} |
{{trans|AWK}} |
||
This REXX version doesn't depend on the ASCII sequence of glyphs; an internal character string was used that mimics a part of the ASCII glyph sequence. |
This REXX version doesn't depend on the ASCII sequence of glyphs; an internal character string was used that mimics a part of the ASCII glyph sequence. |
||
< |
<syntaxhighlight lang=rexx>/*REXX program generates and displays a Mandelbrot set as an ASCII art character image.*/ |
||
@ = '>=<;:9876543210/.-,+*)(''&%$#"!' /*the characters used in the display. */ |
@ = '>=<;:9876543210/.-,+*)(''&%$#"!' /*the characters used in the display. */ |
||
Xsize = 59; minRE = -2; maxRE = +1; stepX = (maxRE-minRE) / Xsize |
Xsize = 59; minRE = -2; maxRE = +1; stepX = (maxRE-minRE) / Xsize |
||
Line 9,302: | Line 9,302: | ||
end /*x*/ |
end /*x*/ |
||
say $ /*display a line of character output.*/ |
say $ /*display a line of character output.*/ |
||
end /*y*/ /*stick a fork in it, we're all done. */</ |
end /*y*/ /*stick a fork in it, we're all done. */</syntaxhighlight> |
||
'''output''' using the internal defaults: |
'''output''' using the internal defaults: |
||
<pre> |
<pre> |
||
Line 9,330: | Line 9,330: | ||
===version 2=== |
===version 2=== |
||
This REXX version uses glyphs that are "darker" (with a white background) around the output's peripheral. |
This REXX version uses glyphs that are "darker" (with a white background) around the output's peripheral. |
||
< |
<syntaxhighlight lang=rexx>/*REXX program generates and displays a Mandelbrot set as an ASCII art character image.*/ |
||
@ = '█▓▒░@9876543210=.-,+*)(·&%$#"!' /*the characters used in the display. */ |
@ = '█▓▒░@9876543210=.-,+*)(·&%$#"!' /*the characters used in the display. */ |
||
Xsize = 59; minRE = -2; maxRE = +1; stepX = (maxRE-minRE) / Xsize |
Xsize = 59; minRE = -2; maxRE = +1; stepX = (maxRE-minRE) / Xsize |
||
Line 9,346: | Line 9,346: | ||
end /*x*/ |
end /*x*/ |
||
say $ /*display a line of character output.*/ |
say $ /*display a line of character output.*/ |
||
end /*y*/ /*stick a fork in it, we're all done. */</ |
end /*y*/ /*stick a fork in it, we're all done. */</syntaxhighlight> |
||
'''output''' using the internal defaults: |
'''output''' using the internal defaults: |
||
<pre> |
<pre> |
||
Line 9,374: | Line 9,374: | ||
===version 3=== |
===version 3=== |
||
This REXX version produces a larger output (it uses the full width of the terminal screen (less one), and the height is one-half of the width. |
This REXX version produces a larger output (it uses the full width of the terminal screen (less one), and the height is one-half of the width. |
||
< |
<syntaxhighlight lang=rexx>/*REXX program generates and displays a Mandelbrot set as an ASCII art character image.*/ |
||
@ = '█▓▒░@9876543210=.-,+*)(·&%$#"!' /*the characters used in the display. */ |
@ = '█▓▒░@9876543210=.-,+*)(·&%$#"!' /*the characters used in the display. */ |
||
parse arg Xsize Ysize . /*obtain optional arguments from the CL*/ |
parse arg Xsize Ysize . /*obtain optional arguments from the CL*/ |
||
Line 9,393: | Line 9,393: | ||
end /*x*/ |
end /*x*/ |
||
say $ /*display a line of character output.*/ |
say $ /*display a line of character output.*/ |
||
end /*y*/ /*stick a fork in it, we're all done. */</ |
end /*y*/ /*stick a fork in it, we're all done. */</syntaxhighlight> |
||
'''output''' using the internal defaults: |
'''output''' using the internal defaults: |
||
<pre> |
<pre> |
||
Line 9,445: | Line 9,445: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang=ring> |
||
load "guilib.ring" |
load "guilib.ring" |
||
Line 9,499: | Line 9,499: | ||
} |
} |
||
label1 { setpicture(p1) show() } |
label1 { setpicture(p1) show() } |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
Line 9,507: | Line 9,507: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
Text only, prints an 80-char by 41-line depiction. Found [http://www.xcombinator.com/2008/02/22/ruby-inject-and-the-mandelbrot-set/ here]. |
Text only, prints an 80-char by 41-line depiction. Found [http://www.xcombinator.com/2008/02/22/ruby-inject-and-the-mandelbrot-set/ here]. |
||
< |
<syntaxhighlight lang=ruby>require 'complex' |
||
def mandelbrot(a) |
def mandelbrot(a) |
||
Line 9,518: | Line 9,518: | ||
end |
end |
||
puts |
puts |
||
end</ |
end</syntaxhighlight> |
||
{{trans|Tcl}} |
{{trans|Tcl}} |
||
Uses [[Raster graphics operations/Ruby]] |
Uses [[Raster graphics operations/Ruby]] |
||
< |
<syntaxhighlight lang=ruby># frozen_string_literal: true |
||
require_relative 'raster_graphics' |
require_relative 'raster_graphics' |
||
Line 9,560: | Line 9,560: | ||
end |
end |
||
Pixmap.mandelbrot(300,300).save('mandel.ppm')</ |
Pixmap.mandelbrot(300,300).save('mandel.ppm')</syntaxhighlight> |
||
{{libheader|RubyGems}} |
{{libheader|RubyGems}} |
||
{{libheader|JRubyArt}} |
{{libheader|JRubyArt}} |
||
JRubyArt is a port of processing to ruby |
JRubyArt is a port of processing to ruby |
||
< |
<syntaxhighlight lang=ruby> |
||
# frozen_string_literal: true |
# frozen_string_literal: true |
||
Line 9,603: | Line 9,603: | ||
size(900, 600) |
size(900, 600) |
||
end |
end |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
Dependencies: image, num-complex |
Dependencies: image, num-complex |
||
< |
<syntaxhighlight lang=rust>extern crate image; |
||
extern crate num_complex; |
extern crate num_complex; |
||
Line 9,647: | Line 9,647: | ||
// Save image |
// Save image |
||
imgbuf.save("fractal.png").unwrap(); |
imgbuf.save("fractal.png").unwrap(); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Sass/SCSS}}== |
=={{header|Sass/SCSS}}== |
||
< |
<syntaxhighlight lang=coffeescript> |
||
$canvasWidth: 200; |
$canvasWidth: 200; |
||
$canvasHeight: 200; |
$canvasHeight: 200; |
||
Line 9,697: | Line 9,697: | ||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
Line 9,703: | Line 9,703: | ||
Uses RgbBitmap from [[Basic_bitmap_storage#Scala|Basic Bitmap Storage]] task and Complex number class from [[Arithmetic/Complex#Scala|this]] |
Uses RgbBitmap from [[Basic_bitmap_storage#Scala|Basic Bitmap Storage]] task and Complex number class from [[Arithmetic/Complex#Scala|this]] |
||
programming task. |
programming task. |
||
< |
<syntaxhighlight lang=scala>import org.rosettacode.ArithmeticComplex._ |
||
import java.awt.Color |
import java.awt.Color |
||
Line 9,745: | Line 9,745: | ||
else new Color(255, 255, (255*(c-2)).toInt) |
else new Color(255, 255, (255*(c-2)).toInt) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
Read–eval–print loop |
Read–eval–print loop |
||
< |
<syntaxhighlight lang=scala>import scala.swing._ |
||
import javax.swing.ImageIcon |
import javax.swing.ImageIcon |
||
val imgMandel=Mandelbrot.generate() |
val imgMandel=Mandelbrot.generate() |
||
val mainframe=new MainFrame(){title="Test"; visible=true |
val mainframe=new MainFrame(){title="Test"; visible=true |
||
contents=new Label(){icon=new ImageIcon(imgMandel.image)} |
contents=new Label(){icon=new ImageIcon(imgMandel.image)} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
This implementation writes an image of the Mandelbrot set to a plain pgm file. The set itself is drawn in white, while the exterior is drawn in black. |
This implementation writes an image of the Mandelbrot set to a plain pgm file. The set itself is drawn in white, while the exterior is drawn in black. |
||
< |
<syntaxhighlight lang=scheme>(define x-centre -0.5) |
||
(define y-centre 0.0) |
(define y-centre 0.0) |
||
(define width 4.0) |
(define width 4.0) |
||
Line 9,796: | Line 9,796: | ||
(begin (display (pixel i j)) (newline)))))))) |
(begin (display (pixel i j)) (newline)))))))) |
||
(plot)</ |
(plot)</syntaxhighlight> |
||
=={{header|Scratch}}== |
=={{header|Scratch}}== |
||
Line 9,873: | Line 9,873: | ||
=={{header|SenseTalk}}== |
=={{header|SenseTalk}}== |
||
< |
<syntaxhighlight lang=sensetalk>put 0 into oReal # Real origin |
||
put 0 into oImag # Imaginary origin |
put 0 into oImag # Imaginary origin |
||
put 0.5 into mag # Magnification |
put 0.5 into mag # Magnification |
||
Line 9,935: | Line 9,935: | ||
close file myFile |
close file myFile |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|SequenceL}}== |
=={{header|SequenceL}}== |
||
'''SequenceL Code for Computing and Coloring:'''<br> |
'''SequenceL Code for Computing and Coloring:'''<br> |
||
< |
<syntaxhighlight lang=sequencel>import <Utilities/Complex.sl>; |
||
import <Utilities/Sequence.sl>; |
import <Utilities/Sequence.sl>; |
||
import <Utilities/Math.sl>; |
import <Utilities/Math.sl>; |
||
Line 10,026: | Line 10,026: | ||
linearInterpolate(v0(0), v1(0), t(0)) := (1 - t) * v0 + t * v1; |
linearInterpolate(v0(0), v1(0), t(0)) := (1 - t) * v0 + t * v1; |
||
//endregion</ |
//endregion</syntaxhighlight> |
||
'''C++ Driver Code:'''<br> |
'''C++ Driver Code:'''<br> |
||
{{libheader|CImg}} |
{{libheader|CImg}} |
||
< |
<syntaxhighlight lang=c>#include "SL_Generated.h" |
||
#include "../../../ThirdParty/CImg/CImg.h" |
#include "../../../ThirdParty/CImg/CImg.h" |
||
Line 10,132: | Line 10,132: | ||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 10,138: | Line 10,138: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang=ruby>func mandelbrot(z) { |
||
var c = z |
var c = z |
||
{ z = (z*z + c) |
{ z = (z*z + c) |
||
Line 10,151: | Line 10,151: | ||
} |
} |
||
print "\n" |
print "\n" |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Simula}}== |
=={{header|Simula}}== |
||
{{trans|Scheme}} |
{{trans|Scheme}} |
||
< |
<syntaxhighlight lang=simula>BEGIN |
||
REAL XCENTRE, YCENTRE, WIDTH, RMAX, XOFFSET, YOFFSET, PIXELSIZE; |
REAL XCENTRE, YCENTRE, WIDTH, RMAX, XOFFSET, YOFFSET, PIXELSIZE; |
||
INTEGER N, IMAX, JMAX, COLOURMAX; |
INTEGER N, IMAX, JMAX, COLOURMAX; |
||
Line 10,240: | Line 10,240: | ||
PLOT; |
PLOT; |
||
END;</ |
END;</syntaxhighlight> |
||
=={{header|Spin}}== |
=={{header|Spin}}== |
||
Line 10,247: | Line 10,247: | ||
{{works with|HomeSpun}} |
{{works with|HomeSpun}} |
||
{{works with|OpenSpin}} |
{{works with|OpenSpin}} |
||
< |
<syntaxhighlight lang=spin>con |
||
_clkmode = xtal1+pll16x |
_clkmode = xtal1+pll16x |
||
_clkfreq = 80_000_000 |
_clkfreq = 80_000_000 |
||
Line 10,290: | Line 10,290: | ||
waitcnt(_clkfreq+cnt) |
waitcnt(_clkfreq+cnt) |
||
ser.stop</ |
ser.stop</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 10,322: | Line 10,322: | ||
=={{header|SPL}}== |
=={{header|SPL}}== |
||
< |
<syntaxhighlight lang=spl>w,h = #.scrsize() |
||
sfx = -2.5; sfy = -2*h/w; fs = 4/w |
sfx = -2.5; sfy = -2*h/w; fs = 4/w |
||
#.aaoff() |
#.aaoff() |
||
Line 10,339: | Line 10,339: | ||
? n=maxn, <= 0,0,0 |
? n=maxn, <= 0,0,0 |
||
<= #.hsv2rgb(n/maxn*360,1,1):3 |
<= #.hsv2rgb(n/maxn*360,1,1):3 |
||
.</ |
.</syntaxhighlight> |
||
Line 10,346: | Line 10,346: | ||
Using the Swift Numerics package, as well as the C library Quick 'N Dirty BMP imported in Swift. |
Using the Swift Numerics package, as well as the C library Quick 'N Dirty BMP imported in Swift. |
||
< |
<syntaxhighlight lang=swift>import Foundation |
||
import Numerics |
import Numerics |
||
import QDBMP |
import QDBMP |
||
Line 10,433: | Line 10,433: | ||
} |
} |
||
canvas.save()</ |
canvas.save()</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
{{libheader|Tk}} |
{{libheader|Tk}} |
||
This code makes extensive use of Tk's built-in photo image system, which provides a 32-bit RGBA plotting surface that can be then quickly drawn in any number of places in the application. It uses a computational color scheme that was easy to code... |
This code makes extensive use of Tk's built-in photo image system, which provides a 32-bit RGBA plotting surface that can be then quickly drawn in any number of places in the application. It uses a computational color scheme that was easy to code... |
||
< |
<syntaxhighlight lang=tcl>package require Tk |
||
proc mandelIters {cx cy} { |
proc mandelIters {cx cy} { |
||
Line 10,467: | Line 10,467: | ||
update |
update |
||
} |
} |
||
.mandel configure -cursor {}</ |
.mandel configure -cursor {}</syntaxhighlight> |
||
=={{header|TeX}}== |
=={{header|TeX}}== |
||
Line 10,473: | Line 10,473: | ||
The <code>pst-fractal</code> package includes a Mandelbrot set drawn by emitting [[PostScript]] code (using [[PSTricks]]), so the actual work done in the printer or PostScript interpreter. |
The <code>pst-fractal</code> package includes a Mandelbrot set drawn by emitting [[PostScript]] code (using [[PSTricks]]), so the actual work done in the printer or PostScript interpreter. |
||
< |
<syntaxhighlight lang=TeX>\input pst-fractal |
||
\psfractal[type=Mandel,xWidth=14cm,yWidth=12cm,maxIter=30,dIter=20] (-2.5,-1.5)(1,1.5) |
\psfractal[type=Mandel,xWidth=14cm,yWidth=12cm,maxIter=30,dIter=20] (-2.5,-1.5)(1,1.5) |
||
\end</ |
\end</syntaxhighlight> |
||
The coordinates are a rectangle in the complex plane to draw, scaled up to <code>xWidth,yWidth</code>. |
The coordinates are a rectangle in the complex plane to draw, scaled up to <code>xWidth,yWidth</code>. |
||
Line 10,491: | Line 10,491: | ||
In PGF 3.0 the calculations are done in [[PostScript]] code emitted, so the output size is small but it only does 10 iterations so is very low resolution. |
In PGF 3.0 the calculations are done in [[PostScript]] code emitted, so the output size is small but it only does 10 iterations so is very low resolution. |
||
< |
<syntaxhighlight lang=LaTeX>\documentclass{minimal} |
||
\usepackage{tikz} |
\usepackage{tikz} |
||
\usetikzlibrary{shadings} |
\usetikzlibrary{shadings} |
||
Line 10,498: | Line 10,498: | ||
\shade[shading=Mandelbrot set] (0,0) rectangle (4,4); |
\shade[shading=Mandelbrot set] (0,0) rectangle (4,4); |
||
\end{tikzpicture} |
\end{tikzpicture} |
||
\end{document}</ |
\end{document}</syntaxhighlight> |
||
=={{header|LuaTeX}}== |
=={{header|LuaTeX}}== |
||
Line 10,508: | Line 10,508: | ||
=={{header|TI-83 BASIC}}== |
=={{header|TI-83 BASIC}}== |
||
Based on the [[Mandelbrot_set#BASIC|BASIC Version]]. Due to the TI-83's lack of power, it takes around 2 hours to complete at 16 iterations. |
Based on the [[Mandelbrot_set#BASIC|BASIC Version]]. Due to the TI-83's lack of power, it takes around 2 hours to complete at 16 iterations. |
||
< |
<syntaxhighlight lang=ti83b>PROGRAM:MANDELBR |
||
:Input "ITER. ",D |
:Input "ITER. ",D |
||
:For(A,Xmin,Xmax,ΔX) |
:For(A,Xmin,Xmax,ΔX) |
||
Line 10,533: | Line 10,533: | ||
:End |
:End |
||
:End |
:End |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|TXR}}== |
=={{header|TXR}}== |
||
Line 10,540: | Line 10,540: | ||
Creates same <code>mandelbrot.pgm</code> file. |
Creates same <code>mandelbrot.pgm</code> file. |
||
< |
<syntaxhighlight lang=txrlisp>(defvar x-centre -0.5) |
||
(defvar y-centre 0.0) |
(defvar y-centre 0.0) |
||
(defvar width 4.0) |
(defvar width 4.0) |
||
Line 10,615: | Line 10,615: | ||
(put-line "" *stdout*)))) |
(put-line "" *stdout*)))) |
||
(plot)</ |
(plot)</syntaxhighlight> |
||
=={{header|uBasic/4tH}}== |
=={{header|uBasic/4tH}}== |
||
Line 10,665: | Line 10,665: | ||
56 Print "8"; : Return |
56 Print "8"; : Return |
||
57 Print "9"; : Return |
57 Print "9"; : Return |
||
64 Print "@"; : Return</ |
64 Print "@"; : Return</syntaxhighlight> |
||
Output: |
Output: |
||
<pre>1111111111111111111111122222222222222222222222222222222222222222222222222222222222222222222222222211111 |
<pre>1111111111111111111111122222222222222222222222222222222222222222222222222222222222222222222222222211111 |
||
Line 10,713: | Line 10,713: | ||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
{{works with|Bourne Again SHell|4}} |
{{works with|Bourne Again SHell|4}} |
||
< |
<syntaxhighlight lang=bash>((xmin=-8601)) # int(-2.1*4096) |
||
((xmax=2867)) # int( 0.7*4096) |
((xmax=2867)) # int( 0.7*4096) |
||
Line 10,737: | Line 10,737: | ||
done |
done |
||
echo |
echo |
||
done</ |
done</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 10,770: | Line 10,770: | ||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
VBScript does'nt have access to Windows graphics. I made a class allowing to create a bmp in an array, save it to BMP format and call the default application to view it. |
VBScript does'nt have access to Windows graphics. I made a class allowing to create a bmp in an array, save it to BMP format and call the default application to view it. |
||
<syntaxhighlight lang=vb> |
|||
<lang vb> |
|||
option explicit |
option explicit |
||
Line 10,968: | Line 10,968: | ||
Set X = Nothing |
Set X = Nothing |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Vedit macro language}}== |
=={{header|Vedit macro language}}== |
||
Vedit macro language does not support floating point calculations, so fixed point arithmetic is used, with Value 10000 representing 1.0. |
Vedit macro language does not support floating point calculations, so fixed point arithmetic is used, with Value 10000 representing 1.0. |
||
The Mandelbrot image is drawn using ASCII characters 1-9 to show number of iterations. Iteration count 10 or more is represented with '@'. |
The Mandelbrot image is drawn using ASCII characters 1-9 to show number of iterations. Iteration count 10 or more is represented with '@'. |
||
To compensate the aspect ratio of the font, step sizes in x and y directions are different. |
To compensate the aspect ratio of the font, step sizes in x and y directions are different. |
||
< |
<syntaxhighlight lang=vedit>#1 =-21000 // left edge = -2.1 |
||
#2 = 15000 // right edge = 1.5 |
#2 = 15000 // right edge = 1.5 |
||
#3 = 15000 // top edge = 1.5 |
#3 = 15000 // top edge = 1.5 |
||
Line 11,006: | Line 11,006: | ||
} |
} |
||
BOF |
BOF |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<small> |
<small> |
||
Line 11,056: | Line 11,056: | ||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
{{libheader|DOME}} |
{{libheader|DOME}} |
||
< |
<syntaxhighlight lang=ecmascript>import "graphics" for Canvas, Color |
||
import "dome" for Window |
import "dome" for Window |
||
Line 11,100: | Line 11,100: | ||
} |
} |
||
var Game = MandelbrotSet.new(800, 600)</ |
var Game = MandelbrotSet.new(800, 600)</syntaxhighlight> |
||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang=XPL0>include c:\cxpl\codes; \intrinsic 'code' declarations |
||
int X, Y, \screen coordinates of current point |
int X, Y, \screen coordinates of current point |
||
Cnt; \iteration counter |
Cnt; \iteration counter |
||
Line 11,128: | Line 11,128: | ||
X:= ChIn(1); \wait for keystroke |
X:= ChIn(1); \wait for keystroke |
||
SetVid($03); \restore normal text display |
SetVid($03); \restore normal text display |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[[File:MandelXPL0.png]] |
[[File:MandelXPL0.png]] |
||
Line 11,138: | Line 11,138: | ||
{{omit from|M4}} |
{{omit from|M4}} |
||
< |
<syntaxhighlight lang=xml> |
||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
||
Line 11,234: | Line 11,234: | ||
</xsl:stylesheet> |
</xsl:stylesheet> |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Z80 Assembly}}== |
=={{header|Z80 Assembly}}== |
||
< |
<syntaxhighlight lang=Z80> |
||
; |
; |
||
; Compute a Mandelbrot set on a simple Z80 computer. |
; Compute a Mandelbrot set on a simple Z80 computer. |
||
Line 11,478: | Line 11,478: | ||
ld d, a |
ld d, a |
||
ret |
ret |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 11,510: | Line 11,510: | ||
{{trans|XPL0}} |
{{trans|XPL0}} |
||
[[File:Mandelbrot.zkl.jpg|300px|thumb|right]] |
[[File:Mandelbrot.zkl.jpg|300px|thumb|right]] |
||
< |
<syntaxhighlight lang=zkl>fcn mandelbrot{ // lord this is slooooow |
||
bitmap:=PPM(640,480); |
bitmap:=PPM(640,480); |
||
foreach y,x in ([0..479],[0..639]){ |
foreach y,x in ([0..479],[0..639]){ |
||
Line 11,529: | Line 11,529: | ||
} |
} |
||
bitmap.write(File("foo.ppm","wb")); |
bitmap.write(File("foo.ppm","wb")); |
||
}();</ |
}();</syntaxhighlight> |
||