Skip to content

Commit 3e2c0d2

Browse files
committed
convert Mandelbrot gallery items to native complex
1 parent 5eb3e69 commit 3e2c0d2

2 files changed

Lines changed: 24 additions & 26 deletions

File tree

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- add labels3d, arrows3d
77
- compatibility break: requires OpenGL 1.5 (from 2003)
88
- now uses OpenGL::Modern
9+
- `demo 3dgal` Mandelbrot entries now native complex
910

1011
2.102 2025-04-11
1112
- fix scrolling out with mousewheel/double-touch-scroll in GLUT

lib/PDL/Demos/TriDGallery.pm

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,22 @@ $|.__PACKAGE__.q|::we_opened = !defined $PDL::Graphics::TriD::current_window;
4646
# B/W Mandelbrot... [Tjl]
4747
4848
use PDL; use PDL::Graphics::TriD; # NOTE all demos need this, only showing once
49-
$s=150;$r=xlinvals(-1.5,0.5,$s,$s);$i=ylinvals(-1,1,$s,$s);
50-
$t=$r;$u=$i;
51-
for(0..12){$q=$r**2-$i**2+$t;$h=2*$r*$i+$u;($r,$i)=map{$_->clip(-5,5)}($q,$h);}
52-
imagrgb[($r**2+$i**2)>2.0];
49+
$s = 150; $z = $c = czip(xlinvals(-1.5,0.5,$s,$s),ylinvals(-1,1,$s,$s));
50+
for (0..12) { $z = $z*$z + $c; $z->$_->inplace->clip(-5,5) for qw(re im); }
51+
imagrgb[$z->abs2 > 2.0];
5352
5453
# [press 'q' in the graphics window when done]
5554
|],
5655

5756
[actnw => q|
5857
# Greyscale Mandelbrot [Tjl]
5958
60-
$x=zeroes 300,300; $r=$x->xlinvals(-1.5, 0.5);
61-
$i=$x->ylinvals(-1,1); $t=$r; $u=$i;
62-
for(1..30){
63-
$q=$r**2-$i**2+$t; $h=2*$r*$i+$u;
64-
$d=$r**2+$i**2; $x=lclip($x,$_*($d>2.0)*($x==0));
65-
($r,$i)=map $_->clip(-5,5), $q, $h;
59+
$s = 300; $x = zeroes $s,$s;
60+
$z = $c = czip($x->xlinvals(-1.5,0.5),$x->ylinvals(-1,1));
61+
for (1..30) {
62+
$d = $z->abs2; $z = $z*$z + $c;
63+
$x = lclip($x,$_*($d>2.0)*($x==0));
64+
$z->$_->inplace->clip(-5,5) for qw(re im);
6665
}
6766
imagrgb[$x/30];
6867
@@ -72,14 +71,12 @@ imagrgb[$x/30];
7271
[actnw => q|
7372
# Color Mandelbrot anim [Tjl]
7473
nokeeptwiddling3d();
75-
$x=zeroes 300,300;
76-
$t=$r=$x->xlinvals(-1.5,0.5);
77-
$u=$i=$x->ylinvals(-1,1);
78-
for(1..30) {
79-
$q=$r**2-$i**2+$t; $h=2*$r*$i+$u; $d=$r**2+$i**2;
80-
$x=lclip($x,$_*($d>2.0)*($x==0));
81-
($r,$i)=map $_->clip(-5,5), $q,$h;
82-
imagrgb[($x==0)*($r/2+0.75),($x==0)*($i+1)/2,$x/30];
74+
$s = 300; $x = zeroes $s,$s;
75+
$z = $c = czip($x->xlinvals(-1.5,0.5),$x->ylinvals(-1,1));
76+
for (1..30) {
77+
$d = $z->abs2; $z = $z*$z + $c;
78+
$x = lclip($x,$_*($d>2.0)*($x==0));
79+
imagrgb[($x==0)*($z->re/2+0.75),($x==0)*($z->im+1)/2,$x/30];
8380
}
8481
keeptwiddling3d();
8582
twiddle3d();
@@ -88,15 +85,15 @@ twiddle3d();
8885

8986
[actnw => q|
9087
# Neat variation of color mandelbrot
91-
sub f {return abs(sin($_[0]*30))}
92-
$x=zeroes 300,300;
93-
$r=$x->xlinvals(-1.5, 0.5); $i=$x->ylinvals(-1,1); $t=$r; $u=$i;
88+
sub f {abs(sin($_[0]*30))}
89+
$s = 300; $x = zeroes $s,$s;
90+
$z = $c = czip($x->xlinvals(-1.5,0.5),$x->ylinvals(-1,1));
9491
nokeeptwiddling3d();
95-
for(1..30) {
96-
$q=$r**2-$i**2+$t;
97-
$h=2*$r*$i+$u; $d=$r**2+$i**2; $x=lclip($x,$_*($d>2.0)*($x==0));
98-
($r,$i)=map $_->clip(-5,5), $q,$h;
99-
imagrgb[f(($x==0)*($r/2+0.75)),f(($x==0)*($i+1)/2),$x/30];
92+
for (1..30) {
93+
$d = $z->abs2; $z = $z*$z + $c;
94+
$x = lclip($x,$_*($d>2.0)*($x==0));
95+
$z->$_->inplace->clip(-5,5) for qw(re im);
96+
imagrgb[f(($x==0)*($z->re/2+0.75)),f(($x==0)*($z->im+1)/2),$x/30];
10097
}
10198
keeptwiddling3d();
10299
twiddle3d();

0 commit comments

Comments
 (0)