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 =
scale = 10
xmin = -2; xmax = 1/2
Line 1,891 ⟶ 1,894:
print "P2\n", width, " ", height, "\n255\n"
for (i = 0; i <
for (j = 0; j <
tmp_scale = scale
scale = 0
m = (255 * mandelbrot(x, y) + max_iter + 1) / max_iter
print m
if ( j <
scale = tmp_scale
Line 5,222 ⟶ 5,225:
=={{header|EasyLang}}==
[https://easylang.
<syntaxhighlight lang="easylang">
# Mandelbrot
#
res = 4
maxiter = 200
Line 5,241 ⟶ 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,256 ⟶ 5,262:
for scr_x = 0 to 2 * mid - 1
cx = (scr_x - center_x) / scale
it = iter cx cy maxiter
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
.
.
</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)
(while (and (<= (+ (** x) (** y)) 4)
(< i depth))
(let x2 (+ c_re (- (** x) (** y)))
y (+ c_im (* 2 x y))
i (inc i)))
(strn ((zero? xx) "\n") (i "ABCDEFGHIJ ")))))
(mandelbrot 48 24 10)
{{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|
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.jpg|300px|thumb|right]]
<syntaxhighlight lang=
my $width = +(@*ARGS[0] // 800);
my $height = $width + $width %% 2;
say "
say "$width $height";
say
sub cut(Range $r, UInt $n where $n > 1 --> Seq) {
Line 11,484 ⟶ 11,543:
my @lines = hyper for @im X+ @re {
mandelbrot(0i, $_);
}.rotor($width);
.put for @lines[1..*].reverse;
.put for @lines
▲.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
#
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));
readln(KEYBOARD);
end func;
Line 13,534 ⟶ 13,590:
for (( iter=0; iter<maxiter && x2+y2<=16384; iter++ ))
do
((
))
done
((c=iter%lC))
Line 14,231 ⟶ 14,287:
{{trans|Kotlin}}
{{libheader|DOME}}
<syntaxhighlight lang="
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}}==
|