Mandelbrot set: Difference between revisions

m
Replace deprecated functions
m (→‎ASCII output: fix links)
m (Replace deprecated functions)
 
(18 intermediate revisions by 6 users not shown)
Line 1,861:
[[File:Mandelbrot-bc.jpg|thumb|right]]
Producing a [https://fr.wikipedia.org/wiki/Portable_pixmap PGM] image.
 
To work properly, this needs to run with the environment variable BC_LINE_LENGTH set to 0.
 
<syntaxhighlight lang=bc>max_iter = 50
width = 400; height =400 401
scale = 10
xmin = -2; xmax = 1/2
Line 1,891 ⟶ 1,894:
print "P2\n", width, " ", height, "\n255\n"
 
for (i = 0; i < widthheight; i++) {
xy = xminymin + (xmaxymax - xminymin) / widthheight * i
for (j = 0; j < heightwidth; j++) {
yx = yminxmin + (ymaxxmax - yminxmin) / heightwidth * j
tmp_scale = scale
scale = 0
m = (255 * mandelbrot(x, y) + max_iter + 1) / max_iter
print m
if ( j < heightwidth - 1 ) print " "
scale = tmp_scale
 
Line 5,222 ⟶ 5,225:
=={{header|EasyLang}}==
 
[https://easylang.onlinedev/apps/mandelbrot.html Run it]
 
<syntaxhighlight lang="easylang">
# Mandelbrot
#
res = 4
maxiter = 200
Line 5,241 ⟶ 5,246:
textsize 2
#
fastprocfastfunc iter cx cy . itmaxiter .
while xx + yy < 4 and it >< 0maxiter
y = 2 * x * y + cy
x = xx - yy + cx
xx = x * x
yy = y * y
it -+= 1
.
return it
.
proc draw . .
Line 5,256 ⟶ 5,262:
for scr_x = 0 to 2 * mid - 1
cx = (scr_x - center_x) / scale
it = iter cx cy maxiter
callif iterit cx< cy itmaxiter
if it > 0
it = maxiter - it
color3 it / 20 it / 100 it / 150
move scr_x / res scr_y / res
Line 5,285 ⟶ 5,289:
scale /= 4
.
call draw
.
call draw
</syntaxhighlight>
 
Line 7,495 ⟶ 7,499:
 
[[File:Mandelbrot-Inform7.png]]
 
=={{Header|Insitux}}==
 
<syntaxhighlight lang="insitux">
(function mandelbrot width height depth
(.. str
(for yy (range height)
xx (range width)
(let c_re (/ (* (- xx (/ width 2)) 4) width)
c_im (/ (* (- yy (/ height 2)) 4) width)
x it0 =y maxiter0 -i it0)
(while (and (<= (+ (** x) (** y)) 4)
(< i depth))
(let x2 (+ c_re (- (** x) (** y)))
y (+ c_im (* 2 x y))
if it > 0 x x2
i (inc i)))
(strn ((zero? xx) "\n") (i "ABCDEFGHIJ ")))))
 
(mandelbrot 48 24 10)
.put for @lines[1..*];</syntaxhighlight>
 
{{out}}
 
<pre>
 
BBBBCCCDDDDDDDDDEEEEFGJJ EEEDDCCCCCCCCCCCCCCCBBB
BBBCCDDDDDDDDDDEEEEFFH HFEEEDDDCCCCCCCCCCCCCCBB
BBBCDDDDDDDDDDEEEEFFH GFFEEDDDCCCCCCCCCCCCCBB
BBCCDDDDDDDDDEEEEGGHI HGFFEDDDCCCCCCCCCCCCCCB
BBCDDDDDDDDEEEEFG HIGEDDDCCCCCCCCCCCCCB
BBDDDDDDDDEEFFFGH IEDDDDCCCCCCCCCCCCB
BCDDDDDDEEFFFFGG GFEDDDCCCCCCCCCCCCC
BDDDDDEEFJGGGHHI IFEDDDDCCCCCCCCCCCC
BDDEEEEFG J JI GEDDDDCCCCCCCCCCCC
BDEEEFFFHJ FEDDDDCCCCCCCCCCCC
BEEEFFFIJ FEEDDDCCCCCCCCCCCC
BEEFGGH HFEEDDDCCCCCCCCCCCC
JGFEEDDDDCCCCCCCCCCC
BEEFGGH HFEEDDDCCCCCCCCCCCC
BEEEFFFIJ FEEDDDCCCCCCCCCCCC
BDEEEFFFHJ FEDDDDCCCCCCCCCCCC
BDDEEEEFG J JI GEDDDDCCCCCCCCCCCC
BDDDDDEEFJGGGHHI IFEDDDDCCCCCCCCCCCC
BCDDDDDDEEFFFFGG GFEDDDCCCCCCCCCCCCC
BBDDDDDDDDEEFFFGH IEDDDDCCCCCCCCCCCCB
BBCDDDDDDDDEEEEFG HIGEDDDCCCCCCCCCCCCCB
BBCCDDDDDDDDDEEEEGGHI HGFFEDDDCCCCCCCCCCCCCCB
BBBCDDDDDDDDDDEEEEFFH GFFEEDDDCCCCCCCCCCCCCBB
BBBCCDDDDDDDDDDEEEEFFH HFEEEDDDCCCCCCCCCCCCCCBB
</pre>
 
=={{header|J}}==
Line 8,178 ⟶ 8,233:
n, r = 200, 500 # number of iterations and escape radius (r > 2)
 
direction, height = 45.0, 1.5 # direction and height of the light
density, intensity = 4.0, 0.5 # density and intensity of the stripes
 
Line 9,362 ⟶ 9,417:
Sample usage:
<syntaxhighlight lang="matlab">mandelbrotSet(-2.05-1.2i,0.004+0.0004i,0.45+1.2i,500);</syntaxhighlight>
 
=={{header|Maxima}}==
Using autoloded package plotdf
<syntaxhighlight lang="maxima">
mandelbrot ([iterations, 30], [x, -2.4, 0.75], [y, -1.2, 1.2],
[grid,320,320])$
</syntaxhighlight>
[[File:MandelbrotMaxima.png|thumb|center]]
 
=={{header|Metapost}}==
Line 11,151 ⟶ 11,214:
n, r = 200, 500 # number of iterations and escape radius (r > 2)
 
direction, height = 45.0, 1.5 # direction and height of the light
density, intensity = 4.0, 0.5 # density and intensity of the stripes
 
Line 11,252 ⟶ 11,315:
break
 
x = np.linspace(0, 2, num=d+1, dtype=np.float64)
y = np.linspace(0, 2 * h / d, num=h+1, dtype=np.float64)
 
A, B = np.meshgrid(x * np.pi, y * np.pi)
Line 11,452 ⟶ 11,515:
=={{header|Raku}}==
(formerly Perl 6)
{{Works with|rakudo|v20232023.08-473-g695b9dc46g2f8234c22}}
 
Using the [https://docs.raku.org/language/statement-prefixes#hyper,_race hyper statement prefix] for concurrency, the code below produces a [[Write ppm file|graymap]] to standard output.
Using the [https://raku.land/zef:raku-community-modules/Color color module] to create a palette.
Trying to use concurrency as much as possible.
Produces a [[Write ppm file|Portable Pixel Map]] to standard output
Redirect into a file to save it.
Converted to a JPEG file for display here.
 
[[File:mandelbrot-raku.jpg|300px|thumb|right]]
<syntaxhighlight lang="perl6"raku>constant MAX-ITERATIONS = 100064;
my $width = +(@*ARGS[0] // 800);
my $height = $width + $width %% 2;
say "P3P2";
say "$width $height";
say "255"MAX-ITERATIONS;
 
sub cut(Range $r, UInt $n where $n > 1 --> Seq) {
Line 11,484 ⟶ 11,543:
my @lines = hyper for @im X+ @re {
mandelbrot(0i, $_);
use Color;
my $i = (255 * sqrt(mandelbrot(0i, $_) / (MAX-ITERATIONS + 1))).Int;
(state @)[$i] //= Color.new(hsv => $i xx 3).rgb
}.rotor($width);
 
.put for @lines[1..*].reverse;
.put for @lines[0];</syntaxhighlight>
.put for @lines[1..*];</syntaxhighlight>
 
<!-- # Not sure this version is that much modern or faster now.
Line 12,398 ⟶ 12,454:
# for which the sequence z[n+1] := z[n] ** 2 + z[0] (n >= 0) is bounded.
# Since this program is computing intensive it should be compiled with
# hi comps7c -O2 mandelbr
 
const integer: pix is 200;
Line 12,430 ⟶ 12,486:
z0 := center + complex(flt(x) * zoom, flt(y) * zoom);
point(x + pix, y + pix, colorTable[iterate(z0)]);
end for;
end for;
end func;
Line 12,448 ⟶ 12,504:
end for;
displayMandelbrotSet(complex(-0.75, 0.0), 1.3 / flt(pix));
DRAW_FLUSHflushGraphic;
readln(KEYBOARD);
end func;
Line 13,534 ⟶ 13,590:
for (( iter=0; iter<maxiter && x2+y2<=16384; iter++ ))
do
((
((
y=((x*y)>>11)+cy,
x=x2-y2+cx,
x2=(x*x)>>12,
y2=(y*y)>>12
))
))
done
((c=iter%lC))
Line 14,231 ⟶ 14,287:
{{trans|Kotlin}}
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color
import "dome" for Window
 
Line 14,276 ⟶ 14,332:
 
var Game = MandelbrotSet.new(800, 600)</syntaxhighlight>
 
{{out}}
[[File:Wren-Mandelbrot_set.png|400px]]
 
=={{header|XPL0}}==
29

edits