Mandelbrot set: Difference between revisions
m
Replace deprecated functions
(→{{header|Raku}}: clarify $width and $height) |
m (Replace deprecated functions) |
||
(22 intermediate revisions by 6 users not shown) | |||
Line 1,856:
!!!!!!!!!!!!!!!""""""""""""#####################################""""""""""""""""
</pre>
=={{header|bc}}==
[[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 = 401
scale = 10
xmin = -2; xmax = 1/2
ymin = -5/4; ymax = 5/4
define mandelbrot(c_re, c_im) {
auto i
# z = 0
z_re = 0; z_im = 0
z2_re = 0; z2_im = 0
for (i=0; i<max_iter; i++) {
# z *= z
z_im = 2*z_re*z_im
z_re = z2_re - z2_im
# z += c
z_re += c_re
z_im += c_im
# z2 = z.*z
z2_re = z_re*z_re
z2_im = z_im*z_im
if (z2_re + z2_im > 4) return i
}
return 0
}
print "P2\n", width, " ", height, "\n255\n"
for (i = 0; i < height; i++) {
y = ymin + (ymax - ymin) / height * i
for (j = 0; j < width; j++) {
x = xmin + (xmax - xmin) / width * j
tmp_scale = scale
scale = 0
m = (255 * mandelbrot(x, y) + max_iter + 1) / max_iter
print m
if ( j < width - 1 ) print " "
scale = tmp_scale
}
print "\n"
}
quit</syntaxhighlight>
=={{header|BASIC}}==
Line 5,003 ⟶ 5,057:
=={{header|Dc}}==
===ASCII output===
{{works with|GNU
{{works with|OpenBSD
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.
Line 5,171 ⟶ 5,225:
=={{header|EasyLang}}==
[https://easylang.
<syntaxhighlight lang="easylang">
# Mandelbrot
#
res = 4
maxiter = 200
Line 5,190 ⟶ 5,246:
textsize 2
#
while xx + yy < 4 and it
y = 2 * x * y + cy
x = xx - yy + cx
xx = x * x
yy = y * y
it
.
return it
.
proc draw . .
Line 5,205 ⟶ 5,262:
for scr_x = 0 to 2 * mid - 1
cx = (scr_x - center_x) / scale
it = iter cx cy maxiter
color3 it / 20 it / 100 it / 150
move scr_x / res scr_y / res
Line 5,234 ⟶ 5,289:
scale /= 4
.
.
</syntaxhighlight>
Line 7,444 ⟶ 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 0 y 0 i 0)
(while (and (<= (+ (** x) (** y)) 4)
(< i depth))
(let x2 (+ c_re (- (** x) (** y)))
y (+ c_im (* 2 x y))
x x2
i (inc i)))
(strn ((zero? xx) "\n") (i "ABCDEFGHIJ ")))))
(mandelbrot 48 24 10)
</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,127 ⟶ 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,311 ⟶ 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,100 ⟶ 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,201 ⟶ 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,401 ⟶ 11,515:
=={{header|Raku}}==
(formerly Perl 6)
{{Works with|rakudo|
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.
[[File:mandelbrot-raku
<syntaxhighlight lang=
my $width = +(@*ARGS[0] // 800);
my $height = $width
say "
say "$width $height";
say
sub cut(Range $r, UInt $n where $n > 1 --> Seq) {
Line 11,422 ⟶ 11,532:
my @re = cut(-2 .. 1/2, $width);
my @im = cut( 0 .. 5/4, 1 + ($height div 2)) X* 1i;
sub mandelbrot(Complex $z is copy, Complex $c --> Int) {
Line 11,432 ⟶ 11,542:
}
my @lines = hyper for @im
mandelbrot(0i, $_);
}.rotor($width);
.put for @lines[1..*].reverse;
.put for @lines;</syntaxhighlight>
<!-- # Not sure this version is that much modern or faster now.
Line 12,344 ⟶ 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
#
const integer: pix is 200;
Line 12,376 ⟶ 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,394 ⟶ 12,504:
end for;
displayMandelbrotSet(complex(-0.75, 0.0), 1.3 / flt(pix));
readln(KEYBOARD);
end func;
Line 13,480 ⟶ 13,590:
for (( iter=0; iter<maxiter && x2+y2<=16384; iter++ ))
do
((
))
done
((c=iter%lC))
Line 14,177 ⟶ 14,287:
{{trans|Kotlin}}
{{libheader|DOME}}
<syntaxhighlight lang="
import "dome" for Window
Line 14,222 ⟶ 14,332:
var Game = MandelbrotSet.new(800, 600)</syntaxhighlight>
{{out}}
[[File:Wren-Mandelbrot_set.png|400px]]
=={{header|XPL0}}==
|