2. ./Configure -des -Dprefix=$HOME/localperl
3. make test
4. make install
Xn+1=a1+a2*Xn+a3*Xn*Xn+a4*Xn*Yn+a5*Yn+a6*Yn*YnYn+1=a7+a8*Xn+a9*Xn*Xn+a10*Xn*Yn+a11*Yn+a12*Yn*Yn下図は、複数のストレンジアトラクタをオーバーレイして、さらに鏡像で合成したものです。前の記事と同じで、PerlとGDで作成しました。
Rampe1 Attractor参考文献
newx=z*sin(a*x)+cos(b*y)
newy=x*sin(c*y)+cos(d*z)
newz=y*sin(e*z)+cos(f*x)
Rampe2 Attractor
newx=z*sin(a*x)+arccos(b*y)
newy=x*sin(c*y)+arccos(d*z)
newz=y*sin(e*z)+arccos(f*x)
Rampe3 Attractor
newx=x*z*sin(a*x)-cos(b*y)
newy=y*x*sin(c*y)-cos(d*z)
newz=z*y*sin(e*z)-cos(f*x)
![]() |
| Xn+1=Xn*Xn-Yn*Yn+a*Xn+b*Yn Yn+1=2*Xn*Yn+c*Xn+d*Yn a=0.9, b=-0.6013, c=2.0, d=0.50 xo=-0.72, y0=-0.64 |
![]() |
| a=0.3, b=0.6000, c=2.0, d=0.27 xo=-0.17, y0=-0.17 |
a=0.9, b=-0.6013, c=2.0, d=0.50Perlのコードはとても単純だから、Gingerbreadmanのものを少し直せばいいです。
a=0.3, b=0.6000, c=2.0, d=0.27
![]() |
| 範囲 (-38, -38) - (80, 80)をプロットした |
![]() |
| ブレッドマンの中心部を切り出し。背景は黒にした |
Xn = 1-Yn-1+|Xn-1|初期値は-20から20の間です。
Yn=Xn
use strict;
use GD::Simple;
my @init = (7.5, -7.2, -39.6679279211404,-39.6679279211404,81.6679279211404,81.6679279211404);
my $x0 = $init[0];
my $y0 = $init[1];
my $max=5000;
my $maxTry = 1000;
my $i = 0;
my $minx = $init[2];
my $miny = $init[3];
my $maxx = $init[4];
my $maxy = $init[5];
sub transform {
my @ret = ();
my ($x, $y, $minx, $miny, $maxx, $maxy, $w, $h) = @_;
$ret[0] = int (($x-$minx)*$w/($maxx-$minx));
$ret[1] = int (($y-$miny)*$h/($maxy-$miny));
return @ret;
}
my $imgW = 2048;
my $imgH = 2048;
my $imgWOut = $imgW;
my $imgHOut = $imgH;
# create a new image
my $img = GD::Simple->new($imgWOut,$imgHOut);
# draw a red rectangle with blue borders
$img->bgcolor('black');
$img->fgcolor('green');
my $black = $img->colorAllocate(0,0,0);
my $green = $img->colorAllocate(0,255,0);
$img->rectangle(0,0,$imgWOut,$imgHOut,$black);
$img->fill(50,50,$black);
my @colors = ();
for ($i=1; $i<=4; $i++) {
my $val = $i*64%256;
$colors[$i*6+0] = $img->colorAllocate($val, 0, 0);
$colors[$i*6+1] = $img->colorAllocate( 0, $val, 0);
$colors[$i*6+2] = $img->colorAllocate( 0, 0, $val);
$colors[$i*6+3] = $img->colorAllocate($val, $val, 0);
$colors[$i*6+4] = $img->colorAllocate($val, 0, $val);
$colors[$i*6+5] = $img->colorAllocate( 0, $val, $val);
}
$img->transparent($black);
my $i = 0;
my $j = 0;
for ($j=0; $j<$maxTry; $j++) {
for ($i=0; $i<$max; $i++) {
my $x1 = 1-$y0+abs($x0);
my $y1 = $x0;
my ($xt, $yt) = transform($x1, $y1, $minx, $miny, $maxx, $maxy, $imgW, $imgH);
$img->setPixel($xt, $yt, $colors[$j%25]);
$x0 = $x1;
$y0 = $y1;
}
$x0 = rand 40;
$x0 -= 20;
$y0 = rand 40;
$y0 -= 20;
}
#output the image
open( OUT, "> gingerBreadMan.png") or die( "Cannot open file: graph.jpg" );
binmode OUT;
print OUT $img->png;
use GD::Simple;
use strict;
sub transform {
my @ret = ();
my ($x, $y, $w, $h) = @_;
$ret[0] = int (($x+2.2)*$w/5);
$ret[1] = int ((10-$y)*$h/10);
return @ret;
}
# a, b, c d, e, f
my @w1 = ( 0, 0, 0, 0.16, 0, 0.00);
my @w2 = ( 0.85, 0.04, -0.04, 0.85, 0, 1.60);
my @w3 = ( 0.20, -0.26, 0.23, 0.22, 0, 1.60);
my @w4 = (-0.15, 0.28, 0.26, 0.24, 0, 0.44);
my $x = 0;
my $y = 0;
my @p = (0.01, 0.85, 0.07, 0.07);
my @p1 = ($p[0]*10000,($p[0]+$p[1])*10000,($p[0]+$p[1]+$p[2])*10000);
my $i = 0;
my $max = 800000;
my $x1 = 0;
my $y1 = 0;
my @wt = ();
my $j;
my @ret;
my $imgW = 960;
my $imgH = 1024;
# create a new image
my $img = GD::Simple->new($imgW,$imgH);
# draw a red rectangle with blue borders
$img->bgcolor('black');
$img->fgcolor('green');
my $black = $img->colorAllocate(0,0,0);
my $green = $img->colorAllocate(0,255,0);
$img->rectangle(0,0,$imgW,$imgH,$black);
$img->fill(50,50,$black);
$img->transparent($black);
@ret = &transform($x, $y, $imgW, $imgH);
$img->setPixel($ret[0], $ret[1], $green);
for ($i=0; $i<$max; $i++) {
my $id=int(rand(10000));
if ($id < $p1[0] ) {
@wt = (@w1);
}
elsif ($id < $p1[1]) {
@wt = (@w2);
}
elsif ($id < $p1[2]) {
@wt = (@w3);
}
else {
@wt = (@w4,0);
}
$x1 = $x*$wt[0] + $y*$wt[1] + $wt[4];
$y1 = $x*$wt[2] + $y*$wt[3] + $wt[5];
@ret = &transform($x1, $y1, $imgW, $imgH);
$img->setPixel($ret[0], $ret[1], $green);
$x = $x1;
$y = $y1;
}
#output the image
open( OUT, "> fern.png") or die( "Cannot open file: graph.jpg" );
binmode OUT;
print OUT $img->png;
yum install gd-devel
yum install perl-GDTextUtil.noarch
yum install perl-GDGraph.noarch
yum install gd-devel.x86_64
my @配列名 = (val0, val1, ..., valn);
my @配列名;
$配列名[0] = val0;
$配列名[1] = val1;
... ...
$配列名[n] = valn;
($配列名[0], $配列名[1]) = (val0, val1);
foreach my $val (@配列名){
print "$val¥n";
}
@配列名 = ();
my $length = @array;