blib/lib/Math/Fractal/Noisemaker.pm

filter: Statementstmt 74.1% 1502 / 2025 Branchbran 64.2% 569 / 886 Conditioncond 50.5% 178 / 352 MC/DCmcdc 19.6% 41 / 209 Subroutinesub 80.0% 88 / 110 Podpod 59.2% 48 / 81 totaltotal 66.2% 2426 / 3663 CC 583 SCAR 62.7
CC
583
Cov
69%
make
3036.6
img
67.3
spheremap
56.0
CRAP 526.9
↑ Summary
1 package Math::Fractal::Noisemaker;
2  
3 1 our $VERSION = '0.105';
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Imager;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Math::Trig qw| :radial deg2rad tan pi |;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Tie::CArray;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use base qw| Exporter |;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 our $COLUMN_CLASS = "Tie::CDoubleArray";
15  
16 1 our @SIMPLE_TYPES = qw|
17 white wavelet gradient square gel sgel stars spirals dla worley wgel
18 fflame mandel dmandel buddha fern gasket julia djulia newton
19 infile intile moire textile sparkle canvas simplex simplex2
20 |;
21  
22 1 our @PERLIN_TYPES = qw|
23 multires ridged block pgel fur tesla lumber wormhole flux
24 |;
25  
26 1 our @NOISE_TYPES = ( @SIMPLE_TYPES, @PERLIN_TYPES, qw| terra | );
27  
28 1 our @EXPORT_OK = "make";
29  
30 # there used to be more stuff here, but i'll leave the :all tag
31 1 our %EXPORT_TAGS = (
32 'all' => \@EXPORT_OK,
33 );
34  
35 1 our $DEFAULT_FORMAT = "bmp";
36 1 our $DEFAULT_AMP = .5;
37 1 our $DEFAULT_BIAS = .5;
38 1 our $DEFAULT_LEN = 256;
39 1 our $DEFAULT_TYPE = 'multires';
40 1 our $DEFAULT_SLICE_TYPE = 'white';
41 1 our $DEFAULT_TERRAIN_BASE = 'multires';
42 1 our $DEFAULT_TERRAIN_SLICE = 'ridged';
43 1 our $DEFAULT_GAP = 0;
44 1 our $DEFAULT_FREQ = 4;
45 1 our $DEFAULT_OCTAVES = 8;
46 1 our $DEFAULT_PERSIST = .5;
47 1 our $DEFAULT_DISPLACEMENT = 1;
48 1 our $DEFAULT_INTERP = 1;
49 1 our $DEFAULT_RHO = 1;
50  
51 1 our $QUIET;
52  
53 1 my $MAX_COLOR = 255;
54  
55 1 my $INTERP_FN;
56 my $GROW_FN;
57  
58 #
59 # Persistent gradient values
60 #
61 1 my @NUMS = ( -255 .. 255 );
62 1 do {
63 1 my @r;
64 1 ▶ while (@NUMS) {
Branch: 1 branch
BranchTrueFalseTotal
if (@NUMS) 511 1 512
65 511 my $i = rand(@NUMS);
66 511 push @r, $NUMS[$i];
67 511 splice( @NUMS, $i, 1 );
68 }
69 1 @NUMS = @r;
70 };
71  
72 0 ▶sub showVersion {
Subroutine showVersion: not called CC=1 SCAR=6.9
Pod undocumented
73 0 print "Math::Fractal::Noisemaker $VERSION\n";
74 }
75  
76 0 ▶sub showTypes {
Subroutine showTypes: not called CC=1 SCAR=6.9
Pod undocumented
77 0 showVersion();
78  
79 0 print "\n";
80 0 print "All noise types have optional args, see -h.\n";
81 0 print "\n";
82 0 print "Noise Types:\n";
83 0 print "\n";
84 0 print " * white ## pseudo-random values\n";
85 0 print " * wavelet ## band-limited ortho\n";
86 0 print " * gradient ## persistent gradient noise\n";
87 0 print " * simplex ## continuous gradient noise\n";
88 0 print " * simplex2 ## interpolated simplex\n";
89 0 print " * square ## diamond-square algorithm\n";
90 0 print " * gel ## self-displaced smooth\n";
91 0 print " * sgel ## self-displaced diamond-square\n";
92 0 print " * dmandel ## \"deep\" mandelbrot\n";
93 0 print " * djulia ## \"deep\" julia\n";
94 0 print " * dla ## diffusion-limited aggregation\n";
95 0 print " * worley ## voronoi cell noise\n";
96 0 print " * wgel ## self-displaced cell noise\n";
97 0 print "\n";
98 0 print " ! multires ## multi-resolution\n";
99 0 print " ! ridged ## ridged multifractal\n";
100 0 print " ! block ## unsmoothed multi-res\n";
101 0 print " ! pgel ## self-displaced multi-res\n";
102 0 print " ! fur ## inspired by \"Perlin Worms\"\n";
103 0 print " ! tesla ## worms/fur variant\n";
104 0 print "\n";
105 0 print "Legend:";
106 0 print "\n";
107 0 print " * single-res type\n";
108 0 print " ! multi-res type - use 'stype' arg to change basis func\n";
109 0 print "\n";
110 0 print "For even more types(!), see:\n";
111 0 print " $0 -h moretypes\n";
112 0 print "\n";
113 0 print "perldoc Math::Fractal::Noisemaker for more help, or see:\n";
114 0 print
115 " http://search.cpan.org/~aayars/Math-Fractal-Noisemaker/lib/Math/Fractal/Noisemaker.pm\n";
116 0 print "\n";
117  
118 0 exit 1;
119 }
120  
121 0 ▶sub showMoreTypes {
Subroutine showMoreTypes: not called CC=1 SCAR=6.9
Pod undocumented
122 0 showVersion();
123 0 print "\n";
124 0 print "Additional types:\n";
125 0 print "\n";
126  
127 0 print " * mandel ## Mandelbrot (demo)\n";
128 0 print " * buddha ## buddhabrot\n";
129 0 print " * julia ## Julia set\n";
130 0 print " * newton ## Newton fractal (demo)\n";
131 0 print " * fflame ## IFS fractal flame\n";
132 0 print " * fern ## IFS fern (demo)\n";
133 0 print " * gasket ## IFS gasket (demo)\n";
134 0 print " * stars ## starfield\n";
135 0 print " * spirals ## tiny logspirals\n";
136 0 print " * moire ## interference patterns\n";
137 0 print " * textile ## random high-freq moire\n";
138 0 print " * infile ## image file named by 'in' arg\n";
139 0 print " * intile ## infile + blend seams\n";
140 0 print " * sparkle ## stylized stars\n";
141 0 print " * canvas ## like an old map\n";
142 0 print "\n";
143 0 print " ! lumber ## vaguely woodlike\n";
144 0 print " ! wormhole ## field flow\n";
145 0 print " ! flux ## extruded contours\n";
146 0 print " ! terra ## terrain recipe (see -h more)\n";
147 0 print "\n";
148  
149 0 exit 1;
150 }
151  
152 0 ▶sub usage {
Subroutine usage: not called CC=2 SCAR=17.9
Pod undocumented
153 0 showVersion();
154  
155 0 print "\n";
156 0 print "All command line args are optional.\n";
157 0 print "\n";
158 0 print "Usage:\n";
159 0 print "$0 \\\n";
160 0 print " [-type <noisetype>] \\ ## noise type\n";
161 0 print " [-stype <single-res type>]\\ ## multi-res slice type\n";
162 0 print " [-amp <num>] \\ ## base amplitude (eg .5)\n";
163 0 print " [-freq <num>] \\ ## base frequency (eg 2)\n";
164 0 print " [-len <int>] \\ ## side length (eg 256)\n";
165 0 print " [-bias <num>] \\ ## value bias (0..1)\n";
166 0 print " [-qual <0|1|2|3>]* \\ ## quality (draft|linear|cosine|gaussian)\n";
167 0 print " [-octaves <int>] \\ ## multi-res octaves (eg 4)\n";
168 0 print " [-refract <0|1>] \\ ## refractive grayscale palette\n";
169 0 print " [-sphere <0|1>] \\ ## fake spheremap\n";
170 0 print " [-displace <num>] \\ ## self-displacement (eg .25)\n";
171 0 print " [-clut <filename>] \\ ## color lookup table (ex.bmp)\n";
172 0 print " [-clutdir 0|1|2] \\ ## clut direction diagonal|vertical|fractal\n";
173 0 print " [-in <filename>] \\ ## input filename for infile (infile.bmp)\n";
174 0 print " [-shadow <0..1>] \\ ## false shadow/highlight amount (rec. .5)\n";
175 0 print " [-nth <n>] \\ ## worley: Nth closest neighbor (0-index)\n";
176 0 print " [-dist <0|1|2|3>] \\ ## worley: euclid|manhat|cheby|? (0|1|2|3)\n";
177 0 print " [-cell <0|1>] \\ ## worley: render as distance|cell (0|1)\n";
178 0 print " [-tile 0|1|2|3] \\ ## force tiling (off|both|horiz|vert)\n";
179 0 print " [-format <type>] \\ ## file type (default bmp)\n";
180 0 print " [-outdir <dir>] \\ ## output dir (eg \"mynoise/\")\n";
181 0 print " [-quiet <0|1>] \\ ## no STDOUT spam\n";
182 0 print " [-out <filename>] ## Output file (foo.bmp)\n";
183 0 print "\n";
184 0 print "* Add a plus (+) to quality arg to use non-upsampled noise, eg:\n";
185 0 print " make-noise -quality 1+\n";
186 0 print "\n";
187 0 print "For more options, see:\n";
188 0 print " $0 -h more\n";
189 0 print "\n";
190 0 print "For a list of available noise types, see:\n";
191 0 print " $0 -h types\n";
192 0 print "\n";
193 0 print "perldoc Math::Fractal::Noisemaker for more help.\n";
194 0 print "\n";
195  
196 0 my $warning = shift;
197 0 ▶ print "$warning\n" if $warning;
Branch: 1 branch
BranchTrueFalseTotal
if $warning 0 0 0
198  
199 0 exit 1;
200 }
201  
202 0 ▶sub moreUsage {
Subroutine moreUsage: not called CC=2 SCAR=17.9
Pod undocumented
203 0 showVersion();
204  
205 0 print "\n";
206 0 print "Additional options:\n";
207 0 print "$0 \\\n";
208 0 print " [-persist <num>] \\ ## multi-res persistence (eg .5)\n";
209 0 print " [-gap <num>] \\ ## stars: gappiness (0..1)\n";
210 0 print " [-smooth <0|1>] \\ ## resampling off|on (default: on)\n";
211 0 print " [-interp <0|1>] \\ ## interp fn linear|cosine\n";
212 0 print " [-grow <0|1>] \\ ## growth fn interp|gaussian\n";
213 0 print " [-limit 0|1] \\ ## scale|clip pixel values\n";
214 0 print " [-zoom <num>] \\ ## fractals: scale magnitude\n";
215 0 print " [-maxiter <num>] \\ ## fractals: iteration limit\n";
216 0 print " [-emboss <0|1>] \\ ## output shadow only (no|yes)\n";
217 0 print " [-zshift <-1..1>] \\ ## final z offset for ridged\n";
218 0 print " [-delta 0|1] \\ ## output as difference noise\n";
219 0 print " [-chiral 0|1] \\ ## output as additive noise\n";
220 0 print " [-stereo 0|1] \\ ## output as stereogram\n";
221 0 print "\n";
222 0 print "'terra' options:\n";
223 0 print "\n";
224 0 print " [-lbase <any type but terra>] \\ ## terra continent shape\n";
225 0 print " [-ltype <any type but terra>] \\ ## terra multi-res type\n";
226 0 print " [-feather <num>] \\ ## terra feather amt (0..255)\n";
227 0 print " [-layers <int>] \\ ## terra layers (eg 3)\n";
228 0 print "\n";
229  
230 0 my $warning = shift;
231 0 ▶ print "$warning\n" if $warning;
Branch: 1 branch
BranchTrueFalseTotal
if $warning 0 0 0
232  
233 0 exit 1;
234 }
235  
236 39 ▶sub make {
Subroutine make: called CC=117 SCAR=80.2
Pod documented
237 39 my %args;
238  
239 39 ▶ while ( my $arg = shift ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $arg = shift()) 196 39 235
240 196 ▶ if ( $arg =~ /(-h$|help)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /(-h$|help)/) 0 196 196
241 0 ▶ if ( $_[0] && lc( $_[0] ) eq 'types' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($_[0] and lc $_[0] eq 'types') { } 0 0 0
elsif ($_[0] and lc $_[0] eq 'moretypes') { } 0 0 0
elsif ($_[0] and lc $_[0] eq 'more') { } 0 0 0
Condition0%0/3
$_[0] and lc $_[0] eq "types"
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] and lc $_[0] eq "types"
$_[0] lc $_[0] eq "types"
Truth table0%0/3
A and B
A= $_[0]B= lc $_[0] eq "types"
ABresult
0X0
100
111
242 0 showTypes();
243 ▶ } elsif ( $_[0] && lc( $_[0] ) eq 'moretypes' ) {
Condition0%0/3
$_[0] and lc $_[0] eq "moretypes"
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] and lc $_[0] eq "moretypes"
$_[0] lc $_[0] eq "moretypes"
Truth table0%0/3
A and B
A= $_[0]B= lc $_[0] eq "moretypes"
ABresult
0X0
100
111
244 0 showMoreTypes();
245 ▶ } elsif ( $_[0] && lc( $_[0] ) eq 'more' ) {
Condition0%0/3
$_[0] and lc $_[0] eq "more"
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] and lc $_[0] eq "more"
$_[0] lc $_[0] eq "more"
Truth table0%0/3
A and B
A= $_[0]B= lc $_[0] eq "more"
ABresult
0X0
100
111
246 0 moreUsage();
247 } else {
248 0 usage();
249 }
250 }
251  
252 196 ▶ if ( $arg =~ /(^|-)type/ ) { $args{type} = shift; }
Branch: 42 branches
BranchTrueFalseTotal
if ($arg =~ /(^|-)type/) { } 39 157 196
elsif ($arg =~ /stype/) { } 0 157 157
elsif ($arg =~ /lbase/) { } 0 157 157
elsif ($arg =~ /ltype/) { } 0 157 157
elsif ($arg =~ /amp/) { } 0 157 157
elsif ($arg =~ /freq/) { } 0 157 157
elsif ($arg =~ /len/) { } 39 118 157
elsif ($arg =~ /octaves/) { } 0 118 118
elsif ($arg =~ /bias/) { } 0 118 118
elsif ($arg =~ /persist/) { } 0 118 118
elsif ($arg =~ /qual/) { } 0 118 118
elsif ($arg =~ /interp$/) { } 0 118 118
elsif ($arg =~ /grow$/) { } 0 118 118
elsif ($arg =~ /gap/) { } 0 118 118
elsif ($arg =~ /feather/) { } 0 118 118
elsif ($arg =~ /layers/) { } 0 118 118
elsif ($arg =~ /smooth/) { } 0 118 118
elsif ($arg =~ /(^|-)out$/) { } 1 117 118
elsif ($arg =~ /sphere/) { } 0 117 117
elsif ($arg =~ /refract/) { } 0 117 117
elsif ($arg =~ /displace/) { } 0 117 117
elsif ($arg =~ /clut$/) { } 0 117 117
elsif ($arg =~ /clutdir$/) { } 0 117 117
elsif ($arg =~ /limit/) { } 0 117 117
elsif ($arg =~ /zoom/) { } 0 117 117
elsif ($arg =~ /maxiter/) { } 0 117 117
elsif ($arg =~ /shadow/) { } 0 117 117
elsif ($arg =~ /emboss/) { } 0 117 117
elsif ($arg =~ /(^|-)in$/) { } 39 78 117
elsif ($arg =~ /zshift/) { } 0 78 78
elsif ($arg =~ /nth/) { } 0 78 78
elsif ($arg =~ /cell/) { } 0 78 78
elsif ($arg =~ /dist/) { } 0 78 78
elsif ($arg =~ /delta/) { } 0 78 78
elsif ($arg =~ /chiral/) { } 0 78 78
elsif ($arg =~ /stereo/) { } 0 78 78
elsif ($arg =~ /tile/) { } 0 78 78
elsif ($arg =~ /xscale/) { } 0 78 78
elsif ($arg =~ /yscale/) { } 0 78 78
elsif ($arg =~ /quiet/) { } 39 39 78
elsif ($arg =~ /format/) { } 0 39 39
elsif ($arg =~ /outdir/) { } 39 0 39
253 0 elsif ( $arg =~ /stype/ ) { $args{stype} = shift; }
254 0 elsif ( $arg =~ /lbase/ ) { $args{lbase} = shift; }
255 0 elsif ( $arg =~ /ltype/ ) { $args{ltype} = shift; }
256 0 elsif ( $arg =~ /amp/ ) { $args{amp} = shift; }
257 0 elsif ( $arg =~ /freq/ ) { $args{freq} = shift; }
258 39 elsif ( $arg =~ /len/ ) { $args{len} = shift; }
259 0 elsif ( $arg =~ /octaves/ ) { $args{octaves} = shift; }
260 0 elsif ( $arg =~ /bias/ ) { $args{bias} = shift; }
261 0 elsif ( $arg =~ /persist/ ) { $args{persist} = shift; }
262 0 elsif ( $arg =~ /qual/ ) { $args{quality} = shift; }
263 0 elsif ( $arg =~ /interp$/ ) { $args{interp} = shift; }
264 0 elsif ( $arg =~ /grow$/ ) { $args{grow} = shift; }
265 0 elsif ( $arg =~ /gap/ ) { $args{gap} = shift; }
266 0 elsif ( $arg =~ /feather/ ) { $args{feather} = shift; }
267 0 elsif ( $arg =~ /layers/ ) { $args{layers} = shift; }
268 0 elsif ( $arg =~ /smooth/ ) { $args{smooth} = shift; }
269 1 elsif ( $arg =~ /(^|-)out$/ ) { $args{out} = shift; }
270 0 elsif ( $arg =~ /sphere/ ) { $args{sphere} = shift; }
271 0 elsif ( $arg =~ /refract/ ) { $args{refract} = shift; }
272 0 elsif ( $arg =~ /displace/ ) { $args{displace} = shift; }
273 0 elsif ( $arg =~ /clut$/ ) { $args{clut} = shift; }
274 0 elsif ( $arg =~ /clutdir$/ ) { $args{clutdir} = shift; }
275 0 ▶ elsif ( $arg =~ /limit/ ) { $args{auto} = shift() ? 0 : 1; }
Branch: 1 branch
BranchTrueFalseTotal
shift() ? : 0 0 0
276 0 elsif ( $arg =~ /zoom/ ) { $args{zoom} = shift; }
277 0 elsif ( $arg =~ /maxiter/ ) { $args{maxiter} = shift; }
278 0 elsif ( $arg =~ /shadow/ ) { $args{shadow} = shift; }
279 0 elsif ( $arg =~ /emboss/ ) { $args{emboss} = shift; }
280 39 elsif ( $arg =~ /(^|-)in$/ ) { $args{in} = shift; }
281 0 elsif ( $arg =~ /zshift/ ) { $args{zshift} = shift; }
282 0 elsif ( $arg =~ /nth/ ) { $args{nth} = shift; }
283 0 elsif ( $arg =~ /cell/ ) { $args{cell} = shift; }
284 0 elsif ( $arg =~ /dist/ ) { $args{dist} = shift; }
285 0 elsif ( $arg =~ /delta/ ) { $args{delta} = shift; }
286 0 elsif ( $arg =~ /chiral/ ) { $args{chiral} = shift; }
287 0 elsif ( $arg =~ /stereo/ ) { $args{stereo} = shift; }
288 0 elsif ( $arg =~ /tile/ ) { $args{tile} = shift; }
289 0 elsif ( $arg =~ /xscale/ ) { $args{xscale} = shift; }
290 0 elsif ( $arg =~ /yscale/ ) { $args{yscale} = shift; }
291 39 elsif ( $arg =~ /quiet/ ) { $QUIET = shift; }
292 0 elsif ( $arg =~ /format/ ) { $args{format} = shift; }
293 39 elsif ( $arg =~ /outdir/ ) { $args{outdir} = shift; }
294 0 else { usage("Unknown argument: $arg") }
295 }
296  
297 39 ▶ usage("Specified CLUT file not found") if $args{clut} && !-e $args{clut};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"clut"} and not -e $args{"clut"} 0 39 39
Condition33%1/3
$args{"clut"} and not -e $args{"clut"}
!ll&&!rl&&r
3900
MC/DC0%0/2
$args{"clut"} and not -e $args{"clut"}
$args{"clut"} not -e $args{"clut"}
Truth table33%1/3
A and not(B)
A= $args{"clut"}B= not -e $args{"clut"}
ABresult
0X0
100
111
298  
299 39 my $q = $args{quality};
300 39 $args{upsample} = 1;
301  
302 39 ▶ if ( defined $q ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $q) 0 39 39
303 0 ▶ $args{upsample} = 0 if $q =~ s/\+$//;
Branch: 1 branch
BranchTrueFalseTotal
if $q =~ s/\+$// 0 0 0
304  
305 0 ▶ if ( $q == 0 ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($q == 0) { } 0 0 0
elsif ($q == 1) { } 0 0 0
elsif ($q == 2) { } 0 0 0
elsif ($q == 3) { } 0 0 0
306 0 ▶ $args{smooth} = 0 if !defined $args{smooth};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"smooth"} 0 0 0
307 0 ▶ $args{interp} = 0 if !defined $args{interp};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"interp"} 0 0 0
308 0 ▶ $args{grow} = 0 if !defined $args{grow};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"grow"} 0 0 0
309 } elsif ( $q == 1 ) {
310 0 ▶ $args{smooth} = 1 if !defined $args{smooth};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"smooth"} 0 0 0
311 0 ▶ $args{interp} = 0 if !defined $args{interp};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"interp"} 0 0 0
312 0 ▶ $args{grow} = 0 if !defined $args{grow};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"grow"} 0 0 0
313 } elsif ( $q == 2 ) {
314 0 ▶ $args{smooth} = 1 if !defined $args{smooth};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"smooth"} 0 0 0
315 0 ▶ $args{interp} = 1 if !defined $args{interp};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"interp"} 0 0 0
316 0 ▶ $args{grow} = 0 if !defined $args{grow};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"grow"} 0 0 0
317 } elsif ( $q == 3 ) {
318 0 ▶ $args{smooth} = 1 if !defined $args{smooth};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"smooth"} 0 0 0
319 0 ▶ $args{interp} = 1 if !defined $args{interp};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"interp"} 0 0 0
320 0 ▶ $args{grow} = 1 if !defined $args{grow};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"grow"} 0 0 0
321 }
322 }
323  
324 #
325 #
326 #
327 39 ▶ $args{type} ||= $DEFAULT_TYPE;
Condition33%1/3
$args{"type"} ||= $Math::Fractal::Noisemaker::DEFAULT_TYPE
l!l&&r!l&&!r
3900
MC/DC0%0/2
$args{"type"} ||= $Math::Fractal::Noisemaker::DEFAULT_TYPE
$args{"type"} $Math::Fractal::Noisemaker::DEFAULT_TYPE
Truth table33%1/3
A ||= B
A= $args{"type"}B= $Math::Fractal::Noisemaker::DEFAULT_TYPE
ABresult
1X1
011
000
328 39 ▶ $args{stype} ||= $DEFAULT_SLICE_TYPE;
Condition33%1/3
$args{"stype"} ||= $Math::Fractal::Noisemaker::DEFAULT_SLICE_TYPE
l!l&&r!l&&!r
0390
MC/DC0%0/2
$args{"stype"} ||= $Math::Fractal::Noisemaker::DEFAULT_SLICE_TYPE
$args{"stype"} $Math::Fractal::Noisemaker::DEFAULT_SLICE_TYPE
Truth table33%1/3
A ||= B
A= $args{"stype"}B= $Math::Fractal::Noisemaker::DEFAULT_SLICE_TYPE
ABresult
1X1
011
000
329 39 ▶ $args{lbase} ||= $DEFAULT_TERRAIN_BASE;
Condition33%1/3
$args{"lbase"} ||= $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_BASE
l!l&&r!l&&!r
0390
MC/DC0%0/2
$args{"lbase"} ||= $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_BASE
$args{"lbase"} $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_BASE
Truth table33%1/3
A ||= B
A= $args{"lbase"}B= $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_BASE
ABresult
1X1
011
000
330 39 ▶ $args{ltype} ||= $DEFAULT_TERRAIN_SLICE;
Condition33%1/3
$args{"ltype"} ||= $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_SLICE
l!l&&r!l&&!r
0390
MC/DC0%0/2
$args{"ltype"} ||= $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_SLICE
$args{"ltype"} $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_SLICE
Truth table33%1/3
A ||= B
A= $args{"ltype"}B= $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_SLICE
ABresult
1X1
011
000
331  
332 #
333 #
334 #
335 39 ▶ if ( !defined $args{interp} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"interp"}) 39 0 39
336 39 $args{interp} = $DEFAULT_INTERP;
337 }
338  
339 39 ▶ $INTERP_FN = $args{interp} ? \&cosine_interp : \&lerp;
Branch: 1 branch
BranchTrueFalseTotal
$args{'interp'} ? : 39 0 39
340  
341 39 ▶ if ( $args{grow} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'grow'}) { } 0 39 39
342 0 $GROW_FN = \&grow_gaussian;
343 } else {
344 39 $GROW_FN = \&grow_interp;
345 }
346  
347 39 ▶ if ( !defined $args{smooth} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"smooth"}) 39 0 39
348 39 $args{smooth} = 1;
349 }
350  
351 #
352 #
353 #
354 39 ▶ if ( $args{shadow} && $args{emboss} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"shadow"} and $args{"emboss"}) 0 39 39
Condition33%1/3
$args{"shadow"} and $args{"emboss"}
!ll&&!rl&&r
3900
MC/DC0%0/2
$args{"shadow"} and $args{"emboss"}
$args{"shadow"} $args{"emboss"}
Truth table33%1/3
A and B
A= $args{"shadow"}B= $args{"emboss"}
ABresult
0X0
100
111
355 0 delete $args{shadow};
356 }
357  
358 39 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'type'} eq 'terra' and $args{'lbase'} =~ /[prs]gel/ || $args{'ltype'} =~ /[prs]gel/ || $args{'stype'} =~ /[prs]gel/) { } 0 39 39
elsif ($args{'type'} eq 'terra' and $args{'lbase'} eq 'gel' || $args{'ltype'} eq 'gel' || $args{'stype'} eq 'gel') { } 0 77 77
Condition44%4/9
$args{"type"} eq "terra" and $args{"lbase"} =~ /[prs]gel/ || $args{"ltype"} =~ /[prs]gel/ || $args{"stype"} =~ /[prs]gel/
!ll&&!rl&&r
3810
$args{"lbase"} =~ /[prs]gel/ or $args{"ltype"} =~ /[prs]gel/ or $args{"stype"} =~ /[prs]gel/
l!l&&r!l&&!r
001
$args{"lbase"} =~ /[prs]gel/ or $args{"ltype"} =~ /[prs]gel/
l!l&&r!l&&!r
001
MC/DC0%0/4
$args{"type"} eq "terra" and $args{"lbase"} =~ /[prs]gel/ || $args{"ltype"} =~ /[prs]gel/ || $args{"stype"} =~ /[prs]gel/
$args{"type"} eq "terra" $args{"lbase"} =~ /[prs]gel/ $args{"ltype"} =~ /[prs]gel/ $args{"stype"} =~ /[prs]gel/
Truth table40%2/5
A and B or C or D
A= $args{"type"} eq "terra"B= $args{"lbase"} =~ /[prs]gel/C= $args{"ltype"} =~ /[prs]gel/D= $args{"stype"} =~ /[prs]gel/
ABCDresult
0XXX0
10000
11XX1
101X1
10011
359 ( $args{type} eq 'terra' )
360 && ( ( $args{lbase} =~ /[prs]gel/ )
361 || ( $args{ltype} =~ /[prs]gel/ )
362 || $args{stype} =~ /[prs]gel/ )
363 )
364 {
365 0 ▶ $args{freq} ||= 2;
Condition0%0/2
$args{"freq"} ||= 2
l!l
00
MC/DC0%0/1
$args{"freq"} ||= 2
$args{"freq"}
Truth table0%0/2
A
A= $args{"freq"}
Aresult
11
00
366 0 ▶ $args{displace} ||= .125;
Condition0%0/2
$args{"displace"} ||= "0.125"
l!l
00
MC/DC0%0/1
$args{"displace"} ||= "0.125"
$args{"displace"}
Truth table0%0/2
A
A= $args{"displace"}
Aresult
11
00
367 ▶ } elsif (
Condition44%4/9
$args{"type"} eq "terra" and $args{"lbase"} eq "gel" || $args{"ltype"} eq "gel" || $args{"stype"} eq "gel"
!ll&&!rl&&r
3810
$args{"lbase"} eq "gel" or $args{"ltype"} eq "gel" or $args{"stype"} eq "gel"
l!l&&r!l&&!r
001
$args{"lbase"} eq "gel" or $args{"ltype"} eq "gel"
l!l&&r!l&&!r
001
MC/DC0%0/4
$args{"type"} eq "terra" and $args{"lbase"} eq "gel" || $args{"ltype"} eq "gel" || $args{"stype"} eq "gel"
$args{"type"} eq "terra" $args{"lbase"} eq "gel" $args{"ltype"} eq "gel" $args{"stype"} eq "gel"
Truth table40%2/5
A and B or C or D
A= $args{"type"} eq "terra"B= $args{"lbase"} eq "gel"C= $args{"ltype"} eq "gel"D= $args{"stype"} eq "gel"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
368 ( $args{type} eq 'terra' )
369 && ( ( $args{lbase} eq 'gel' )
370 || ( $args{ltype} eq 'gel' )
371 || $args{stype} eq 'gel' )
372 )
373 {
374 0 ▶ $args{freq} ||= 4;
Condition0%0/2
$args{"freq"} ||= 4
l!l
00
MC/DC0%0/1
$args{"freq"} ||= 4
$args{"freq"}
Truth table0%0/2
A
A= $args{"freq"}
Aresult
11
00
375 0 ▶ $args{displace} ||= .5;
Condition0%0/2
$args{"displace"} ||= "0.5"
l!l
00
MC/DC0%0/1
$args{"displace"} ||= "0.5"
$args{"displace"}
Truth table0%0/2
A
A= $args{"displace"}
Aresult
11
00
376 }
377  
378 39 ▶ my $format = $args{format} || $DEFAULT_FORMAT;
Condition33%1/3
$args{'format'} || $Math::Fractal::Noisemaker::DEFAULT_FORMAT
l!l&&r!l&&!r
0390
MC/DC0%0/2
$args{'format'} || $Math::Fractal::Noisemaker::DEFAULT_FORMAT
$args{'format'} $Math::Fractal::Noisemaker::DEFAULT_FORMAT
Truth table33%1/3
A || B
A= $args{'format'}B= $Math::Fractal::Noisemaker::DEFAULT_FORMAT
ABresult
1X1
011
000
379  
380 39 ▶ if ( !$Imager::formats{$format} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Imager::formats{$format}) 0 39 39
381 0 my $formats = join( ",", sort keys %Imager::formats );
382  
383 0 usage("Unsupported format: $format (choose: $formats)");
384 }
385  
386 39 ▶ $args{out} ||= join(".", $args{type}, $format);
Condition66%2/3
$args{"out"} ||= join(".", $args{"type"}, $format)
l!l&&r!l&&!r
1380
MC/DC0%0/2
$args{"out"} ||= join(".", $args{"type"}, $format)
$args{"out"} join(".", $args{"type"}, $format)
Truth table66%2/3
A ||= B
A= $args{"out"}B= join(".", $args{"type"}, $format)
ABresult
1X1
011
000
387  
388 39 ▶ if ( $args{outdir} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"outdir"}) 39 0 39
389 39 ▶ usage("outdir does not exist") if !-e $args{outdir};
Branch: 1 branch
BranchTrueFalseTotal
unless -e $args{"outdir"} 0 39 39
390  
391 39 $args{out} = join( "/", $args{outdir}, $args{out} );
392 }
393  
394 39 ▶ if ( $args{upsample} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"upsample"}) 39 0 39
395 39 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
3900
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
396 39 $args{len} /= 2;
397 }
398  
399 39 my $grid;
400  
401 39 for my $type (@NOISE_TYPES) {
402 754 ▶ if ( $args{type} eq $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"type"} eq $type) 39 715 754
403 39 my $sub;
404  
405 39 do {
406 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
407 39 $sub = \&{"Math::Fractal::Noisemaker::$type"};
408 };
409  
410 39 $grid = &$sub(%args);
411 39 last;
412 }
413 }
414  
415 39 ▶ if ( !$grid ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($grid) 0 39 39
416 0 usage("Unknown noise type '$args{type}' specified");
417 }
418  
419 39 ▶ if ( $args{refract} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"refract"}) 0 39 39
420 0 $grid = refract( $grid, %args );
421 }
422  
423 39 ▶ if ( defined($args{xscale}) || defined($args{yscale}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"xscale"} or defined $args{"yscale"}) 0 39 39
Condition33%1/3
defined $args{"xscale"} or defined $args{"yscale"}
l!l&&r!l&&!r
0039
MC/DC0%0/2
defined $args{"xscale"} or defined $args{"yscale"}
defined $args{"xscale"} defined $args{"yscale"}
Truth table33%1/3
A or B
A= defined $args{"xscale"}B= defined $args{"yscale"}
ABresult
1X1
011
000
424 0 $grid = stretch($grid, %args);
425 }
426  
427 39 ▶ if ( $args{sphere} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"sphere"}) 0 39 39
428 0 %args = defaultArgs(%args);
429  
430 0 $grid = spheremap( $grid, %args );
431 }
432  
433 39 ▶ if ( $args{delta} || $args{chiral} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"delta"} or $args{"chiral"}) 0 39 39
Condition33%1/3
$args{"delta"} or $args{"chiral"}
l!l&&r!l&&!r
0039
MC/DC0%0/2
$args{"delta"} or $args{"chiral"}
$args{"delta"} $args{"chiral"}
Truth table33%1/3
A or B
A= $args{"delta"}B= $args{"chiral"}
ABresult
1X1
011
000
434 0 my $grid2;
435  
436 0 for my $type (@NOISE_TYPES) {
437 0 ▶ if ( $args{type} eq $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"type"} eq $type) 0 0 0
438 0 my $sub;
439  
440 0 do {
441 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
442 0 $sub = \&{"Math::Fractal::Noisemaker::$type"};
443 };
444  
445 0 $grid2 = &$sub(%args);
446 0 last;
447 }
448 }
449  
450 0 ▶ if ( $args{delta} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'delta'}) { } 0 0 0
451 0 $grid = delta( $grid, $grid2, %args );
452 } else {
453 0 $grid = chiral( $grid, $grid2, %args );
454 }
455 }
456  
457 39 ▶ if ( $args{stereo} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"stereo"}) 0 39 39
458 0 $grid = stereo( $grid, %args );
459 }
460  
461 39 ▶ if ( $args{upsample} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"upsample"}) 39 0 39
462 39 $args{len} *= 2;
463 39 $grid = grow($grid, %args);
464 }
465  
466 39 my $img;
467  
468 39 $img = img( $grid, %args);
469  
470 39 ▶ $img->write( file => $args{out} ) || die $img->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$img->write("file", $args{"out"}) or die $img->errstr 39 0 39
471  
472 39 ▶ print "Saved file to $args{out}\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 39 39
473  
474 39 return($img, $args{out});
475 }
476  
477 338 ▶sub defaultArgs {
Subroutine defaultArgs: called CC=14 SCAR=27.5
Pod undocumented
478 338 my %args = @_;
479  
480 338 ▶ $args{bias} = $DEFAULT_BIAS if !defined $args{bias};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"bias"} 129 209 338
481  
482 338 ▶ $args{gap} ||= $DEFAULT_GAP;
Condition66%2/3
$args{"gap"} ||= $Math::Fractal::Noisemaker::DEFAULT_GAP
l!l&&r!l&&!r
120326
MC/DC50%1/2
$args{"gap"} ||= $Math::Fractal::Noisemaker::DEFAULT_GAP
$args{"gap"} $Math::Fractal::Noisemaker::DEFAULT_GAP
Truth table66%2/3
A ||= B
A= $args{"gap"}B= $Math::Fractal::Noisemaker::DEFAULT_GAP
ABresult
1X1
011
000
483 338 ▶ $args{type} ||= $DEFAULT_TYPE;
Condition66%2/3
$args{"type"} ||= $Math::Fractal::Noisemaker::DEFAULT_TYPE
l!l&&r!l&&!r
32990
MC/DC0%0/2
$args{"type"} ||= $Math::Fractal::Noisemaker::DEFAULT_TYPE
$args{"type"} $Math::Fractal::Noisemaker::DEFAULT_TYPE
Truth table66%2/3
A ||= B
A= $args{"type"}B= $Math::Fractal::Noisemaker::DEFAULT_TYPE
ABresult
1X1
011
000
484 338 ▶ $args{stype} ||= $DEFAULT_SLICE_TYPE;
Condition66%2/3
$args{"stype"} ||= $Math::Fractal::Noisemaker::DEFAULT_SLICE_TYPE
l!l&&r!l&&!r
32990
MC/DC0%0/2
$args{"stype"} ||= $Math::Fractal::Noisemaker::DEFAULT_SLICE_TYPE
$args{"stype"} $Math::Fractal::Noisemaker::DEFAULT_SLICE_TYPE
Truth table66%2/3
A ||= B
A= $args{"stype"}B= $Math::Fractal::Noisemaker::DEFAULT_SLICE_TYPE
ABresult
1X1
011
000
485 338 ▶ $args{lbase} ||= $DEFAULT_TERRAIN_BASE;
Condition66%2/3
$args{"lbase"} ||= $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_BASE
l!l&&r!l&&!r
32990
MC/DC0%0/2
$args{"lbase"} ||= $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_BASE
$args{"lbase"} $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_BASE
Truth table66%2/3
A ||= B
A= $args{"lbase"}B= $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_BASE
ABresult
1X1
011
000
486 338 ▶ $args{ltype} ||= $DEFAULT_TERRAIN_SLICE;
Condition66%2/3
$args{"ltype"} ||= $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_SLICE
l!l&&r!l&&!r
32990
MC/DC0%0/2
$args{"ltype"} ||= $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_SLICE
$args{"ltype"} $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_SLICE
Truth table66%2/3
A ||= B
A= $args{"ltype"}B= $Math::Fractal::Noisemaker::DEFAULT_TERRAIN_SLICE
ABresult
1X1
011
000
487 338 ▶ $args{freq} ||= $DEFAULT_FREQ;
Condition66%2/3
$args{"freq"} ||= $Math::Fractal::Noisemaker::DEFAULT_FREQ
l!l&&r!l&&!r
2321060
MC/DC0%0/2
$args{"freq"} ||= $Math::Fractal::Noisemaker::DEFAULT_FREQ
$args{"freq"} $Math::Fractal::Noisemaker::DEFAULT_FREQ
Truth table66%2/3
A ||= B
A= $args{"freq"}B= $Math::Fractal::Noisemaker::DEFAULT_FREQ
ABresult
1X1
011
000
488 338 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
33800
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
489 338 ▶ $args{octaves} ||= $DEFAULT_OCTAVES;
Condition66%2/3
$args{"octaves"} ||= $Math::Fractal::Noisemaker::DEFAULT_OCTAVES
l!l&&r!l&&!r
2001380
MC/DC0%0/2
$args{"octaves"} ||= $Math::Fractal::Noisemaker::DEFAULT_OCTAVES
$args{"octaves"} $Math::Fractal::Noisemaker::DEFAULT_OCTAVES
Truth table66%2/3
A ||= B
A= $args{"octaves"}B= $Math::Fractal::Noisemaker::DEFAULT_OCTAVES
ABresult
1X1
011
000
490 338 ▶ $args{persist} ||= $DEFAULT_PERSIST;
Condition66%2/3
$args{"persist"} ||= $Math::Fractal::Noisemaker::DEFAULT_PERSIST
l!l&&r!l&&!r
1981400
MC/DC0%0/2
$args{"persist"} ||= $Math::Fractal::Noisemaker::DEFAULT_PERSIST
$args{"persist"} $Math::Fractal::Noisemaker::DEFAULT_PERSIST
Truth table66%2/3
A ||= B
A= $args{"persist"}B= $Math::Fractal::Noisemaker::DEFAULT_PERSIST
ABresult
1X1
011
000
491  
492 338 ▶ $args{auto} = 1 if !defined( $args{auto} ) && $args{type} ne 'fern';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $args{"auto"} and $args{"type"} ne "fern" 137 201 338
Condition100%3/3
not defined $args{"auto"} and $args{"type"} ne "fern"
!ll&&!rl&&r
1965137
MC/DC100%2/2
not defined $args{"auto"} and $args{"type"} ne "fern"
not defined $args{"auto"} $args{"type"} ne "fern"
Truth table100%3/3
not(A) and B
A= not defined $args{"auto"}B= $args{"type"} ne "fern"
ABresult
0X0
100
111
493  
494 338 ▶ $args{amp} = $DEFAULT_AMP if !defined $args{amp};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"amp"} 120 218 338
495  
496 338 return %args;
497 }
498  
499 39 ▶sub img {
Subroutine img: called CC=28 SCAR=42.1
Pod undocumented
500 39 my $grid = shift;
501 39 my %args = defaultArgs(@_);
502  
503 39 ▶ print "Generating image...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 39 39
504  
505 39 my $len = scalar( @{$grid} );
506  
507 39 ▶ my $stretch = $args{sphere} ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$args{'sphere'} ? : 0 39 39
508  
509 ###
510 ### Save the image
511 ###
512 39 my %imagerArgs = (
513 xsize => $len*$stretch,
514 ysize => $len,
515 );
516  
517 39 ▶ $imagerArgs{channels} = 1 if !$args{clut};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"clut"} 39 0 39
518  
519 39 my $img = Imager->new(%imagerArgs);
520  
521 ###
522 ### Scale pixel values to sane levels
523 ###
524 39 my ( $min, $max, $range );
525  
526 39 ▶ if ( $args{auto} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"auto"}) 38 1 39
527 38 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 1216 38 1254
528 1216 my $column = $grid->[$x];
529  
530 1216 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 38912 1216 40128
531 38912 my $gray = $column->get($y);
532  
533 38912 ▶ $min = $gray if !defined $min;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $min 38 38874 38912
534 38912 ▶ $max = $gray if !defined $max;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max 38 38874 38912
535  
536 38912 ▶ $min = $gray if $gray < $min;
Branch: 1 branch
BranchTrueFalseTotal
if $gray < $min 414 38498 38912
537 38912 ▶ $max = $gray if $gray > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $gray > $max 325 38587 38912
538 }
539 }
540  
541 38 $range = $max - $min;
542 }
543  
544 39 my $scaledGrid = [];
545  
546 39 ▶ for ( my $x = 0 ; $x < $len*$stretch ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len * $stretch) 1248 39 1287
547 1248 my $scaledColumn = $COLUMN_CLASS->new($len);
548  
549 1248 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 39936 1248 41184
550 # my $gray = $column->get($y);
551 39936 my $gray = noise($grid,$x/$stretch,$y);
552  
553 39936 my $scaled;
554  
555 39936 ▶ if ( $args{auto} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'auto'}) { } 38912 1024 39936
556 38912 ▶ $scaled = $range ? ( ( $gray - $min ) / $range ) * $MAX_COLOR : 0;
Branch: 1 branch
BranchTrueFalseTotal
$range ? : 37888 1024 38912
557 } else {
558 1024 $scaled = clamp($gray);
559 }
560  
561 39936 $scaledColumn->set( $y, $scaled );
562 }
563  
564 1248 $scaledGrid->[$x] = $scaledColumn;
565 }
566  
567 39 ▶ if ( $args{clut} && $args{clutdir} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'clut'} and $args{'clutdir'}) { } 0 39 39
elsif ($args{'clut'}) { } 0 39 39
Condition33%1/3
$args{"clut"} and $args{"clutdir"}
!ll&&!rl&&r
3900
MC/DC0%0/2
$args{"clut"} and $args{"clutdir"}
$args{"clut"} $args{"clutdir"}
Truth table33%1/3
A and B
A= $args{"clut"}B= $args{"clutdir"}
ABresult
0X0
100
111
568 0 $img = vertclut( $scaledGrid, %args );
569 } elsif ( $args{clut} ) {
570 0 $img = hypoclut( $scaledGrid, %args );
571 } else {
572 39 ▶ if ( $args{emboss} && !$args{shadow} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"emboss"} and not $args{"shadow"}) 0 39 39
Condition33%1/3
$args{"emboss"} and not $args{"shadow"}
!ll&&!rl&&r
3900
MC/DC0%0/2
$args{"emboss"} and not $args{"shadow"}
$args{"emboss"} not $args{"shadow"}
Truth table33%1/3
A and not(B)
A= $args{"emboss"}B= not $args{"shadow"}
ABresult
0X0
100
111
573 0 $scaledGrid = emboss( $scaledGrid, %args );
574 0 $scaledGrid = smooth( $scaledGrid, %args );
575 # $scaledGrid = glow( $scaledGrid, %args );
576 0 $scaledGrid = densemap( $scaledGrid );
577 }
578  
579 39 ▶ for ( my $x = 0 ; $x < $len*$stretch; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len * $stretch) 1248 39 1287
580 1248 my $column = $scaledGrid->[$x];
581  
582 1248 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 39936 1248 41184
583 39936 my $gray = $column->get($y);
584 39936 $img->setpixel(
585 x => $x,
586 y => $y,
587 color => [ $gray, $gray, $gray ],
588 );
589 }
590 1248 printRow($column);
591 }
592 }
593  
594 39 ▶ if ( $args{shadow} && !$args{emboss} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"shadow"} and not $args{"emboss"}) 0 39 39
Condition33%1/3
$args{"shadow"} and not $args{"emboss"}
!ll&&!rl&&r
3900
MC/DC0%0/2
$args{"shadow"} and not $args{"emboss"}
$args{"shadow"} not $args{"emboss"}
Truth table33%1/3
A and not(B)
A= $args{"shadow"}B= not $args{"emboss"}
ABresult
0X0
100
111
595 0 my $embossed = emboss( $scaledGrid, %args );
596  
597 # $embossed = smooth( $embossed, %args );
598 # $embossed = glow( $embossed, %args );
599 0 $embossed = densemap( $embossed );
600  
601 0 my $shadow = $args{shadow};
602  
603 0 ▶ for ( my $x = 0 ; $x < $len*$stretch ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len * $stretch) 0 0 0
604 0 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 0 0 0
605 0 my $color = $img->getpixel( x => $x, y => $y );
606 0 my ( $r, $g, $b ) = $color->rgba;
607  
608 0 my $embColor = noise($embossed,$x/$stretch,$y/$stretch) / $MAX_COLOR;
609  
610 0 ▶ if ( $embColor < .65 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($embColor < 0.65) { } 0 0 0
611 0 my $amt = ( 1 - ( $embColor / .65 ) ) * $shadow;
612  
613 0 $r = interp( $r, 0, $amt );
614 0 $g = interp( $g, 0, $amt );
615 0 $b = interp( $b, 0, $amt );
616 } else {
617 0 my $amt = ( ( ( $embColor - .65 ) / .65 ) ) * $shadow;
618  
619 0 $r = interp( $r, $MAX_COLOR, $amt );
620 0 $g = interp( $g, $MAX_COLOR, $amt );
621 0 $b = interp( $b, $MAX_COLOR, $amt );
622 }
623  
624 0 $img->setpixel(
625 x => $x,
626 y => $y,
627 color => [ $r, $g, $b ]
628 );
629 }
630 0 ▶ printRow( $embossed->[$x/2] ) if $x % 2 == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $x % 2 == 0 0 0 0
631 }
632 }
633  
634 39 return $img;
635 }
636  
637 114 ▶sub grow {
Subroutine grow: called CC=2 SCAR=7.2
Pod documented
638 114 ▶ $GROW_FN ||= \&grow_interp;
Condition50%1/2
$GROW_FN ||= \&Math::Fractal::Noisemaker::grow_interp
l!l
1140
MC/DC0%0/1
$GROW_FN ||= \&Math::Fractal::Noisemaker::grow_interp
$GROW_FN
Truth table50%1/2
A
A= $GROW_FN
Aresult
11
00
639  
640 114 &$GROW_FN(@_);
641 }
642  
643 #
644 # Artificially stretch noise along either axis
645 #
646 0 ▶sub stretch {
Subroutine stretch: not called CC=5 SCAR=34.0
Pod undocumented
647 0 my $noise = shift;
648 0 my %args = defaultArgs(@_);
649  
650 0 my $len = $args{len};
651  
652 0 my $grid = grid(%args);
653  
654 0 ▶ my $xscale = $args{xscale} || 1;
Condition0%0/2
$args{'xscale'} || 1
l!l
00
MC/DC0%0/1
$args{'xscale'} || 1
$args{'xscale'}
Truth table0%0/2
A
A= $args{'xscale'}
Aresult
11
00
655 0 ▶ my $yscale = $args{yscale} || 1;
Condition0%0/2
$args{'yscale'} || 1
l!l
00
MC/DC0%0/1
$args{'yscale'} || 1
$args{'yscale'}
Truth table0%0/2
A
A= $args{'yscale'}
Aresult
11
00
656  
657 0 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 0 0 0
658 0 my $column = $grid->[$x];
659  
660 0 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 0 0 0
661 0 my $thisX = $x * $xscale;
662 0 my $thisY = $y * $yscale;
663  
664 0 $column->set( $y, noise( $noise, $thisX, $thisY ) );
665 }
666 }
667  
668 0 return $grid;
669 }
670  
671 #
672 # Grow the image using the interpolation function
673 #
674 114 ▶sub grow_interp {
Subroutine grow_interp: called CC=4 SCAR=13.9
Pod undocumented
675 114 my $noise = shift;
676 114 my %args = @_;
677  
678 114 my $wantLength = $args{len};
679 114 my $haveLength = scalar( @{$noise} );
680  
681 114 my $scale = $wantLength / $haveLength;
682  
683 114 my $grid = grid(%args);
684  
685 114 my $smooth = $args{smooth};
686  
687 114 ▶ for ( my $x = 0 ; $x < $wantLength ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $wantLength) 2520 114 2634
688 2520 my $column = $grid->[$x];
689  
690 2520 ▶ for ( my $y = 0 ; $y < $wantLength ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $wantLength) 63168 2520 65688
691 63168 my $thisX = $x / $scale;
692 63168 my $thisY = $y / $scale;
693  
694 63168 ▶ if ( !$smooth ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($smooth) 3136 60032 63168
695 3136 $thisX = int($thisX);
696 3136 $thisY = int($thisY);
697 }
698  
699 63168 $column->set( $y, noise( $noise, $thisX, $thisY ) );
700 }
701 }
702  
703 114 return $grid;
704 }
705  
706 #
707 # Grow the image by resampling neighborhood pixels
708 #
709 0 ▶sub grow_gaussian {
Subroutine grow_gaussian: not called CC=5 SCAR=34.0
Pod undocumented
710 0 my $noise = shift;
711 0 my %args = @_;
712  
713 0 my $grid = $noise;
714  
715 0 my $wantLength = $args{len};
716 0 my $haveLength = scalar( @{$noise} );
717  
718 0 ▶ until ( $haveLength >= $wantLength ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($haveLength >= $wantLength) 0 0 0
719 0 my $grown = [];
720  
721 0 ▶ for ( my $x = 0 ; $x < $haveLength * 2 ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $haveLength * 2) 0 0 0
722 0 my $column = $grid->[ $x / 2 ];
723 0 my $grownColumn = $COLUMN_CLASS->new( $haveLength * 2 );
724  
725 0 ▶ for ( my $y = 0 ; $y < $haveLength * 2 ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $haveLength * 2) 0 0 0
726 0 $grownColumn->set( $y, $column->get( $y / 2 ) );
727 }
728  
729 0 $grown->[$x] = $grownColumn;
730 }
731  
732 0 ▶ $grid = $args{smooth} ? smooth( $grown, %args ) : $grown;
Branch: 1 branch
BranchTrueFalseTotal
$args{'smooth'} ? : 0 0 0
733  
734 0 $haveLength *= 2;
735 }
736  
737 0 return $grid;
738 }
739  
740 15 ▶sub shrink {
Subroutine shrink: called CC=4 SCAR=13.9
Pod undocumented
741 15 my $noise = shift;
742 15 my %args = @_;
743  
744 15 my $grid = $noise;
745  
746 15 my $wantLength = $args{len};
747 15 my $haveXLen = scalar @$noise;
748 15 my $haveYLen = $noise->[0]->len();
749  
750 15 ▶ until ( $haveXLen <= $wantLength ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($haveXLen <= $wantLength) 15 15 30
751 15 my $shrunk = [];
752  
753 15 ▶ for ( my $x = 0 ; $x < $haveXLen / 2 ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $haveXLen / 2) 160 15 175
754 160 my $shrunkColumn = $COLUMN_CLASS->new( $haveYLen / 2 );
755  
756 160 ▶ for ( my $y = 0 ; $y < $haveYLen / 2 ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $haveYLen / 2) 1920 160 2080
757 1920 my $value = noise($grid, $x*2, $y*2);
758 1920 $value += noise($grid, ($x*2)+1, $y*2);
759 1920 $value += noise($grid, $x*2, ($y*2)+1);
760 1920 $value += noise($grid, ($x*2)+1, ($y*2)+1);
761  
762 1920 $shrunkColumn->set( $y, $value / 4 );
763 }
764  
765 160 $shrunk->[$x] = $shrunkColumn;
766 }
767  
768 15 $haveXLen /= 2;
769  
770 15 $grid = $shrunk;
771 }
772  
773 15 return $grid;
774 }
775  
776 197 ▶sub grid {
Subroutine grid: called CC=3 SCAR=11.0
Pod undocumented
777 197 my %args = defaultArgs(@_);
778  
779 197 my $grid = [];
780  
781 197 my $len = $args{len};
782  
783 197 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 3628 197 3825
784 3628 my @row;
785  
786 3628 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 83264 3628 86892
787 83264 $row[$y] = ( $args{bias} / 1 ) * $MAX_COLOR;
788 }
789  
790 3628 $grid->[$x] = $COLUMN_CLASS->new( $len, \@row );
791 }
792  
793 197 return $grid;
794 }
795  
796 3 ▶sub infile {
Subroutine infile: called CC=6 SCAR=18.0
Pod documented
797 3 my %args = defaultArgs(@_);
798  
799 3 ▶ print "Loading image...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 3 3
800  
801 3 my $len = $args{len};
802  
803 3 my $img = Imager->new;
804  
805 3 ▶ $img->read( file => $args{in} ) || die $img->errstr();
Branch: 1 branch
BranchTrueFalseTotal
$img->read("file", $args{"in"}) or die $img->errstr 3 0 3
806  
807 3 my $width = $img->getwidth();
808 3 my $height = $img->getheight();
809  
810 3 ▶ my $tempSize = ( $width > $height ) ? $width : $height;
Branch: 1 branch
BranchTrueFalseTotal
$width > $height ? : 0 3 3
811 3 my $tempGrid = grid(%args, len => $tempSize);
812  
813 3 ▶ for ( my $x = 0 ; $x < $tempSize ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $tempSize) 96 3 99
814 96 my $column = $tempGrid->[$x];
815  
816 96 ▶ for ( my $y = 0 ; $y < $tempSize ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $tempSize) 3072 96 3168
817 3072 my $color = $img->getpixel(
818 x => ( $x / ( $tempSize / 1 ) ) * ( $width - 1 ),
819 y => ( $y / ( $tempSize - 1 ) ) * ( $height - 1 )
820 );
821  
822 3072 my ( $r, $g, $b ) = $color->rgba;
823  
824 3072 $column->set( $y, ( $r + $g + $b ) / 3 );
825 }
826 }
827  
828 3 return grow($tempGrid, %args);
829 }
830  
831 1 ▶sub intile {
Subroutine intile: called CC=1 SCAR=0.0
Pod undocumented
832 1 my $grid = infile(@_);
833  
834 1 return tile( $grid, @_ );
835 }
836  
837 1 ▶sub gradient {
Subroutine gradient: called CC=8 SCAR=21.1
Pod documented
838 1 my %args = @_;
839  
840 1 ▶ print "Generating gradient noise...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 1 1
841  
842 1 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
100
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
843 1 ▶ $args{freq} = $args{len} if !defined $args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"freq"} 1 0 1
844  
845 1 %args = defaultArgs(%args);
846  
847 1 my $freq = $args{freq};
848  
849 1 my $grid = grid( %args, len => $freq );
850  
851 1 ▶ $args{amp} = $DEFAULT_AMP if !defined $args{amp};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"amp"} 0 1 1
852  
853 1 my $ampVal = $args{amp} * $MAX_COLOR;
854 1 my $biasVal = $args{bias} * $MAX_COLOR;
855  
856 1 ▶ spamConsole(%args) if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 1 1
857  
858 1 my $amp = $args{amp};
859  
860 1 ▶ for ( my $x = 0 ; $x < $freq ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $freq) 16 1 17
861 16 my $column = $grid->[$x];
862  
863 16 my $thisX = $x / $freq;
864  
865 16 ▶ for ( my $y = 0 ; $y < $freq ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $freq) 256 16 272
866  
867 # my $randAmp = rand($ampVal);
868  
869 256 my $thisY = $y / $freq;
870  
871 256 my $xval = $NUMS[ $thisX * 256 ] + $NUMS[ $thisY * 256 ];
872 256 my $yval = $NUMS[ $thisY * 256 ] + $NUMS[ $xval % 256 ];
873 256 $xval = ( $NUMS[ $xval % 256 ] / 255 ) * $amp;
874 256 $yval = ( $NUMS[ $yval % 256 ] / 255 ) * $amp;
875  
876 256 my $randAmp = interp( $xval, $yval, .5 );
877  
878 256 $column->set( $y, $randAmp + $biasVal );
879 }
880  
881 16 printRow($column);
882 }
883  
884 1 return grow( $grid, %args );
885 }
886  
887 2 ▶sub worley {
Subroutine worley: called CC=18 SCAR=30.5
Pod documented
888 2 my %args = @_;
889 2 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
200
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
890 2 ▶ $args{freq} = 32 if !defined $args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"freq"} 1 1 2
891  
892 2 %args = defaultArgs(%args);
893  
894 2 my $freq = $args{freq};
895 2 my $len = $args{len};
896 2 my $amp = $args{amp};
897 2 my $nth = $args{nth};
898 2 my $cell = $args{cell};
899 2 ▶ my $distType = $args{dist} || 0;
Condition100%2/2
$args{'dist'} || 0
l!l
11
MC/DC100%1/1
$args{'dist'} || 0
$args{'dist'}
Truth table100%2/2
A
A= $args{'dist'}
Aresult
11
00
900  
901 2 my $grid = grid(%args);
902  
903 2 my @points;
904 2 ▶ if ( $args{points} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'points'}) { } 0 2 2
905 0 @points = @{$args{points}};
906 } else {
907 2 ▶ for ( my $i = 0 ; $i < $freq ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $freq) 40 2 42
908 40 my $x = rand($len);
909 40 my $y = rand($len);
910 40 my $white = $NUMS[$i];
911  
912 40 push @points, [ $x, $y, $white ];
913 }
914 }
915  
916 2 ▶ if ( !defined $nth ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nth) 2 0 2
917 2 $nth = sqrt(scalar @points);
918 }
919  
920 # render as shaded distance or solid cells? normalize the index:
921 2 ▶ $cell = $cell ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$cell ? : 0 2 2
922  
923 2 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 32 2 34
924 32 my $column = $grid->[$x];
925  
926 32 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 512 32 544
927 512 my @thisDist;
928 512 for my $point (@points) {
929 10240 ▶ if ( $distType == 0 || $distType == 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distType == 0 or $distType == 3) 10240 0 10240
Condition66%2/3
$distType == 0 or $distType == 3
l!l&&r!l&&!r
819220480
MC/DC0%0/2
$distType == 0 or $distType == 3
$distType == 0 $distType == 3
Truth table66%2/3
A or B
A= $distType == 0B= $distType == 3
ABresult
1X1
011
000
930 10240 my $xdist = abs( $x - $point->[0] );
931 10240 my $ydist = abs( $y - $point->[1] );
932 10240 push @thisDist, [ sqrt( $xdist**2 + $ydist**2 ), $point->[2] ];
933 }
934 10240 ▶ if ( $distType == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distType == 1) 0 10240 10240
935 0 push @thisDist, [
936 abs( $x - $point->[0] ) + abs( $y - $point->[1] ),
937 $point->[2]
938 ];
939 }
940 10240 ▶ if ( $distType == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distType == 2) 0 10240 10240
941 0 my $xdist = abs( $x - $point->[0] );
942 0 my $ydist = abs( $y - $point->[1] );
943 0 ▶ my $thisDist = ( $xdist > $ydist ) ? $xdist : $ydist;
Branch: 1 branch
BranchTrueFalseTotal
$xdist > $ydist ? : 0 0 0
944 0 push @thisDist, [ $thisDist, $point->[2] ];
945 }
946 }
947 512 ▶ if ( $distType == 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distType == 3) { } 256 256 512
948 256 my @foo;
949 256 my $i = 0;
950 256 for (@thisDist) {
951 2048 $i++;
952 2048 push @foo, [
953 abs( $_->[0] - ( $NUMS[$i] / $MAX_COLOR ) * $len ), $_->[1]
954 ];
955 }
956  
957 # push @thisDist, @foo;
958 256 @thisDist = sort { $a->[0] <=> $b->[0] } @foo;
959 } else {
960 256 @thisDist = sort { $a->[0] <=> $b->[0] } @thisDist;
961 }
962  
963 512 my $val = $thisDist[$nth]->[$cell];
964 512 $column->set( $y, $val);
965 }
966 }
967  
968 2 $grid = densemap($grid, $args{invert});
969  
970 2 return tile( $grid, %args );
971 }
972  
973 45 ▶sub white {
Subroutine white: called CC=11 SCAR=24.1
Pod documented
974 45 my %args = @_;
975  
976 45 ▶ print "Generating white noise...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 45 45
977  
978 45 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
4500
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
979 45 ▶ $args{freq} = $args{len} if !defined $args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"freq"} 2 43 45
980  
981 45 %args = defaultArgs(%args);
982  
983 45 my $freq = $args{freq};
984 45 my $gap = $args{gap};
985  
986 45 my $grid = grid( %args, len => $freq );
987  
988 45 ▶ $args{amp} = $DEFAULT_AMP if !defined $args{amp};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"amp"} 0 45 45
989  
990 45 my $ampVal = $args{amp} * $MAX_COLOR;
991 45 my $biasVal = $args{bias} * $MAX_COLOR;
992  
993 45 ▶ spamConsole(%args) if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 45 45
994  
995 45 my $stars = $args{stars};
996  
997 # my $offX = rand($freq);
998 # my $offY = rand($freq);
999 45 my $offX = 0;
1000 45 my $offY = 0;
1001  
1002 45 ▶ for ( my $x = 0 ; $x < $freq ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $freq) 400 45 445
1003 400 my $thisX = ( $x + $offX ) % $freq;
1004 400 my $column = $grid->[$thisX];
1005  
1006 400 ▶ for ( my $y = 0 ; $y < $freq ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $freq) 4848 400 5248
1007 4848 my $thisY = ( $y + $offY ) % $freq;
1008  
1009 4848 ▶ if ( rand() < $gap ) {
Branch: 1 branch
BranchTrueFalseTotal
if (rand() < $gap) 763 4085 4848
1010 763 $column->set( $thisY, 0 );
1011 763 next;
1012 }
1013  
1014 4085 my $randAmp = rand($ampVal);
1015  
1016 4085 ▶ if ( !$stars ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stars) 4080 5 4085
1017 4080 ▶ $randAmp *= -1 if rand(1) >= .5;
Branch: 1 branch
BranchTrueFalseTotal
if rand 1 >= "0.5" 2025 2055 4080
1018 }
1019  
1020 4085 $column->set( $thisY, $randAmp + $biasVal );
1021 }
1022  
1023 400 printRow($column);
1024 }
1025  
1026 45 return grow( $grid, %args );
1027 }
1028  
1029 3 ▶sub stars {
Subroutine stars: called CC=5 SCAR=16.7
Pod documented
1030 3 my %args = @_;
1031  
1032 3 ▶ print "Generating stars...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 3 3
1033  
1034 3 $args{bias} = 0;
1035 3 ▶ $args{amp} ||= $DEFAULT_AMP;
Condition66%2/3
$args{"amp"} ||= $Math::Fractal::Noisemaker::DEFAULT_AMP
l!l&&r!l&&!r
120
MC/DC0%0/2
$args{"amp"} ||= $Math::Fractal::Noisemaker::DEFAULT_AMP
$args{"amp"} $Math::Fractal::Noisemaker::DEFAULT_AMP
Truth table66%2/3
A ||= B
A= $args{"amp"}B= $Math::Fractal::Noisemaker::DEFAULT_AMP
ABresult
1X1
011
000
1036 3 ▶ $args{gap} ||= .995;
Condition50%1/2
$args{"gap"} ||= "0.995"
l!l
03
MC/DC0%0/1
$args{"gap"} ||= "0.995"
$args{"gap"}
Truth table50%1/2
A
A= $args{"gap"}
Aresult
11
00
1037  
1038 3 my $grid = white( %args, stars => 1 );
1039  
1040 3 %args = defaultArgs(%args);
1041  
1042 3 ▶ return $args{smooth} ? smooth( $grid, %args ) : $grid;
Branch: 1 branch
BranchTrueFalseTotal
$args{'smooth'} ? : 3 0 3
1043 }
1044  
1045 1 ▶sub gel {
Subroutine gel: called CC=3 SCAR=11.2
Pod documented
1046 1 my %args = @_;
1047  
1048 1 ▶ print "Generating gel noise...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 1 1
1049  
1050 1 ▶ $args{displace} = $DEFAULT_DISPLACEMENT if !defined $args{displace};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"displace"} 1 0 1
1051  
1052 1 %args = defaultArgs(%args);
1053  
1054 1 my $grid = white(%args);
1055  
1056 1 return displace( $grid, %args );
1057 }
1058  
1059 4 ▶sub displace {
Subroutine displace: called CC=5 SCAR=16.1
Pod documented
1060 4 my $grid = shift;
1061 4 my %args = @_;
1062  
1063 4 ▶ print "Applying self-displacement...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 4 4
1064  
1065 4 my $out = [];
1066  
1067 4 my $length = $args{len};
1068 4 my $displace = $args{displace};
1069  
1070 4 ▶ $displace = .5 if !defined $displace;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $displace 0 4 4
1071  
1072 4 $displace =
1073 ( $displace / 1 ) * ( $length / $DEFAULT_LEN )
1074 ; # Same visual offset for diff size imgs
1075  
1076 4 $grid = smooth( $grid, %args );
1077  
1078 4 ▶ for ( my $x = 0 ; $x < $length ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $length) 64 4 68
1079 64 my $column = $COLUMN_CLASS->new($length);
1080  
1081 64 ▶ for ( my $y = 0 ; $y < $length ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $length) 1024 64 1088
1082 1024 my $tmpX = noise($grid, $x + $length/2, $y + $length/2);
1083 1024 my $displaceX = noise($grid, $tmpX, $y) * $displace;
1084  
1085 1024 my $tmpY = noise($grid, $x, $y);
1086 1024 my $displaceY = noise($grid, $x, $tmpY) * $displace;
1087  
1088 1024 $column->set( $y, noise( $grid, $displaceX, $displaceY ) );
1089 }
1090  
1091 64 $out->[$x] = $column;
1092 }
1093  
1094 4 return $out;
1095 }
1096  
1097 3 ▶sub square {
Subroutine square: called CC=18 SCAR=29.0
Pod documented
1098 3 my %args = defaultArgs(@_);
1099  
1100 3 ▶ print "Generating square noise...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 3 3
1101  
1102 3 my $freq = $args{freq};
1103 3 my $amp = $args{amp};
1104 3 my $bias = $args{bias};
1105 3 my $length = $args{len};
1106 3 my $persist = $args{persist};
1107  
1108 3 ▶ $amp = $DEFAULT_AMP if !defined $amp;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $amp 0 3 3
1109  
1110 3 ▶ my $grid = $args{grid} || white( %args, len => $freq * 2 );
Condition33%1/3
$args{'grid'} || white(%args, 'len', $freq * 2)
l!l&&r!l&&!r
030
MC/DC0%0/2
$args{'grid'} || white(%args, 'len', $freq * 2)
$args{'grid'} white(%args, 'len', $freq * 2)
Truth table33%1/3
A || B
A= $args{'grid'}B= white(%args, 'len', $freq * 2)
ABresult
1X1
011
000
1111 3 my $haveLength = scalar @$grid;
1112 3 my $baseOffset = $MAX_COLOR * $amp;
1113 3 ▶ $baseOffset = sqrt($baseOffset) if $args{grid};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"grid"} 0 3 3
1114  
1115 3 ▶ spamConsole(%args) if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 3 3
1116  
1117 3 ▶ until ( $haveLength >= $length ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($haveLength >= $length) 3 3 6
1118 3 my $grown = [];
1119  
1120 3 ▶ for ( my $x = 0 ; $x < $haveLength * 2 ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $haveLength * 2) 48 3 51
1121 48 $grown->[$x] = $COLUMN_CLASS->new( $haveLength * 2 );
1122 }
1123  
1124 3 ▶ for ( my $x = 0 ; $x < $haveLength ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $haveLength) 24 3 27
1125 24 my $thisX = $x * 2;
1126 24 my $column = $grid->[$x];
1127 24 my $grownColumn = $grown->[$thisX];
1128  
1129 24 ▶ for ( my $y = 0 ; $y < $haveLength ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $haveLength) 192 24 216
1130 192 my $thisY = $y * 2;
1131  
1132 192 my $offset = rand($baseOffset);
1133 192 ▶ $offset *= -1 if ( rand(1) >= .5 );
Branch: 1 branch
BranchTrueFalseTotal
if rand 1 >= "0.5" 86 106 192
1134  
1135 192 $grownColumn->set( $thisY, $column->get($y) + $offset );
1136 }
1137  
1138 24 $grown->[$thisX] = $grownColumn;
1139 }
1140  
1141 3 ▶ for ( my $x = 0 ; $x < $haveLength ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $haveLength) 24 3 27
1142 24 my $thisX = $x * 2;
1143 24 $thisX += 1;
1144  
1145 24 my $grownColumn = $grown->[$thisX];
1146  
1147 24 ▶ for ( my $y = 0 ; $y < $haveLength ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $haveLength) 192 24 216
1148 192 my $thisY = $y * 2;
1149 192 $thisY += 1;
1150  
1151 192 my $corners =
1152 ( noise( $grid, $x - 1, $y - 1 ) +
1153 noise( $grid, $x + 1, $y - 1 ) +
1154 noise( $grid, $x - 1, $y + 1 ) +
1155 noise( $grid, $x + 1, $y + 1 ) ) / 4;
1156  
1157 192 my $offset = rand($baseOffset);
1158 192 ▶ $offset *= -1 if ( rand(1) >= .5 );
Branch: 1 branch
BranchTrueFalseTotal
if rand 1 >= "0.5" 97 95 192
1159 192 $grownColumn->set( $thisY, $corners + $offset );
1160 }
1161 }
1162  
1163 3 $haveLength *= 2;
1164  
1165 3 $baseOffset *= $persist;
1166  
1167 3 ▶ for ( my $x = 0 ; $x < $haveLength ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $haveLength) 48 3 51
1168 48 my $base = ( $x + 1 ) % 2;
1169  
1170 48 my $grownColumn = $grown->[$x];
1171  
1172 48 ▶ for ( my $y = $base ; $y < $haveLength ; $y += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $haveLength) 384 48 432
1173 384 my $sides =
1174 ( noise( $grown, $x - 1, $y ) +
1175 noise( $grown, $x + 1, $y ) +
1176 noise( $grown, $x, $y - 1 ) +
1177 noise( $grown, $x, $y + 1 ) ) / 4;
1178  
1179 384 my $offset = rand($baseOffset);
1180 384 ▶ $offset *= -1 if ( rand(1) >= .5 );
Branch: 1 branch
BranchTrueFalseTotal
if rand 1 >= "0.5" 201 183 384
1181 384 $grownColumn->set( $y, $sides + $offset );
1182 }
1183 }
1184  
1185 3 ▶ $grid = $args{smooth} ? smooth( $grown, %args ) : $grown;
Branch: 1 branch
BranchTrueFalseTotal
$args{'smooth'} ? : 2 1 3
1186 }
1187  
1188 3 return $grid;
1189 }
1190  
1191 1 ▶sub sgel {
Subroutine sgel: called CC=3 SCAR=11.3
Pod documented
1192 1 my %args = defaultArgs(@_);
1193  
1194 1 ▶ $args{displace} = $DEFAULT_DISPLACEMENT if !defined $args{displace};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"displace"} 1 0 1
1195  
1196 1 ▶ print "Generating square gel noise...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 1 1
1197  
1198 1 my $grid = square(%args);
1199  
1200 1 return displace( $grid, %args );
1201 }
1202  
1203 14 ▶sub multires {
Subroutine multires: called CC=19 SCAR=29.5
Pod documented
1204 14 my %args = @_;
1205  
1206 14 ▶ print "Generating multi-res noise...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 14 14
1207  
1208 14 ▶ $args{amp} = $DEFAULT_AMP if !defined $args{amp};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"amp"} 3 11 14
1209  
1210 14 %args = defaultArgs(%args);
1211  
1212 14 $args{amp} *= $args{octaves};
1213  
1214 14 my $length = $args{len};
1215 14 my $amp = $args{amp};
1216 14 my $freq = $args{freq};
1217 14 my $bias = $args{bias};
1218 14 my $octaves = $args{octaves};
1219  
1220 14 my @layers;
1221  
1222 14 ▶ spamConsole(%args) if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 14 14
1223  
1224 14 ▶ for ( my $o = 0 ; $o < $octaves ; $o++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o < $octaves) 47 3 50
1225 47 ▶ last if $freq > $length;
Branch: 1 branch
BranchTrueFalseTotal
if $freq > $length 11 36 47
1226  
1227 36 ▶ print "Octave " . ( $o + 1 ) . " ... \n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 36 36
1228  
1229 36 my $generator;
1230  
1231 36 for my $type (@SIMPLE_TYPES) {
1232 1008 ▶ if ( $args{stype} eq $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"stype"} eq $type) 36 972 1008
1233 36 do {
1234 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1235 36 $generator = \&{"Math::Fractal::Noisemaker::$type"};
1236 };
1237 }
1238 }
1239  
1240 36 ▶ if ( !$generator ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($generator) 0 36 36
1241 0 usage("Unknown slice type '$args{stype}' specified");
1242 }
1243  
1244 36 push @layers,
1245 &$generator(
1246 %args,
1247 freq => $freq,
1248 amp => $amp,
1249 bias => $bias,
1250 len => $length,
1251 );
1252  
1253 36 $amp *= $args{persist};
1254 36 $freq *= 2;
1255 }
1256  
1257 #
1258 # Restore orig values
1259 #
1260 14 $amp = $args{amp};
1261 14 $freq = $args{freq};
1262  
1263 14 my $combined = [];
1264  
1265 14 my $zshift;
1266 14 ▶ if ( $args{ridged} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"ridged"}) 5 9 14
1267 5 ▶ $args{zshift} = $amp if !defined $args{zshift};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"zshift"} 1 4 5
1268 5 $zshift = $args{zshift} * $MAX_COLOR;
1269 }
1270  
1271 14 ▶ for ( my $x = 0 ; $x < $length ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $length) 256 14 270
1272  
1273 256 my $combinedColumn = $COLUMN_CLASS->new($length);
1274  
1275 256 ▶ for ( my $y = 0 ; $y < $length ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $length) 5120 256 5376
1276 5120 my $n;
1277 my $t;
1278  
1279 5120 ▶ for ( my $z = 0 ; $z < @layers ; $z++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($z < @layers) 13824 5120 18944
1280 13824 $n++;
1281  
1282 13824 my $gray = $layers[$z][$x]->get($y);
1283  
1284 13824 ▶ if ( $args{ridged} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'ridged'}) { } 2304 11520 13824
1285 2304 $t += abs($gray);
1286 } else {
1287 11520 $t += $gray;
1288 }
1289 }
1290  
1291 5120 ▶ if ( $n && $args{ridged} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($n and $args{'ridged'}) { } 1024 4096 5120
elsif ($n) { } 3840 256 4096
Condition100%3/3
$n and $args{"ridged"}
!ll&&!rl&&r
25638401024
MC/DC100%2/2
$n and $args{"ridged"}
$n $args{"ridged"}
Truth table100%3/3
A and B
A= $nB= $args{"ridged"}
ABresult
0X0
100
111
1292 1024 $combinedColumn->set( $y,
1293 ( $bias * $MAX_COLOR ) + $zshift - ( $t / $n ) );
1294 } elsif ($n) {
1295 3840 $combinedColumn->set( $y, $t / $n );
1296 } else {
1297 256 $combinedColumn->set( $y, 0 );
1298 }
1299 }
1300  
1301 256 $combined->[$x] = $combinedColumn;
1302  
1303 256 printRow($combinedColumn);
1304 }
1305  
1306 14 return $combined;
1307 }
1308  
1309 1 ▶sub block {
Subroutine block: called CC=2 SCAR=7.0
Pod documented
1310 1 my %args = @_;
1311  
1312 1 ▶ print "Generating block noise...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 1 1
1313  
1314 1 $args{smooth} = 0;
1315  
1316 1 return multires(%args);
1317 }
1318  
1319 1 ▶sub pgel {
Subroutine pgel: called CC=3 SCAR=11.2
Pod documented
1320 1 my %args = @_;
1321  
1322 1 ▶ print "Generating multi-res gel noise...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 1 1
1323  
1324 1 my $grid = multires(%args);
1325  
1326 1 ▶ $args{displace} = $DEFAULT_DISPLACEMENT if !defined $args{displace};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"displace"} 1 0 1
1327  
1328 1 %args = defaultArgs(%args);
1329  
1330 1 return displace( $grid, %args );
1331 }
1332  
1333 1 ▶sub wgel {
Subroutine wgel: called CC=5 SCAR=16.8
Pod documented
1334 1 my %args = @_;
1335  
1336 1 ▶ print "Generating worley gel noise...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 1 1
1337  
1338 1 ▶ my $dist = defined $args{dist} ? $args{dist} : 3;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'dist'} ? : 0 1 1
1339 1 ▶ my $freq = defined $args{freq} ? $args{freq} : 8;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'freq'} ? : 0 1 1
1340 1 ▶ my $displace = defined $args{displace} ? $args{displace} : 4;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'displace'} ? : 0 1 1
1341  
1342 1 %args = defaultArgs(
1343 %args,
1344 dist => $dist,
1345 freq => $freq,
1346 displace => $displace,
1347 );
1348  
1349 1 my $grid = worley(%args);
1350  
1351 1 return displace( $grid, %args );
1352 }
1353  
1354 5 ▶sub ridged {
Subroutine ridged: called CC=4 SCAR=13.9
Pod documented
1355 5 my %args = @_;
1356  
1357 5 ▶ print "Generating ridged multifractal noise...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 5 5
1358  
1359 5 ▶ $args{bias} = 0 if !defined $args{bias};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"bias"} 1 4 5
1360 5 ▶ $args{amp} = 1 if !defined $args{amp};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"amp"} 1 4 5
1361  
1362 5 return multires( %args, ridged => 1 );
1363 }
1364  
1365 0 ▶sub refract {
Subroutine refract: not called CC=5 SCAR=34.0
Pod documented
1366 0 my $grid = shift;
1367 0 my %args = @_;
1368  
1369 0 ▶ print "Applying fractal Z displacement...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 0 0
1370  
1371 0 my $haveLength = scalar( @{$grid} );
1372  
1373 0 my $out = [];
1374  
1375 0 ▶ for ( my $x = 0 ; $x < $haveLength ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $haveLength) 0 0 0
1376 0 $out->[$x] = [];
1377  
1378 0 my $inColumn = $grid->[$x];
1379 0 my $outColumn = $COLUMN_CLASS->new($haveLength);
1380  
1381 0 ▶ for ( my $y = 0 ; $y < $haveLength ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $haveLength) 0 0 0
1382 0 ▶ my $color = $inColumn->get($y) || 0;
Condition0%0/2
$inColumn->get($y) || 0
l!l
00
MC/DC0%0/1
$inColumn->get($y) || 0
$inColumn->get($y)
Truth table0%0/2
A
A= $inColumn->get($y)
Aresult
11
00
1383 0 my $srcY = ( $color / $MAX_COLOR ) * $haveLength;
1384  
1385 0 $outColumn->set( $y, $inColumn->get($srcY % $haveLength) );
1386 }
1387  
1388 0 $out->[$x] = $outColumn;
1389 }
1390  
1391 0 return $out;
1392 }
1393  
1394 2 ▶sub lsmooth {
Subroutine lsmooth: called CC=8 SCAR=20.8
Pod undocumented
1395 2 my $grid = shift;
1396 2 my %args = @_;
1397  
1398 2 my $len = scalar( @{$grid} );
1399  
1400 2 my $smooth = grid(%args, len => $args{len}/2);
1401  
1402 2 ▶ my $dirs = $args{dirs} || 6;
Condition100%2/2
$args{'dirs'} || 6
l!l
11
MC/DC100%1/1
$args{'dirs'} || 6
$args{'dirs'}
Truth table100%2/2
A
A= $args{'dirs'}
Aresult
11
00
1403 2 ▶ my $angle = $args{angle} || rand(360);
Condition66%2/3
$args{'angle'} || rand 360
l!l&&r!l&&!r
110
MC/DC0%0/2
$args{'angle'} || rand 360
$args{'angle'} rand 360
Truth table66%2/3
A || B
A= $args{'angle'}B= rand 360
ABresult
1X1
011
000
1404 2 ▶ my $rad = $args{rad} || 6;
Condition100%2/2
$args{'rad'} || 6
l!l
11
MC/DC100%1/1
$args{'rad'} || 6
$args{'rad'}
Truth table100%2/2
A
A= $args{'rad'}
Aresult
11
00
1405  
1406 2 my $dirAngle = 360 / $dirs;
1407 2 my $angle360 = 360 + $angle;
1408  
1409 2 ▶ for ( my $x = 0 ; $x < $len/2 ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len / 2) 16 2 18
1410 16 my $smoothColumn = $smooth->[$x];
1411 16 my $column = $grid->[$x*2];
1412  
1413 16 ▶ for ( my $y = 0 ; $y < $len/2 ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len / 2) 128 16 144
1414 128 $smoothColumn->set( $y,
1415 $smoothColumn->get($y) + $column->get($y*2) / $dirs );
1416  
1417 128 ▶ for ( my $a = $angle ; $a < $angle360 ; $a += $dirAngle ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a < $angle360) 640 128 768
1418 640 ▶ for ( my $d = 1 ; $d <= $rad ; $d++ ) { # distance
Branch: 1 branch
BranchTrueFalseTotal
if ($d <= $rad) 2560 640 3200
1419 2560 my ( $tx, $ty ) = translate( $x, $y, $a, $d );
1420 2560 $tx = ($tx*2) % $len;
1421 2560 $ty = ($ty*2) % $len;
1422  
1423 2560 $smoothColumn->set( $y,
1424 $smoothColumn->get($y) +
1425 $grid->[$tx]->get($ty) * ( 1 - ( $d / $rad ) ) / $rad );
1426 }
1427 }
1428 }
1429  
1430 16 $smooth->[$x] = $smoothColumn;
1431 }
1432  
1433 2 return grow($smooth,%args);
1434 }
1435  
1436 19 ▶sub smooth {
Subroutine smooth: called CC=3 SCAR=11.0
Pod documented
1437 19 my $grid = shift;
1438 19 my %args = @_;
1439  
1440 19 my $haveLength = scalar( @{$grid} );
1441  
1442 19 my $smooth = [];
1443  
1444 19 my $amt = $args{smooth};
1445  
1446 19 ▶ for ( my $x = 0 ; $x < $haveLength ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $haveLength) 232 19 251
1447 232 my $smoothColumn = $COLUMN_CLASS->new($haveLength);
1448  
1449 232 ▶ for ( my $y = 0 ; $y < $haveLength ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $haveLength) 3136 232 3368
1450 3136 my $corners =
1451 ( noise( $grid, $x - 1, $y - 1 ) +
1452 noise( $grid, $x + 1, $y - 1 ) +
1453 noise( $grid, $x - 1, $y + 1 ) +
1454 noise( $grid, $x + 1, $y + 1 ) ) / 16;
1455  
1456 3136 my $sides =
1457 ( noise( $grid, $x - 1, $y ) +
1458 noise( $grid, $x + 1, $y ) +
1459 noise( $grid, $x, $y - 1 ) +
1460 noise( $grid, $x, $y + 1 ) ) / 8;
1461  
1462 3136 my $pixel = noise( $grid, $x, $y );
1463  
1464 3136 my $center = $pixel / 4;
1465  
1466 3136 my $blended = $corners + $sides + $center;
1467  
1468 3136 my $final = interp( $pixel, $blended, $amt );
1469  
1470 3136 $smoothColumn->set( $y, $final );
1471 }
1472  
1473 232 $smooth->[$x] = $smoothColumn;
1474 }
1475  
1476 19 return $smooth;
1477 }
1478  
1479 1 ▶sub terra {
Subroutine terra: called CC=18 SCAR=29.6
Pod documented
1480 1 my %args = @_;
1481  
1482 1 ▶ print "Generating terra noise...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 1 1
1483  
1484 1 ▶ $args{amp} = .5 if !defined $args{amp};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"amp"} 1 0 1
1485 1 ▶ $args{feather} = 48 if !defined $args{feather};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"feather"} 1 0 1
1486 1 ▶ $args{layers} ||= 4;
Condition50%1/2
$args{"layers"} ||= 4
l!l
01
MC/DC0%0/1
$args{"layers"} ||= 4
$args{"layers"}
Truth table50%1/2
A
A= $args{"layers"}
Aresult
11
00
1487  
1488 1 %args = defaultArgs(%args);
1489  
1490 1 my $refGenerator = __generator( $args{lbase} );
1491  
1492 my $reference = &$refGenerator(
1493 %args,
1494 bias => .4,
1495 amp => .6,
1496 freq => $args{freq},
1497 1 );
1498  
1499 1 my @layers;
1500  
1501 1 do {
1502 1 my $biasOffset = .5;
1503 1 my $bias = .25;
1504 1 my $amp = .125;
1505 1 my $freq = $args{freq};
1506  
1507 1 my $generator = __generator( $args{ltype} );
1508  
1509 1 ▶ for ( my $i = 0 ; $i < $args{layers} ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $args{"layers"}) 4 1 5
1510 4 ▶ print "---------------------------------------\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 4 4
1511 4 ▶ print "Complex layer $i ...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 4 4
1512  
1513 4 my %xargs;
1514  
1515 4 ▶ if ( $args{ltype} eq 'ridged' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'ltype'} eq 'ridged') { } 4 0 4
1516 4 $xargs{zshift} = $bias;
1517 4 $xargs{bias} = 0;
1518 } else {
1519 0 $xargs{bias} = $bias;
1520 }
1521  
1522 4 push @layers,
1523 &$generator(
1524 %args,
1525 %xargs,
1526 freq => $freq,
1527 amp => $amp,
1528 );
1529  
1530 4 $bias += $biasOffset;
1531 4 $biasOffset *= .5;
1532  
1533 4 $freq *= 2;
1534  
1535 # $amp *= $args{persist};
1536 }
1537 };
1538  
1539 1 my $out = grid(%args);
1540  
1541 1 my $feather = $args{feather};
1542 1 my $length = $args{len};
1543  
1544 1 ▶ for ( my $x = 0 ; $x < $length ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $length) 16 1 17
1545 16 my $referenceColumn = $reference->[$x];
1546 16 my $outColumn = $COLUMN_CLASS->new($length);
1547  
1548 16 ▶ for ( my $y = 0 ; $y < $length ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $length) 256 16 272
1549 256 my $value = $referenceColumn->get($y);
1550  
1551 256 my $level = 128;
1552 256 my $levelOffset = 64;
1553  
1554 256 $outColumn->set( $y, $layers[0][$x]->get($y) );
1555  
1556 256 ▶ for ( my $z = 1 ; $z < $args{layers} ; $z++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($z < $args{"layers"}) 768 256 1024
1557 768 my $diff = $level - $value;
1558  
1559 768 ▶ if ( $value >= $level ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value >= $level) { } 381 387 768
elsif ($feather > 0 and $diff <= $feather or $feather < 0 and $diff <= $feather * -1) { } 64 646 710
1560 ##
1561 ## Reference pixel value is greater than current level,
1562 ## so use the current level's pixel value
1563 ##
1564 381 $outColumn->set( $y, $layers[$z][$x]->get($y) );
1565  
1566 ▶ } elsif ( ( ( $feather > 0 ) && $diff <= $feather )
Condition55%5/9
$feather > 0 and $diff <= $feather or $feather < 0 and $diff <= $feather * -1
l!l&&r!l&&!r
640323
$feather > 0 and $diff <= $feather
!ll&&!rl&&r
032364
$feather < 0 and $diff <= $feather * -1
!ll&&!rl&&r
32300
MC/DC25%1/4
$feather > 0 and $diff <= $feather or $feather < 0 and $diff <= $feather * -1
$feather > 0 $diff <= $feather $feather < 0 $diff <= $feather * -1
Truth table28%2/7
A and B or C and D
A= $feather > 0B= $diff <= $featherC= $feather < 0D= $diff <= $feather * -1
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
1567 || ( ( $feather < 0 ) && $diff <= $feather * -1 ) )
1568 {
1569 64 my $fadeAmt = $diff / abs($feather);
1570  
1571 64 ▶ if ( $feather < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feather < 0) 0 64 64
1572 0 $fadeAmt = 1 - $fadeAmt;
1573 }
1574  
1575 ##
1576 ## Reference pixel value is less than current level,
1577 ## but within the feather range, so fade it
1578 ##
1579 64 my $color =
1580 interp( $layers[$z][$x]->get($y), $outColumn->get($y), $fadeAmt );
1581  
1582 64 $outColumn->set( $y, $color );
1583 }
1584  
1585 768 $level += $levelOffset;
1586 768 $levelOffset /= 2;
1587 }
1588  
1589 256 $outColumn->set( $y, interp( $outColumn->get($y), $value, .25 ) );
1590 }
1591  
1592 16 $out->[$x] = $outColumn;
1593 16 printRow($outColumn);
1594 }
1595  
1596 1 return $out;
1597  
1598 # return $args{smooth} ? smooth($out, %args) : $out;
1599 }
1600  
1601 2 ▶sub __generator {
Subroutine __generator: called CC=4 SCAR=13.9
1602 2 my $type = shift;
1603  
1604 2 my $generator;
1605  
1606 2 for my $ltype ( @SIMPLE_TYPES, @PERLIN_TYPES ) {
1607 74 ▶ if ( $type eq $ltype ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq $ltype) 2 72 74
1608 2 do {
1609 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1610 2 $generator = \&{"Math::Fractal::Noisemaker::$type"};
1611 };
1612 }
1613 }
1614  
1615 2 ▶ if ( !$generator ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($generator) 0 2 2
1616 0 usage("Unknown noise type '$type' specified");
1617 }
1618  
1619 2 return $generator;
1620 }
1621  
1622 1024 ▶sub clamp {
Subroutine clamp: called CC=4 SCAR=14.5
Pod undocumented
1623 1024 my $val = shift;
1624 1024 ▶ my $max = shift || $MAX_COLOR;
Condition33%1/3
shift() || $MAX_COLOR
l!l&&r!l&&!r
010240
MC/DC0%0/2
shift() || $MAX_COLOR
shift() $MAX_COLOR
Truth table33%1/3
A || B
A= shift()B= $MAX_COLOR
ABresult
1X1
011
000
1625  
1626 1024 ▶ $val = 0 if $val < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $val < 0 0 1024 1024
1627 1024 ▶ $val = $max if $val > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $val > $max 334 690 1024
1628  
1629 1024 return $val;
1630 }
1631  
1632 155136 ▶sub noise {
Subroutine noise: called CC=9 SCAR=22.0
Pod undocumented
1633 155136 my $noise = shift;
1634 155136 my $x = shift;
1635 155136 my $y = shift;
1636  
1637 155136 my $length = shift;
1638 155136 ▶ my $xlen = $length || scalar @$noise;
Condition100%2/2
$length || scalar @$noise
l!l
2048153088
MC/DC100%1/1
$length || scalar @$noise
$length
Truth table100%2/2
A
A= $length
Aresult
11
00
1639 155136 ▶ my $ylen = $length || $noise->[0]->len();
Condition66%2/3
$length || $noise->[0]->len
l!l&&r!l&&!r
20481530880
MC/DC0%0/2
$length || $noise->[0]->len
$length $noise->[0]->len
Truth table66%2/3
A || B
A= $lengthB= $noise->[0]->len
ABresult
1X1
011
000
1640  
1641 155136 my $thisX = int($x);
1642 155136 my $thisY = int($y);
1643  
1644 #
1645 # No need to interpolate
1646 #
1647 155136 ▶ if ( ( $thisX == $x ) && ( $thisY == $y ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thisX == $x and $thisY == $y) 110816 44320 155136
Condition100%3/3
$thisX == $x and $thisY == $y
!ll&&!rl&&r
3129613024110816
MC/DC100%2/2
$thisX == $x and $thisY == $y
$thisX == $x $thisY == $y
Truth table100%3/3
A and B
A= $thisX == $xB= $thisY == $y
ABresult
0X0
100
111
1648 110816 return $noise->[ $x % $xlen ]->get( $y % $ylen );
1649 }
1650  
1651 44320 $x = ( ( $x * 1000 ) % ( $xlen * 1000 ) ) / 1000;
1652 44320 $y = ( ( $y * 1000 ) % ( $ylen * 1000 ) ) / 1000;
1653  
1654 44320 my $fractX = $x - $thisX;
1655 44320 my $nextX = ( $x + 1 ) % $xlen;
1656  
1657 44320 my $fractY = $y - $thisY;
1658 44320 my $nextY = ( $y + 1 ) % $ylen;
1659  
1660 44320 $thisX = $thisX % $xlen;
1661 44320 $thisY = $thisY % $ylen;
1662  
1663 44320 my $thisColumn = $noise->[$thisX];
1664 44320 my $nextColumn = $noise->[$nextX];
1665  
1666 44320 ▶ my $v1 = $thisColumn->get($thisY) || 0;
Condition100%2/2
$thisColumn->get($thisY) || 0
l!l
408793441
MC/DC100%1/1
$thisColumn->get($thisY) || 0
$thisColumn->get($thisY)
Truth table100%2/2
A
A= $thisColumn->get($thisY)
Aresult
11
00
1667 44320 ▶ my $v2 = $nextColumn->get($thisY) || 0;
Condition100%2/2
$nextColumn->get($thisY) || 0
l!l
408793441
MC/DC100%1/1
$nextColumn->get($thisY) || 0
$nextColumn->get($thisY)
Truth table100%2/2
A
A= $nextColumn->get($thisY)
Aresult
11
00
1668 44320 ▶ my $v3 = $thisColumn->get($nextY) || 0;
Condition100%2/2
$thisColumn->get($nextY) || 0
l!l
408793441
MC/DC100%1/1
$thisColumn->get($nextY) || 0
$thisColumn->get($nextY)
Truth table100%2/2
A
A= $thisColumn->get($nextY)
Aresult
11
00
1669 44320 ▶ my $v4 = $nextColumn->get($nextY) || 0;
Condition100%2/2
$nextColumn->get($nextY) || 0
l!l
408793441
MC/DC100%1/1
$nextColumn->get($nextY) || 0
$nextColumn->get($nextY)
Truth table100%2/2
A
A= $nextColumn->get($nextY)
Aresult
11
00
1670  
1671 44320 my $i1 = interp( $v1, $v2, $fractX );
1672 44320 my $i2 = interp( $v3, $v4, $fractX );
1673  
1674 44320 return interp( $i1, $i2, $fractY );
1675 }
1676  
1677 140768 ▶sub interp {
Subroutine interp: called CC=2 SCAR=7.2
Pod documented
1678 140768 ▶ die "No interp function defined" if !$INTERP_FN;
Branch: 1 branch
BranchTrueFalseTotal
unless $INTERP_FN 0 140768 140768
1679  
1680 140768 &$INTERP_FN(@_);
1681 }
1682  
1683 0 ▶sub lerp {
Subroutine lerp: not called CC=6 SCAR=37.4
Pod undocumented
1684 0 ▶ my $a = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1685 0 ▶ my $b = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1686 0 ▶ my $x = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1687  
1688 0 ▶ if ( $x < 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($x < 0) { } 0 0 0
elsif ($x > 1) { } 0 0 0
1689 0 $x = 0;
1690 } elsif ( $x > 1 ) {
1691 0 $x = 1;
1692 }
1693  
1694 0 return ( $a * ( 1 - $x ) + $b * $x );
1695 }
1696  
1697 140768 ▶sub cosine_interp {
Subroutine cosine_interp: called CC=4 SCAR=13.9
Pod undocumented
1698 140768 ▶ my $a = shift || 0;
Condition100%2/2
shift() || 0
l!l
12981410954
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1699 140768 ▶ my $b = shift || 0;
Condition100%2/2
shift() || 0
l!l
12991810850
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1700 140768 ▶ my $x = shift || 0;
Condition100%2/2
shift() || 0
l!l
10060340165
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1701  
1702 140768 my $ft = ( $x * pi );
1703 140768 my $f = ( 1 - cos($ft) ) * .5;
1704  
1705 140768 return ( $a * ( 1 - $f ) + $b * $f );
1706 }
1707  
1708 1 ▶sub wavelet {
Subroutine wavelet: called CC=8 SCAR=21.4
Pod documented
1709 1 my %args = @_;
1710  
1711 1 ▶ print "Generating wavelet noise...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 1 1
1712  
1713 1 ▶ $args{amp} = $DEFAULT_AMP if !defined $args{amp};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"amp"} 1 0 1
1714 1 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
100
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
1715 1 ▶ $args{freq} = $args{len} if !defined $args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"freq"} 1 0 1
1716  
1717 1 %args = defaultArgs(%args);
1718  
1719 1 ▶ my $source = $args{grid} || white( %args, len => $args{freq} );
Condition33%1/3
$args{'grid'} || white(%args, 'len', $args{'freq'})
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{'grid'} || white(%args, 'len', $args{'freq'})
$args{'grid'} white(%args, 'len', $args{'freq'})
Truth table33%1/3
A || B
A= $args{'grid'}B= white(%args, 'len', $args{'freq'})
ABresult
1X1
011
000
1720  
1721 1 my $down = shrink( $source, %args, len => $args{freq} / 2 );
1722 1 my $up = grow( $down, %args, len => $args{freq} );
1723  
1724 1 my $out = [];
1725  
1726 1 my $freq = $args{freq};
1727  
1728 1 ▶ for ( my $x = 0 ; $x < $freq ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $freq) 16 1 17
1729 16 my $column = $COLUMN_CLASS->new($freq);
1730 16 my $sourceColumn = $source->[$x];
1731 16 my $upColumn = $up->[$x];
1732  
1733 16 ▶ for ( my $y = 0 ; $y < $freq ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $freq) 256 16 272
1734 $column->set( $y,
1735 256 ( $args{bias} * $MAX_COLOR ) +
1736 $sourceColumn->get($y) -
1737 $upColumn->get($y) );
1738 }
1739  
1740 16 $out->[$x] = $column;
1741 16 printRow($column);
1742 }
1743  
1744 1 return grow( $out, %args );
1745 }
1746  
1747 1 ▶sub gasket {
Subroutine gasket: called CC=11 SCAR=24.2
Pod documented
1748 1 my %args = @_;
1749  
1750 1 ▶ print "Generating gasket...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 1 1
1751  
1752 1 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
100
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
1753 1 ▶ $args{freq} = $args{len} if !defined $args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"freq"} 1 0 1
1754 1 ▶ $args{amp} ||= 1;
Condition50%1/2
$args{"amp"} ||= 1
l!l
01
MC/DC0%0/1
$args{"amp"} ||= 1
$args{"amp"}
Truth table50%1/2
A
A= $args{"amp"}
Aresult
11
00
1755  
1756 1 my $freq = $args{freq};
1757 1 my $amp = $args{amp} * $MAX_COLOR;
1758  
1759 1 %args = defaultArgs(%args);
1760  
1761 1 my $grid = grid( %args, len => $args{freq} );
1762  
1763 1 ▶ for ( my $x = 0 ; $x < $freq ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $freq) 16 1 17
1764 16 $grid->[$x] = $COLUMN_CLASS->new($freq);
1765 }
1766  
1767 1 ▶ my $f1 = sub { return ( $_[0] / 2, $_[1] / 2 ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
1768 1 ▶ my $f2 = sub { return ( ( $_[0] + 1 ) / 2, $_[1] / 2 ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
1769 1 ▶ my $f3 = sub { return ( $_[0] / 2, ( $_[1] + 1 ) / 2 ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
1770  
1771 1 ▶ my $iters = $args{maxiter} || $freq * $freq;
Condition33%1/3
$args{'maxiter'} || $freq * $freq
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{'maxiter'} || $freq * $freq
$args{'maxiter'} $freq * $freq
Truth table33%1/3
A || B
A= $args{'maxiter'}B= $freq * $freq
ABresult
1X1
011
000
1772  
1773 1 my $x = rand(1);
1774 1 my $y = rand(1);
1775  
1776 1 ▶ for ( my $i = 0 ; $i < $iters ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $iters) 256 1 257
1777 256 ▶ if ( $i > 20 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 20) 235 21 256
1778 235 my $thisX = ( $x * $freq ) % $freq;
1779 235 my $thisY = ( $y * $freq ) % $freq;
1780 235 $grid->[$thisX]->set( $thisY, $MAX_COLOR );
1781 }
1782  
1783 256 my $rand = rand(3);
1784 256 ▶ if ( $rand < 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rand < 1) { } 97 159 256
elsif ($rand < 2) { } 87 72 159
1785 97 ( $x, $y ) = &$f1( $x, $y );
1786 } elsif ( $rand < 2 ) {
1787 87 ( $x, $y ) = &$f2( $x, $y );
1788 } else {
1789 72 ( $x, $y ) = &$f3( $x, $y );
1790 }
1791 }
1792  
1793 1 return grow( $grid, %args );
1794 }
1795  
1796 #
1797 # Set up IFS flame functions once
1798 #
1799 6411 ▶sub _fflinear { return @_ }
Subroutine _fflinear: called CC=1 SCAR=0.0
1800  
1801 6387 ▶sub _ffsinusoidal {
Subroutine _ffsinusoidal: called CC=1 SCAR=0.0
1802 6387 my ( $x, $y ) = @_;
1803 6387 return sin($x) * 3, sin($y) * 3;
1804 }
1805  
1806 4309 ▶sub _ffsphere {
Subroutine _ffsphere: called CC=1 SCAR=0.0
1807 4309 my ( $x, $y ) = @_;
1808 4309 my $n = 1 / ( ( $x * $x ) + ( $y + $y ) );
1809 4309 return $x * $n, $y * $n;
1810 }
1811  
1812 2074 ▶sub _ffswirl {
Subroutine _ffswirl: called CC=1 SCAR=0.0
1813 2074 my ( $x, $y ) = @_;
1814 2074 my $rsqrd = ( ( $x * $x ) + ( $y + $y ) );
1815 return (
1816 2074 ( $x * sin($rsqrd) ) - ( $y * cos($rsqrd) ),
1817 ( $x * cos($rsqrd) ) + ( $y * sin($rsqrd) )
1818 );
1819 }
1820  
1821 2251 ▶sub _ffhorseshoe {
Subroutine _ffhorseshoe: called CC=1 SCAR=0.0
1822 2251 my ( $x, $y ) = @_;
1823 2251 my $r = sqrt( ( $x * $x ) + ( $y * $y ) );
1824 2251 my $rf = 1 / ( $r * $r );
1825 2251 return ( $rf * ( $x - $y ) * ( $x + $y ), $rf * 2 * $x * $y );
1826 }
1827  
1828 4168 ▶sub _ffpopcorn {
Subroutine _ffpopcorn: called CC=1 SCAR=0.0
1829 4168 my ( $x, $y, $c, $f ) = @_;
1830 4168 return ( $x + ( $c * sin( tan( 3 * $y ) ) ),
1831 $y + ( $f * sin( tan( 3 * $x ) ) ), );
1832 }
1833  
1834 1 my @flameFns;
1835  
1836 1 do {
1837 1 push @flameFns, \&_fflinear;
1838 1 push @flameFns, \&_ffsinusoidal;
1839 1 push @flameFns, \&_ffsphere;
1840 1 push @flameFns, \&_ffswirl;
1841 1 push @flameFns, \&_ffhorseshoe;
1842 1 push @flameFns, \&_ffpopcorn;
1843 };
1844  
1845 1 ▶sub fflame {
Subroutine fflame: called CC=10 SCAR=23.2
Pod documented
1846 1 my %args = @_;
1847  
1848 1 my @fns;
1849  
1850 1 ▶ for ( my $i = 0 ; $i < @flameFns * 2 ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @flameFns * 2) 12 1 13
1851 12 push @fns, $flameFns[ rand(@flameFns) ];
1852 }
1853  
1854 1 ▶ print "Generating fractal flame!\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 1 1
1855  
1856 1 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
100
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
1857 1 ▶ $args{freq} = $args{len} if !defined $args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"freq"} 1 0 1
1858 1 ▶ $args{amp} ||= 1;
Condition50%1/2
$args{"amp"} ||= 1
l!l
01
MC/DC0%0/1
$args{"amp"} ||= 1
$args{"amp"}
Truth table50%1/2
A
A= $args{"amp"}
Aresult
11
00
1859  
1860 1 my $freq = $args{freq};
1861 1 my $amp = $args{amp} * $MAX_COLOR;
1862  
1863 1 %args = defaultArgs(%args);
1864  
1865 1 my $grid = grid( %args, len => $freq );
1866  
1867 1 ▶ my $steps = $args{maxiter} || $freq * $freq * 100;
Condition33%1/3
$args{'maxiter'} || $freq * $freq * 100
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{'maxiter'} || $freq * $freq * 100
$args{'maxiter'} $freq * $freq * 100
Truth table33%1/3
A || B
A= $args{'maxiter'}B= $freq * $freq * 100
ABresult
1X1
011
000
1868  
1869 1 my $A = rand(.125) + .25;
1870 1 my $B = rand(.125) + .25;
1871 1 my $c = rand(.125) + .25;
1872 1 my $d = rand(.125) + .25;
1873 1 my $e = rand(.125) + .25;
1874 1 my $f = rand(.125) + .25;
1875  
1876 1 ▶ my $scale = $args{zoom} || 1;
Condition50%1/2
$args{'zoom'} || 1
l!l
01
MC/DC0%0/1
$args{'zoom'} || 1
$args{'zoom'}
Truth table50%1/2
A
A= $args{'zoom'}
Aresult
11
00
1877  
1878 1 my $x = 0;
1879 1 my $y = 0;
1880  
1881 1 my $finalX = rand($freq);
1882 1 my $finalY = rand($freq);
1883  
1884 1 ▶ for ( my $n = 0 ; $n < $steps ; $n++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < $steps) 25600 1 25601
1885 25600 do {
1886 25600 my $gx = ( ( $x * $scale * $freq ) + $finalX ) % $freq;
1887 25600 my $gy = ( ( $y * $scale * $freq ) + $finalY ) % $freq;
1888  
1889 25600 my $column = $grid->[$gx];
1890  
1891 25600 $column->set( $gy, $column->get($gy) + 1 );
1892  
1893 25600 ▶ if ( $n >= 20 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n >= 20) 25580 20 25600
1894 25580 $column->set( $gy, $column->get($gy) + 1 );
1895 }
1896 };
1897  
1898 25600 my $i = rand(@fns);
1899  
1900 25600 do {
1901 25600 my $fn = $fns[$i];
1902  
1903 25600 my $thisX = ( $A * $x ) + ( $B * $y ) + $c;
1904 25600 my $thisY = ( $d * $y ) + ( $e * $y ) + $f;
1905  
1906 25600 ( $x, $y ) = &$fn( $thisX, $thisY, $c, $f );
1907 };
1908  
1909 }
1910  
1911 1 $grid = densemap($grid);
1912  
1913 1 $grid = glow( $grid, %args );
1914  
1915 1 return grow( $grid, %args );
1916 }
1917  
1918 10 ▶sub densemap {
Subroutine densemap: called CC=7 SCAR=19.5
Pod undocumented
1919 10 my $grid = shift;
1920 10 my $invert = shift;
1921  
1922 10 my $xlen = scalar @$grid;
1923 10 my $ylen = $grid->[0]->len();
1924  
1925 10 my $colors = {};
1926  
1927 10 ▶ for ( my $x = 0 ; $x < $xlen ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $xlen) 160 10 170
1928 160 my $column = $grid->[$x];
1929  
1930 160 ▶ for ( my $y = 0 ; $y < $ylen ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $ylen) 2560 160 2720
1931 2560 $colors->{ $column->get($y) }++;
1932 }
1933 }
1934  
1935 10 my @colors = keys %{$colors};
1936  
1937 10 my $i = 0;
1938 10 for ( sort { $a <=> $b } @colors ) {
1939 1520 ▶ if ( $invert ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($invert) { } 0 1520 1520
1940 0 $colors->{$_} = $MAX_COLOR - ( $i / @colors ) * $MAX_COLOR;
1941 } else {
1942 1520 $colors->{$_} = ( $i / @colors ) * $MAX_COLOR;
1943 }
1944  
1945 1520 $i++;
1946 }
1947  
1948 10 my $out = [];
1949  
1950 10 ▶ for ( my $x = 0 ; $x < $xlen ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $xlen) 160 10 170
1951 160 my $outColumn = $COLUMN_CLASS->new($ylen);
1952 160 my $column = $grid->[$x];
1953 160 ▶ for ( my $y = 0 ; $y < $ylen ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $ylen) 2560 160 2720
1954 2560 $outColumn->set( $y, $colors->{ $column->get($y) } );
1955 }
1956 160 $out->[$x] = $outColumn;
1957 }
1958  
1959 10 return $out;
1960 }
1961  
1962 1 ▶sub fern {
Subroutine fern: called CC=10 SCAR=23.3
Pod documented
1963 1 my %args = @_;
1964  
1965 1 ▶ print "Generating fern...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 1 1
1966  
1967 1 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
100
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
1968 1 ▶ $args{freq} = $args{len} if !defined $args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"freq"} 1 0 1
1969 1 ▶ $args{amp} ||= 1;
Condition50%1/2
$args{"amp"} ||= 1
l!l
01
MC/DC0%0/1
$args{"amp"} ||= 1
$args{"amp"}
Truth table50%1/2
A
A= $args{"amp"}
Aresult
11
00
1970  
1971 1 my $freq = $args{freq};
1972 1 my $amp = $args{amp} * $MAX_COLOR;
1973  
1974 1 %args = defaultArgs(%args);
1975  
1976 1 my $grid = grid( %args, len => $freq );
1977  
1978 1 my $steps = $freq * $freq * 10;
1979  
1980 1 my $x = 0;
1981 1 my $y = 0;
1982  
1983 1 ▶ my $scale = $args{zoom} || 1;
Condition50%1/2
$args{'zoom'} || 1
l!l
01
MC/DC0%0/1
$args{'zoom'} || 1
$args{'zoom'}
Truth table50%1/2
A
A= $args{'zoom'}
Aresult
11
00
1984  
1985 1 ▶ for ( my $n = 0 ; $n < $steps ; $n++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < $steps) 2560 1 2561
1986 2560 my $gx =
1987 ( $freq - ( ( ( $x * $scale ) + 2.1818 ) / 4.8374 * $freq ) ) % $freq;
1988 2560 my $gy = ( $freq - ( ( ( $y * $scale ) / 9.95851 ) * $freq ) ) % $freq;
1989  
1990 2560 my $column = $grid->[$gx];
1991  
1992 2560 $column->set( $gy, $column->get($gy) + sqrt( rand() * $amp ) );
1993  
1994 2560 my $rand = rand();
1995  
1996 2560 ▶ if ( $rand <= .01 ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($rand <= 0.01) { } 19 2541 2560
elsif ($rand <= 0.08) { } 192 2349 2541
elsif ($rand <= 0.15) { } 172 2177 2349
1997 19 ( $x, $y ) = _fern1( $x, $y );
1998 } elsif ( $rand <= .08 ) {
1999 192 ( $x, $y ) = _fern2( $x, $y );
2000 } elsif ( $rand <= .15 ) {
2001 172 ( $x, $y ) = _fern3( $x, $y );
2002 } else {
2003 2177 ( $x, $y ) = _fern4( $x, $y );
2004 }
2005 }
2006  
2007 1 return grow( $grid, %args );
2008 }
2009  
2010 19 ▶sub _fern1 {
Subroutine _fern1: called CC=1 SCAR=0.0
2011 19 my $x = shift;
2012 19 my $y = shift;
2013  
2014 19 return ( 0, .16 * $y );
2015 }
2016  
2017 192 ▶sub _fern2 {
Subroutine _fern2: called CC=1 SCAR=0.0
2018 192 my $x = shift;
2019 192 my $y = shift;
2020  
2021 192 return ( ( .2 * $x ) - (.26) * $y, ( .23 * $x ) + ( .22 * $y ) + 1.6 );
2022 }
2023  
2024 172 ▶sub _fern3 {
Subroutine _fern3: called CC=1 SCAR=0.0
2025 172 my $x = shift;
2026 172 my $y = shift;
2027  
2028 172 return ( ( -.15 * $x ) + ( .28 * $y ), ( .26 * $x ) + ( .24 * $y ) + .44 );
2029 }
2030  
2031 2177 ▶sub _fern4 {
Subroutine _fern4: called CC=1 SCAR=0.0
2032 2177 my $x = shift;
2033 2177 my $y = shift;
2034  
2035 2177 return ( ( .85 * $x ) + ( .04 * $y ), ( -.04 * $x ) + ( .85 * $y ) + 1.6 );
2036 }
2037  
2038 2 ▶sub mandel {
Subroutine mandel: called CC=10 SCAR=23.3
Pod documented
2039 2 my %args = @_;
2040  
2041 2 ▶ print "Generating Mandelbrot...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 2 2
2042  
2043 2 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
200
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
2044 2 ▶ $args{freq} = $args{len} if !defined $args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"freq"} 2 0 2
2045  
2046 2 %args = defaultArgs(%args);
2047  
2048 2 my $freq = $args{freq};
2049  
2050 2 ▶ my $iters = $args{maxiter} || $freq;
Condition33%1/3
$args{'maxiter'} || $freq
l!l&&r!l&&!r
020
MC/DC0%0/2
$args{'maxiter'} || $freq
$args{'maxiter'} $freq
Truth table33%1/3
A || B
A= $args{'maxiter'}B= $freq
ABresult
1X1
011
000
2051  
2052 2 ▶ my $scale = $args{zoom} || 1;
Condition50%1/2
$args{'zoom'} || 1
l!l
02
MC/DC0%0/1
$args{'zoom'} || 1
$args{'zoom'}
Truth table50%1/2
A
A= $args{'zoom'}
Aresult
11
00
2053  
2054 2 $freq *= 2;
2055  
2056 2 my $grid = grid( %args, len => $freq );
2057  
2058 2 ▶ for ( my $x = 0 ; $x < $freq ; $x += 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $freq) 64 2 66
2059 64 my $cx = ( $x / $freq ) * 2 - 1;
2060 64 $cx -= .5;
2061 64 $cx /= $scale;
2062  
2063 64 my $column = $grid->[$x];
2064  
2065 64 ▶ for ( my $y = 0 ; $y < $freq / 2 ; $y += 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $freq / 2) 1024 64 1088
2066 1024 my $cy = ( $y / $freq ) * 2 - 1;
2067 1024 $cy /= $scale;
2068  
2069 1024 my $zx = 0;
2070 1024 my $zy = 0;
2071 1024 my $n = 0;
2072 1024 ▶ while ( ( $zx * $zx + $zy * $zy < $freq ) && $n < $iters ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zx * $zx + $zy * $zy < $freq and $n < $iters) 11020 1024 12044
Condition100%3/3
$zx * $zx + $zy * $zy < $freq and $n < $iters
!ll&&!rl&&r
58244211020
MC/DC100%2/2
$zx * $zx + $zy * $zy < $freq and $n < $iters
$zx * $zx + $zy * $zy < $freq $n < $iters
Truth table100%3/3
A and B
A= $zx * $zx + $zy * $zy < $freqB= $n < $iters
ABresult
0X0
100
111
2073 11020 my $new_zx = $zx * $zx - $zy * $zy + $cx;
2074 11020 $zy = 2 * $zx * $zy + $cy;
2075 11020 $zx = $new_zx;
2076  
2077 11020 $n++;
2078 }
2079  
2080 1024 $column->set( $y, $MAX_COLOR - ( ( $n / $iters ) * $MAX_COLOR ) );
2081 1024 $column->set( $freq - 1 - $y,
2082 $MAX_COLOR - ( ( $n / $iters ) * $MAX_COLOR ) );
2083 }
2084  
2085 64 printRow($column);
2086 }
2087  
2088 2 $grid = shrink( $grid, %args );
2089  
2090 2 $grid = grow( $grid, %args );
2091  
2092 2 return $grid;
2093 }
2094  
2095 1 ▶sub dmandel {
Subroutine dmandel: called CC=16 SCAR=27.8
Pod documented
2096 1 my %args = @_;
2097  
2098 1 ▶ print "Generating Mandelbrot...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 1 1
2099  
2100 1 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
100
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
2101 1 ▶ $args{freq} = $args{len} if !defined $args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"freq"} 1 0 1
2102  
2103 1 %args = defaultArgs(%args);
2104  
2105 1 my $freq = $args{freq};
2106 1 ▶ my $iters = $args{maxiter} || $MAX_COLOR;
Condition33%1/3
$args{'maxiter'} || $MAX_COLOR
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{'maxiter'} || $MAX_COLOR
$args{'maxiter'} $MAX_COLOR
Truth table33%1/3
A || B
A= $args{'maxiter'}B= $MAX_COLOR
ABresult
1X1
011
000
2107  
2108 1 my @interesting;
2109  
2110 1 my $prefreq = 256;
2111  
2112 1 ▶ for ( my $x = 0 ; $x < $prefreq ; $x += 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $prefreq) 256 1 257
2113 256 my $cx = ( $x / $prefreq ) * 2 - 1;
2114  
2115 256 ▶ for ( my $y = 0 ; $y < $prefreq / 2 ; $y += 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $prefreq / 2) 32768 256 33024
2116 32768 my $cy = ( $y / $prefreq ) * 2 - 1;
2117  
2118 32768 my $zx = 0;
2119 32768 my $zy = 0;
2120 32768 my $n = 0;
2121 32768 ▶ while ( ( $zx * $zx + $zy * $zy < $prefreq ) && $n < $prefreq / 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zx * $zx + $zy * $zy < $prefreq and $n < $prefreq / 2) 1674170 32768 1706938
Condition100%3/3
$zx * $zx + $zy * $zy < $prefreq and $n < $prefreq / 2
!ll&&!rl&&r
21240115281674170
MC/DC100%2/2
$zx * $zx + $zy * $zy < $prefreq and $n < $prefreq / 2
$zx * $zx + $zy * $zy < $prefreq $n < $prefreq / 2
Truth table100%3/3
A and B
A= $zx * $zx + $zy * $zy < $prefreqB= $n < $prefreq / 2
ABresult
0X0
100
111
2122 1674170 my $new_zx = $zx * $zx - $zy * $zy + $cx;
2123 1674170 $zy = 2 * $zx * $zy + $cy;
2124 1674170 $zx = $new_zx;
2125 1674170 $n++;
2126 }
2127  
2128 32768 my $pct = ( $n / ( $prefreq / 2 ) );
2129  
2130 32768 ▶ if ( $pct > .99 && $pct < 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pct > "0.99" and $pct < 1) 4 32764 32768
Condition100%3/3
$pct > "0.99" and $pct < 1
!ll&&!rl&&r
21234115304
MC/DC100%2/2
$pct > "0.99" and $pct < 1
$pct > "0.99" $pct < 1
Truth table100%3/3
A and B
A= $pct > "0.99"B= $pct < 1
ABresult
0X0
100
111
2131 4 push @interesting, [ $cx, $cy ];
2132 }
2133 }
2134 }
2135  
2136 1 my $tuple = $interesting[ rand(@interesting) ];
2137  
2138 1 ▶ my $scale = $args{zoom} || 5120 + rand(128);
Condition33%1/3
$args{'zoom'} || 5120 + rand(128)
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{'zoom'} || 5120 + rand(128)
$args{'zoom'} 5120 + rand(128)
Truth table33%1/3
A || B
A= $args{'zoom'}B= 5120 + rand(128)
ABresult
1X1
011
000
2139  
2140 1 $freq *= 2;
2141  
2142 1 my $grid = grid( %args, len => $freq );
2143  
2144 1 ▶ for ( my $x = 0 ; $x < $freq ; $x += 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $freq) 32 1 33
2145 32 my $cx = ( $x / $freq ) * 2 - 1;
2146 32 $cx += $tuple->[0] * $scale;
2147 32 $cx /= $scale;
2148  
2149 32 my $column = $grid->[$x];
2150  
2151 32 ▶ for ( my $y = 0 ; $y < $freq ; $y += 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $freq) 1024 32 1056
2152 1024 my $cy = ( $y / $freq ) * 2 - 1;
2153  
2154 1024 $cy += $tuple->[1] * $scale;
2155 1024 $cy /= $scale;
2156 1024 my $cyKey = $cy * $scale;
2157  
2158 1024 my $zx = 0;
2159 1024 my $zy = 0;
2160 1024 my $n = 0;
2161 1024 ▶ while ( ( $zx * $zx + $zy * $zy < $freq ) && $n < $iters ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zx * $zx + $zy * $zy < $freq and $n < $iters) 85284 1024 86308
Condition100%3/3
$zx * $zx + $zy * $zy < $freq and $n < $iters
!ll&&!rl&&r
9319385284
MC/DC100%2/2
$zx * $zx + $zy * $zy < $freq and $n < $iters
$zx * $zx + $zy * $zy < $freq $n < $iters
Truth table100%3/3
A and B
A= $zx * $zx + $zy * $zy < $freqB= $n < $iters
ABresult
0X0
100
111
2162 85284 my $new_zx = $zx * $zx - $zy * $zy + $cx;
2163 85284 $zy = 2 * $zx * $zy + $cy;
2164 85284 $zx = $new_zx;
2165 85284 $n++;
2166 }
2167  
2168 1024 my $color = $MAX_COLOR - ( ( $n / ( $iters - 1 ) ) * $MAX_COLOR );
2169  
2170 # $color = 0 if $color >= $MAX_COLOR;
2171  
2172 1024 $column->set( $y, $color );
2173 }
2174  
2175 32 printRow($column);
2176 }
2177  
2178 1 $grid = shrink( $grid, %args );
2179  
2180 1 $grid = grow( $grid, %args );
2181  
2182 1 return tile($grid,%args);
2183 }
2184  
2185 1 ▶sub buddha {
Subroutine buddha: called CC=15 SCAR=27.3
Pod documented
2186 1 my %args = @_;
2187  
2188 1 ▶ print "Generating Buddhabrot (this will take a while)...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 1 1
2189  
2190 1 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
100
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
2191 1 ▶ $args{freq} = $args{len} if !defined $args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"freq"} 1 0 1
2192  
2193 1 %args = defaultArgs(%args);
2194  
2195 1 my $freq = $args{freq};
2196  
2197 1 ▶ my $iters = $args{maxiter} || 4096;
Condition50%1/2
$args{'maxiter'} || 4096
l!l
01
MC/DC0%0/1
$args{'maxiter'} || 4096
$args{'maxiter'}
Truth table50%1/2
A
A= $args{'maxiter'}
Aresult
11
00
2198  
2199 1 my $gap = $args{gap};
2200  
2201 1 my $grid = grid( %args, len => $freq, bias => 0 );
2202  
2203 #
2204 # Zooming in just makes buddhabrots disappear
2205 #
2206 1 ▶ my $scale = $args{zoom} || 1;
Condition50%1/2
$args{'zoom'} || 1
l!l
01
MC/DC0%0/1
$args{'zoom'} || 1
$args{'zoom'}
Truth table50%1/2
A
A= $args{'zoom'}
Aresult
11
00
2207  
2208 1 ▶ for ( my $x = 0 ; $x < $freq ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $freq) 16 1 17
2209 16 ▶ for ( my $y = 0 ; $y < $freq / 2 ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $freq / 2) 128 16 144
2210 128 ▶ next if rand() < $gap;
Branch: 1 branch
BranchTrueFalseTotal
if rand() < $gap 0 128 128
2211  
2212 128 my $cx = ( $x / $freq ) * 2 - 1;
2213 128 $cx -= .5;
2214  
2215 128 my $cy = ( $y / $freq ) * 2 - 1;
2216  
2217 128 $cx /= $scale;
2218 128 $cy /= $scale;
2219  
2220 128 my $zx = 0;
2221 128 my $zy = 0;
2222 128 my $n = 0;
2223 128 ▶ while ( ( $zx * $zx + $zy * $zy < $freq ) && $n < $iters ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zx * $zx + $zy * $zy < $freq and $n < $iters) 181050 128 181178
Condition100%3/3
$zx * $zx + $zy * $zy < $freq and $n < $iters
!ll&&!rl&&r
8444181050
MC/DC100%2/2
$zx * $zx + $zy * $zy < $freq and $n < $iters
$zx * $zx + $zy * $zy < $freq $n < $iters
Truth table100%3/3
A and B
A= $zx * $zx + $zy * $zy < $freqB= $n < $iters
ABresult
0X0
100
111
2224 181050 my $new_zx = $zx * $zx - $zy * $zy + $cx;
2225 181050 $zy = 2 * $zx * $zy + $cy;
2226 181050 $zx = $new_zx;
2227 181050 $n++;
2228 }
2229  
2230 128 ▶ next if $n == $iters;
Branch: 1 branch
BranchTrueFalseTotal
if $n == $iters 44 84 128
2231 84 ▶ next if $n <= sqrt($iters);
Branch: 1 branch
BranchTrueFalseTotal
if $n <= CORE::sqrt $iters 83 1 84
2232  
2233 1 $zx = 0;
2234 1 $zy = 0;
2235 1 $n = 0;
2236 1 ▶ while ( ( $zx * $zx + $zy * $zy < $freq ) && $n < $iters ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zx * $zx + $zy * $zy < $freq and $n < $iters) 155 1 156
Condition66%2/3
$zx * $zx + $zy * $zy < $freq and $n < $iters
!ll&&!rl&&r
10155
MC/DC50%1/2
$zx * $zx + $zy * $zy < $freq and $n < $iters
$zx * $zx + $zy * $zy < $freq $n < $iters
Truth table66%2/3
A and B
A= $zx * $zx + $zy * $zy < $freqB= $n < $iters
ABresult
0X0
100
111
2237 155 my $new_zx = $zx * $zx - $zy * $zy + $cx;
2238 155 $zy = 2 * $zx * $zy + $cy;
2239 155 $zx = $new_zx;
2240 155 $n++;
2241  
2242 155 my $thisX = ( ( ( $zx + 1 ) / 2 ) * $freq + ( $freq * .25 ) ) % $freq;
2243 155 my $thisY = ( ( $zy + 1 ) / 2 ) * $freq % $freq;
2244  
2245 155 $grid->[$thisY]->set( $thisX, $grid->[$thisY]->get($thisX) + 25 );
2246 155 $grid->[ $freq - 1 - $thisY ]
2247 ->set( $thisX, $grid->[ $freq - 1 - $thisY ]->get($thisX) + 25 );
2248 }
2249 }
2250 16 printRow( $grid->[$x] );
2251 }
2252  
2253 1 $grid = densemap( $grid );
2254  
2255 1 $grid = grow( $grid, %args );
2256  
2257 1 return $grid;
2258 }
2259  
2260 # Re-maps pixel values along the north and south edges of the source
2261 # image using polar coordinates, slowly blending back into original
2262 # pixel values towards the middle.
2263 0 ▶sub spheremap {
Subroutine spheremap: not called CC=7 SCAR=40.3
Pod undocumented
2264 0 my $grid = shift;
2265 0 my %args = defaultArgs(@_);
2266  
2267 0 ▶ print "Generating spheremap...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 0 0
2268  
2269 0 my $len = $args{len};
2270 0 my $offset = $len / 2;
2271  
2272 0 my $out = [];
2273  
2274 0 my $srclen = scalar( @{$grid} );
2275 0 my $scale = $srclen / $len;
2276  
2277 #
2278 # Polar regions
2279 #
2280 0 my $xOffset = $len / 4;
2281  
2282 0 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 0 0 0
2283 0 my $column = $COLUMN_CLASS->new($len);
2284  
2285 0 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 0 0 0
2286 0 my ( $cartX, $cartY, $cartZ ) = cartCoords( $x, $y, $len, $scale );
2287  
2288 ### North Pole
2289 0 $column->set( $y / 2,
2290 noise( $grid, $xOffset + ( ( $srclen - $cartX ) / 2 ), $cartY / 2 ) );
2291  
2292 ### South Pole
2293 0 $column->set(
2294 $len - 1 - ( $y / 2 ),
2295 noise(
2296 $grid,
2297 $xOffset + ( $cartX / 2 ),
2298 ( $offset * $scale ) + ( $cartY / 2 )
2299 )
2300 );
2301 }
2302  
2303 0 $out->[$x] = $column;
2304 }
2305  
2306 0 $grid = grow( $grid, %args, len => $len * 2 );
2307  
2308 #
2309 # Equator (cover up the unsightly seam left by the above pass)
2310 #
2311 0 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 0 0 0
2312 0 my $column = $out->[$x];
2313  
2314 0 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 0 0 0
2315 0 my $diff = abs( $offset - $y );
2316 0 my $pct = ( $diff / $offset );
2317  
2318 0 my $srcY = $scale * $y * 2;
2319 0 $srcY += ( $offset / 2 ) * $scale;
2320  
2321 0 my $source = noise( $grid, $scale * $x * 2, $srcY / 2 );
2322  
2323 0 ▶ my $target = $column->get($y) || 0;
Condition0%0/2
$column->get($y) || 0
l!l
00
MC/DC0%0/1
$column->get($y) || 0
$column->get($y)
Truth table0%0/2
A
A= $column->get($y)
Aresult
11
00
2324  
2325 0 $column->set( $y, interp( $source, $target, $pct ) );
2326 }
2327 }
2328  
2329 0 return $out;
2330 }
2331  
2332 0 ▶sub cartCoords {
Subroutine cartCoords: not called CC=2 SCAR=17.9
Pod undocumented
2333 0 my $x = shift;
2334 0 my $y = shift;
2335 0 my $len = shift;
2336 0 ▶ my $scale = shift || 1;
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
2337  
2338 0 my $thisLen = $len * $scale;
2339  
2340 0 $x = ( $x * $scale ) % $thisLen;
2341 0 $y = ( $y * $scale ) % $thisLen;
2342  
2343 0 my $theta = deg2rad( ( $x / $thisLen ) * 360 );
2344 0 my $phi = deg2rad( ( $y / $thisLen ) * 90 );
2345  
2346 0 my ( $cartX, $cartY, $cartZ ) =
2347 spherical_to_cartesian( $DEFAULT_RHO, $theta, $phi );
2348  
2349 0 $cartX = int( ( ( $cartX + 1 ) / 2 ) * $thisLen );
2350 0 $cartY = int( ( ( $cartY + 1 ) / 2 ) * $thisLen );
2351 0 $cartZ = int( ( ( $cartZ + 1 ) / 2 ) * $thisLen );
2352  
2353 0 return ( $cartX, $cartY, $cartZ );
2354 }
2355  
2356 ##
2357 ## Look up color values using vertical offset
2358 ##
2359 0 ▶sub vertclut {
Subroutine vertclut: not called CC=5 SCAR=34.0
Pod undocumented
2360 0 my $grid = shift;
2361 0 my %args = @_;
2362  
2363 0 ▶ print "Applying CLUT...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 0 0
2364  
2365 0 my $palette = Imager->new;
2366 0 ▶ $palette->read( file => $args{clut} ) || die $palette->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$palette->read("file", $args{"clut"}) or die $palette->errstr 0 0 0
2367  
2368 0 my $srcHeight = $palette->getheight();
2369 0 my $srcWidth = $palette->getwidth();
2370  
2371 0 my $xlen = scalar @$grid;
2372 0 my $ylen = $grid->[0]->len();
2373  
2374 0 my $out = Imager->new(
2375 xsize => $xlen,
2376 ysize => $ylen,
2377 );
2378  
2379 0 ▶ for ( my $x = 0 ; $x < $xlen ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $xlen) 0 0 0
2380 0 my $column = $grid->[$x];
2381  
2382 0 ▶ for ( my $y = 0 ; $y < $ylen ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $ylen) 0 0 0
2383 0 my $gray = $column->get($y);
2384  
2385 0 my $srcY = $y / $ylen;
2386  
2387 0 $out->setpixel(
2388 x => $x,
2389 y => $y,
2390 color => $palette->getpixel(
2391 x =>
2392 clamp( ( $gray / $MAX_COLOR ) * ( $srcWidth - 1 ), $srcWidth - 1 ),
2393 y => clamp( $srcY * ( $srcHeight - 1 ), $srcHeight - 1 ),
2394 )
2395 );
2396 }
2397 }
2398  
2399 0 return $out;
2400 }
2401  
2402 ##
2403 ## Look up color values from bottom left corner to top right corner
2404 ##
2405 0 ▶sub hypoclut {
Subroutine hypoclut: not called CC=5 SCAR=34.0
Pod undocumented
2406 0 my $grid = shift;
2407 0 my %args = @_;
2408  
2409 0 ▶ print "Applying corner-to-corner CLUT...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 0 0
2410  
2411 0 my $palette = Imager->new;
2412 0 ▶ $palette->read( file => $args{clut} ) || die $palette->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$palette->read("file", $args{"clut"}) or die $palette->errstr 0 0 0
2413  
2414 0 my $srcHeight = $palette->getheight();
2415 0 my $srcWidth = $palette->getwidth();
2416  
2417 0 my $xlen = scalar @$grid;
2418 0 my $ylen = $grid->[0]->len();
2419  
2420 0 my $out = Imager->new(
2421 xsize => $xlen,
2422 ysize => $ylen,
2423 );
2424  
2425 0 ▶ for ( my $x = 0 ; $x < $xlen ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $xlen) 0 0 0
2426 0 my $column = $grid->[$x];
2427  
2428 0 ▶ for ( my $y = 0 ; $y < $ylen ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $ylen) 0 0 0
2429 0 my $gray = $column->get($y);
2430  
2431 0 my $color = $palette->getpixel(
2432 x => ( clamp($gray) / $MAX_COLOR * ( $srcWidth - 1 ) ),
2433 y => $srcHeight - 1 - ( clamp($gray) / $MAX_COLOR * ( $srcHeight - 1 ) ),
2434 );
2435  
2436 0 $out->setpixel(
2437 x => $x,
2438 y => $y,
2439 color => $color
2440 );
2441 }
2442 }
2443  
2444 0 return $out;
2445 }
2446  
2447 1 ▶sub spirals {
Subroutine spirals: called CC=12 SCAR=27.5
Pod documented
2448 1 my %args = @_;
2449  
2450 1 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
100
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
2451 1 ▶ $args{freq} = $args{len} if !defined $args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"freq"} 1 0 1
2452  
2453 1 my $voronoi = $args{voronoi};
2454  
2455 1 %args = defaultArgs(%args);
2456  
2457 1 my $len = $args{freq};
2458  
2459 1 my $grid = grid( %args, len => $len, bias => 0 );
2460  
2461 1 my $half = $len / 2;
2462 1 my $radius = $half;
2463 0 ▶ my $rand = sub { ( rand() >= .5 ) ? 1 : -1 };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
rand() >= 0.5 ? : 0 0 0
2464  
2465 1 ▶ $args{amp} = $DEFAULT_AMP if !defined $args{amp};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"amp"} 0 1 1
2466  
2467 1 my $bias = $args{bias} * $MAX_COLOR;
2468 1 my $amp = $args{amp} * $MAX_COLOR;
2469  
2470 1 ▶ for ( my $n = 0 ; $n < sqrt($len) * 2 ; $n++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < CORE::sqrt($len) * 2) 8 1 9
2471 8 my ( $coils, $arms, $steps );
2472  
2473 8 ▶ if ($voronoi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($voronoi) { } 0 8 8
2474 0 $coils = 360;
2475 0 $arms = 1;
2476 0 $steps = $len * $len * 2;
2477 } else {
2478 8 $coils = int( rand(5) );
2479 8 $arms = int( rand(7) ) + 1;
2480 8 $steps = 180 + rand(180);
2481 }
2482  
2483 8 my $aroundStep = ( $coils / $steps );
2484 8 my $aroundRads = $aroundStep * 2 * ( 22 / 7 );
2485  
2486 8 my $centerX = rand($len);
2487 8 my $centerY = rand($len);
2488  
2489 8 my $rotation = rand() * 2 * 22 / 7;
2490  
2491 8 ▶ for ( my $i = 1 ; $i <= $steps ; $i += 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $steps) 2366 8 2374
2492 2366 my $away = $radius**( $i / $steps );
2493  
2494 2366 ▶ for ( my $r = 0 ; $r < $arms ; $r += 1 / $arms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r < $arms) 53983 2366 56349
2495 53983 my $around = ( $i * $aroundRads ) + $rotation + ( $r * 2 * ( 22 / 7 ) );
2496  
2497 53983 my $x = ( $centerX + cos($around) * $away ) % $len;
2498 53983 my $y = ( $centerY + sin($around) * $away ) % $len;
2499  
2500 53983 my $column = $grid->[$x];
2501 53983 my $color = $MAX_COLOR - ( ( ( $i - 1 ) / ( $steps - 1 ) ) * $MAX_COLOR );
2502  
2503 53983 ▶ if ( $column->get($y) < $color ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($column->get($y) < $color) 442 53541 53983
2504 442 $column->set( $y, $color );
2505 }
2506 }
2507 }
2508  
2509 8 $grid->[$centerX]->set( $centerY, $MAX_COLOR );
2510 }
2511  
2512 1 ▶ if ($voronoi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($voronoi) { } 0 1 1
2513 0 $grid = densemap($grid);
2514  
2515 0 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 0 0 0
2516 0 my $column = $grid->[$x];
2517  
2518 0 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 0 0 0
2519 0 $column->set( $y,
2520 $MAX_COLOR - ( ( $column->get($y) / $MAX_COLOR ) * $MAX_COLOR ) );
2521 }
2522 }
2523 } else {
2524 1 $grid = glow( $grid, %args );
2525 }
2526  
2527 1 return grow( $grid, %args );
2528 }
2529  
2530 1 ▶sub dla {
Subroutine dla: called CC=25 SCAR=34.9
Pod documented
2531 1 my %args = @_;
2532  
2533 1 ▶ $args{bias} ||= $DEFAULT_BIAS;
Condition33%1/3
$args{"bias"} ||= $Math::Fractal::Noisemaker::DEFAULT_BIAS
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{"bias"} ||= $Math::Fractal::Noisemaker::DEFAULT_BIAS
$args{"bias"} $Math::Fractal::Noisemaker::DEFAULT_BIAS
Truth table33%1/3
A ||= B
A= $args{"bias"}B= $Math::Fractal::Noisemaker::DEFAULT_BIAS
ABresult
1X1
011
000
2534 1 ▶ $args{amp} ||= $DEFAULT_AMP;
Condition33%1/3
$args{"amp"} ||= $Math::Fractal::Noisemaker::DEFAULT_AMP
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{"amp"} ||= $Math::Fractal::Noisemaker::DEFAULT_AMP
$args{"amp"} $Math::Fractal::Noisemaker::DEFAULT_AMP
Truth table33%1/3
A ||= B
A= $args{"amp"}B= $Math::Fractal::Noisemaker::DEFAULT_AMP
ABresult
1X1
011
000
2535 1 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
100
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
2536 1 ▶ $args{freq} ||= $DEFAULT_FREQ;
Condition33%1/3
$args{"freq"} ||= $Math::Fractal::Noisemaker::DEFAULT_FREQ
l!l&&r!l&&!r
010
MC/DC0%0/2
$args{"freq"} ||= $Math::Fractal::Noisemaker::DEFAULT_FREQ
$args{"freq"} $Math::Fractal::Noisemaker::DEFAULT_FREQ
Truth table33%1/3
A ||= B
A= $args{"freq"}B= $Math::Fractal::Noisemaker::DEFAULT_FREQ
ABresult
1X1
011
000
2537  
2538 1 %args = defaultArgs(%args);
2539  
2540 1 my $amp = $args{amp};
2541 1 my $len = $args{len};
2542 1 my $freq = $args{freq};
2543  
2544 1 my $grid;
2545  
2546 1 ▶ if ( $args{in} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'in'}) { } 1 0 1
2547 1 $grid = infile( %args, len => $len );
2548 } else {
2549 0 $grid = grid( %args, bias => 0 );
2550  
2551 0 ▶ if ( $args{points} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'points'}) { } 0 0 0
2552 0 for ( @{$args{points}} ) {
2553 0 $grid->[ $_->[0] % $len ]->set($_->[1] % $len, $amp);
2554 }
2555 } else {
2556 0 ▶ for ( my $i = 0 ; $i <= $freq; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $freq) 0 0 0
2557 0 $grid->[ rand($len) ]->set(rand($len), $amp);
2558 }
2559 }
2560 }
2561  
2562 1 my @points;
2563  
2564 1 my $branches = $len * $len / 4;
2565  
2566 1 ▶ for ( my $i = 0 ; $i < $branches ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $branches) 64 1 65
2567 64 push @points, [ rand($len), rand($len) ];
2568 }
2569  
2570 1 my $prev = 0;
2571  
2572 1 my $buf = $|;
2573 1 $| = 1;
2574  
2575 1 ▶ while (@points) {
Branch: 1 branch
BranchTrueFalseTotal
if (@points) 6 0 6
2576 6 my $color = ( @points / $branches ) * $MAX_COLOR;
2577  
2578 6 ▶ print scalar(@points) . " " if !$QUIET && ( $prev != @points );
Branch: 1 branch
BranchTrueFalseTotal
if not $Math::Fractal::Noisemaker::QUIET and $prev != @points 0 6 6
Condition33%1/3
not $Math::Fractal::Noisemaker::QUIET and $prev != @points
!ll&&!rl&&r
600
MC/DC0%0/2
not $Math::Fractal::Noisemaker::QUIET and $prev != @points
not $Math::Fractal::Noisemaker::QUIET $prev != @points
Truth table33%1/3
not(A) and B
A= not $Math::Fractal::Noisemaker::QUIETB= $prev != @points
ABresult
0X0
100
111
2579  
2580 6 $prev = scalar(@points);
2581  
2582 6 my @newPoints;
2583  
2584 6 ▶ for ( my $i = 0 ; $i < @points ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @points) 79 6 85
2585 79 my $x = $points[$i]->[0] % $len;
2586 79 my $y = $points[$i]->[1] % $len;
2587  
2588 79 my $column = $grid->[$x];
2589  
2590 79 ▶ if ( ( $column->get($y) )
Branch: 1 branch
BranchTrueFalseTotal
if ($column->get($y) or $$grid[($x + 1) % $len]->get($y) or $$grid[($x - 1) % $len]->get($y) or $column->get(($y + 1) % $len) or $column->get(($y - 1) % $len) or $$grid[($x + 1) % $len]->get(($y + 1) % $len) or $$grid[($x + 1) % $len]->get(($y - 1) % $len) or $$grid[($x - 1) % $len]->get(($y - 1) % $len) or $$grid[($x - 1) % $len]->get(($y + 1) % $len)) { } 64 15 79
Condition95%23/24
$column->get($y) or $$grid[($x + 1) % $len]->get($y) or $$grid[($x - 1) % $len]->get($y) or $column->get(($y + 1) % $len) or $column->get(($y - 1) % $len) or $$grid[($x + 1) % $len]->get(($y + 1) % $len) or $$grid[($x + 1) % $len]->get(($y - 1) % $len) or $$grid[($x - 1) % $len]->get(($y - 1) % $len) or $$grid[($x - 1) % $len]->get(($y + 1) % $len)
l!l&&r!l&&!r
63115
$column->get($y) or $$grid[($x + 1) % $len]->get($y) or $$grid[($x - 1) % $len]->get($y) or $column->get(($y + 1) % $len) or $column->get(($y - 1) % $len) or $$grid[($x + 1) % $len]->get(($y + 1) % $len) or $$grid[($x + 1) % $len]->get(($y - 1) % $len) or $$grid[($x - 1) % $len]->get(($y - 1) % $len)
l!l&&r!l&&!r
62116
$column->get($y) or $$grid[($x + 1) % $len]->get($y) or $$grid[($x - 1) % $len]->get($y) or $column->get(($y + 1) % $len) or $column->get(($y - 1) % $len) or $$grid[($x + 1) % $len]->get(($y + 1) % $len) or $$grid[($x + 1) % $len]->get(($y - 1) % $len)
l!l&&r!l&&!r
62017
$column->get($y) or $$grid[($x + 1) % $len]->get($y) or $$grid[($x - 1) % $len]->get($y) or $column->get(($y + 1) % $len) or $column->get(($y - 1) % $len) or $$grid[($x + 1) % $len]->get(($y + 1) % $len)
l!l&&r!l&&!r
61117
$column->get($y) or $$grid[($x + 1) % $len]->get($y) or $$grid[($x - 1) % $len]->get($y) or $column->get(($y + 1) % $len) or $column->get(($y - 1) % $len)
l!l&&r!l&&!r
60118
$column->get($y) or $$grid[($x + 1) % $len]->get($y) or $$grid[($x - 1) % $len]->get($y) or $column->get(($y + 1) % $len)
l!l&&r!l&&!r
59119
$column->get($y) or $$grid[($x + 1) % $len]->get($y) or $$grid[($x - 1) % $len]->get($y)
l!l&&r!l&&!r
56320
$column->get($y) or $$grid[($x + 1) % $len]->get($y)
l!l&&r!l&&!r
51523
MC/DC88%8/9
$column->get($y) or $$grid[($x + 1) % $len]->get($y) or $$grid[($x - 1) % $len]->get($y) or $column->get(($y + 1) % $len) or $column->get(($y - 1) % $len) or $$grid[($x + 1) % $len]->get(($y + 1) % $len) or $$grid[($x + 1) % $len]->get(($y - 1) % $len) or $$grid[($x - 1) % $len]->get(($y - 1) % $len) or $$grid[($x - 1) % $len]->get(($y + 1) % $len)
$column->get($y) $$grid[($x + 1) % $len]->get($y) $$grid[($x - 1) % $len]->get($y) $column->get(($y + 1) % $len) $column->get(($y - 1) % $len) $$grid[($x + 1) % $len]->get(($y + 1) % $len) $$grid[($x + 1) % $len]->get(($y - 1) % $len) $$grid[($x - 1) % $len]->get(($y - 1) % $len) $$grid[($x - 1) % $len]->get(($y + 1) % $len)
Truth table90%9/10
A or B or C or D or E or F or G or H or I
A= $column->get($y)B= $$grid[($x + 1) % $len]->get($y)C= $$grid[($x - 1) % $len]->get($y)D= $column->get(($y + 1) % $len)E= $column->get(($y - 1) % $len)F= $$grid[($x + 1) % $len]->get(($y + 1) % $len)G= $$grid[($x + 1) % $len]->get(($y - 1) % $len)H= $$grid[($x - 1) % $len]->get(($y - 1) % $len)I= $$grid[($x - 1) % $len]->get(($y + 1) % $len)
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
000001XXX1
0000001XX1
00000001X1
0000000011
0000000000
2591 || ( $grid->[ ( $x + 1 ) % $len ]->get($y) )
2592 || ( $grid->[ ( $x - 1 ) % $len ]->get($y) )
2593 || ( $column->get( ( $y + 1 ) % $len ) )
2594 || ( $column->get( ( $y - 1 ) % $len ) )
2595 || ( $grid->[ ( $x + 1 ) % $len ]->get( ( $y + 1 ) % $len ) )
2596 || ( $grid->[ ( $x + 1 ) % $len ]->get( ( $y - 1 ) % $len ) )
2597 || ( $grid->[ ( $x - 1 ) % $len ]->get( ( $y - 1 ) % $len ) )
2598 || ( $grid->[ ( $x - 1 ) % $len ]->get( ( $y + 1 ) % $len ) ) )
2599 {
2600 64 $column->set( $y, $color );
2601 } else {
2602 15 push @newPoints, [ $x, $y ];
2603 }
2604 }
2605  
2606 6 @points = @newPoints;
2607  
2608 6 ▶ last if !@points;
Branch: 1 branch
BranchTrueFalseTotal
unless @points 1 5 6
2609  
2610 5 ▶ for ( my $i = 0 ; $i < @points ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @points) 15 5 20
2611 15 my $x = $points[$i]->[0] % $len;
2612 15 my $y = $points[$i]->[1] % $len;
2613  
2614 15 my $offset = rand(6) - 3;
2615 15 $points[$i]->[0] = $x + $offset % $len;
2616  
2617 15 $offset = rand(6) - 3;
2618 15 $points[$i]->[1] = $y + $offset % $len;
2619 }
2620 }
2621  
2622 1 $| = $buf;
2623  
2624 1 return grow($grid, %args);
2625 }
2626  
2627  
2628 9 ▶sub glow {
Subroutine glow: called CC=4 SCAR=13.9
Pod undocumented
2629 9 my $grid = shift;
2630 9 my %args = @_;
2631  
2632 9 ▶ my $len = $args{len} || $DEFAULT_LEN;
Condition33%1/3
$args{'len'} || $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
900
MC/DC0%0/2
$args{'len'} || $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{'len'} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A || B
A= $args{'len'}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
2633  
2634 9 my $down = shrink($grid, len => $len/2);
2635 9 $down = smooth($down, len => $len/2);
2636 9 my $smoothed = grow($down, len => $len);
2637  
2638 9 ▶ for ( my $x = 0; $x < $len; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 144 9 153
2639 144 my $column = $grid->[$x];
2640 144 my $smoothedColumn = $smoothed->[$x];
2641  
2642 144 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 2304 144 2448
2643 2304 $smoothedColumn->set( $y, $smoothedColumn->get($y) + $column->get($y) );
2644 }
2645 }
2646  
2647 9 return $smoothed;
2648 }
2649  
2650 1 ▶sub tesla {
Subroutine tesla: called CC=2 SCAR=7.1
Pod documented
2651 1 my %args = @_;
2652  
2653 1 ▶ $args{freq} ||= 8;
Condition50%1/2
$args{"freq"} ||= 8
l!l
01
MC/DC0%0/1
$args{"freq"} ||= 8
$args{"freq"}
Truth table50%1/2
A
A= $args{"freq"}
Aresult
11
00
2654  
2655 1 return fur( %args, tesla => 1 );
2656 }
2657  
2658 2 ▶sub fur {
Subroutine fur: called CC=9 SCAR=22.0
Pod documented
2659 2 my %args = @_;
2660  
2661 # $args{octaves} = 4 if !defined $args{octaves};
2662 2 ▶ $args{freq} = 2 if !defined $args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"freq"} 1 1 2
2663  
2664 2 my $multires = multires( %args, amp => 1, bias => 0 );
2665 2 my $grid = grid(%args);
2666  
2667 2 ▶ my $len = $args{len} || $DEFAULT_LEN;
Condition33%1/3
$args{'len'} || $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
200
MC/DC0%0/2
$args{'len'} || $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{'len'} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A || B
A= $args{'len'}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
2668  
2669 2 %args = defaultArgs(%args);
2670  
2671 2 my @worms;
2672  
2673 2 my ( $numWorms, $threadLen );
2674  
2675 2 ▶ if ( $args{tesla} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'tesla'}) { } 1 1 2
2676 1 $numWorms = $len;
2677 1 $threadLen = $len;
2678 } else {
2679 1 $numWorms = $len * $len;
2680 1 $threadLen = sqrt($len);
2681 }
2682  
2683 2 ▶ for ( my $i = 0 ; $i < $numWorms ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numWorms) 272 2 274
2684 272 my $worm = [ rand($len), rand($len) ];
2685  
2686 272 push @worms, $worm;
2687 }
2688  
2689 2 ▶ for ( my $i = 0 ; $i < $threadLen ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $threadLen) 20 2 22
2690 20 my $w = 0;
2691  
2692 20 for my $worm (@worms) {
2693 1280 my $x = $worm->[0];
2694 1280 my $y = $worm->[1];
2695  
2696 1280 my $multiresColumn = $multires->[$x];
2697 1280 my $column = $grid->[$x];
2698  
2699 1280 my $heading = ( $multiresColumn->get($y) / $MAX_COLOR ) * 360;
2700  
2701 1280 ▶ if ( $args{tesla} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"tesla"}) 256 1024 1280
2702 ### kink it up
2703 256 $heading += ( $w / $numWorms ) * 45;
2704 }
2705  
2706 1280 $column->set( $y,
2707 $column->get($y) + 1 -
2708 ( abs( $i - ( $threadLen / 2 ) ) / ( $threadLen / 2 ) ) );
2709  
2710 1280 ( $x, $y ) = translate( $x, $y, $heading, 1 );
2711 1280 $x = ( $x * 100 ) % ( $len * 100 );
2712 1280 $y = ( $y * 100 ) % ( $len * 100 );
2713 1280 $worm->[0] = $x / 100;
2714 1280 $worm->[1] = $y / 100;
2715  
2716 1280 $w++;
2717 }
2718 }
2719  
2720 2 $grid = densemap( $grid );
2721  
2722 2 ▶ if ( $args{tesla} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"tesla"}) 1 1 2
2723 1 $grid = glow( $grid, %args );
2724 }
2725  
2726 2 return $grid;
2727 }
2728  
2729 0 ▶sub emboss {
Subroutine emboss: not called CC=4 SCAR=30.0
Pod documented
2730 0 my $grid = shift;
2731 0 my %args = @_;
2732  
2733 0 my $xlen = scalar @$grid;
2734 0 my $ylen = $grid->[0]->len();
2735  
2736 0 ▶ print "Generating light map\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 0 0
2737  
2738 0 my $lightmap = [];
2739  
2740 0 my $angle = rand(360);
2741  
2742 0 ▶ for ( my $x = 0 ; $x < $xlen ; $x += 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $xlen) 0 0 0
2743 0 $lightmap->[$x] = [];
2744  
2745 0 my $lightmapColumn = $COLUMN_CLASS->new($ylen);
2746 0 my $column = $grid->[$x];
2747  
2748 0 ▶ for ( my $y = 0 ; $y < $ylen; $y += 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $ylen) 0 0 0
2749 0 my $value;
2750  
2751 0 my ( $neighborX, $neighborY ) = translate( $x, $y, $angle, 1.5 );
2752  
2753 0 my $neighbor = noise( $grid, $neighborX, $neighborY );
2754  
2755 0 my $diff = $column->get($y) - $neighbor;
2756  
2757 0 $lightmapColumn->set( $y, $MAX_COLOR - $diff );
2758 }
2759  
2760 0 $lightmap->[$x] = $lightmapColumn;
2761 }
2762  
2763 0 return grow($lightmap,%args);
2764 }
2765  
2766 #
2767 # Make a seamless tile from non-seamless input, such as an infile
2768 #
2769 9 ▶sub tile {
Subroutine tile: called CC=19 SCAR=29.5
Pod documented
2770 9 my $grid = shift;
2771 9 my %args = @_;
2772  
2773 9 ▶ my $dirs = defined $args{tile} ? $args{tile} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'tile'} ? : 1 8 9
2774 9 ▶ return $grid if !$dirs;
Branch: 1 branch
BranchTrueFalseTotal
unless $dirs 1 8 9
2775  
2776 8 my $len = scalar( @{$grid} );
2777  
2778 8 my $out = grid( %args, len => $len );
2779  
2780 8 my $border = $len / 2;
2781  
2782 8 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 128 8 136
2783 128 my $outColumn = $out->[$x];
2784 128 my $column = $grid->[$x];
2785  
2786 128 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 2048 128 2176
2787 2048 $outColumn->set( $y, $column->get($y) );
2788 }
2789 }
2790  
2791 8 ▶ if ( $dirs == 1 || $dirs == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirs == 1 or $dirs == 2) 8 0 8
Condition33%1/3
$dirs == 1 or $dirs == 2
l!l&&r!l&&!r
800
MC/DC0%0/2
$dirs == 1 or $dirs == 2
$dirs == 1 $dirs == 2
Truth table33%1/3
A or B
A= $dirs == 1B= $dirs == 2
ABresult
1X1
011
000
2792 8 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 128 8 136
2793 128 my $outColumn = $out->[$x];
2794  
2795 128 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 2048 128 2176
2796 2048 my $thisX = ( $x - ( $len / 2 ) ) % $len;
2797  
2798 2048 my $blend = 1;
2799 2048 ▶ if ( $x < $border ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($x < $border) { } 1024 1024 2048
elsif ($len - $x < $border) { } 896 128 1024
2800 1024 $blend = 1 - ( ( $border - $x ) / $border );
2801 } elsif ( ( $len - $x ) < $border ) {
2802 896 $blend = ( $len - $x ) / $border;
2803 }
2804  
2805 2048 $outColumn->set( $y,
2806 interp( $out->[$thisX]->get($y), $outColumn->get($y), $blend ) );
2807 }
2808 }
2809  
2810 8 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 128 8 136
2811 128 my $outColumn = $grid->[$x];
2812 128 my $column = $out->[$x];
2813  
2814 128 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 2048 128 2176
2815 2048 $outColumn->set( $y, $column->get($y) );
2816 }
2817 }
2818 }
2819  
2820 8 ▶ if ( $dirs == 1 || $dirs == 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirs == 1 or $dirs == 3) 8 0 8
Condition33%1/3
$dirs == 1 or $dirs == 3
l!l&&r!l&&!r
800
MC/DC0%0/2
$dirs == 1 or $dirs == 3
$dirs == 1 $dirs == 3
Truth table33%1/3
A or B
A= $dirs == 1B= $dirs == 3
ABresult
1X1
011
000
2821 8 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 128 8 136
2822 128 my $outColumn = $out->[$x];
2823  
2824 128 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 2048 128 2176
2825 2048 my $thisX = $x;
2826 2048 my $thisY = ( $y - ( $len / 2 ) ) % $len;
2827  
2828 2048 my $blend = 1;
2829 2048 ▶ if ( $y < $border ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($y < $border) { } 1024 1024 2048
elsif ($len - $y < $border) { } 896 128 1024
2830 1024 $blend = 1 - ( ( $border - $y ) / $border );
2831 } elsif ( ( $len - $y ) < $border ) {
2832 896 $blend = ( $len - $y ) / $border;
2833 }
2834  
2835 2048 $outColumn->set( $y,
2836 interp( $out->[$thisX]->get($thisY), $outColumn->get($y), $blend ) );
2837 }
2838 }
2839 }
2840  
2841 8 return $out;
2842 }
2843  
2844 #
2845 # Translate X and Y coordinates according to heading by N units
2846 #
2847 5888 ▶sub translate {
Subroutine translate: called CC=10 SCAR=23.0
Pod undocumented
2848 5888 my $x = shift;
2849 5888 my $y = shift;
2850 5888 my $heading = shift; # Euler angle
2851 5888 my $units = shift; # Pixels
2852  
2853 #
2854 # A
2855 # |\
2856 # b | \ c
2857 # | \
2858 # |___\
2859 # C a B
2860 #
2861 #
2862 # 0
2863 # 3/NW | 0/NE
2864 # |
2865 # 270 ----+---- 90
2866 # |
2867 # 2/SW | 1/SE
2868 # 180
2869 #
2870  
2871 5888 my $quadrant = 0; # 0 NE, 1 SE, 2 SW, 3 NW
2872  
2873 5888 my $relativeHeading = $heading % 360;
2874  
2875 5888 ▶ if ( $relativeHeading == 0 ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($relativeHeading == 0) { } 74 5814 5888
elsif ($relativeHeading == 90) { } 71 5743 5814
elsif ($relativeHeading == 180) { } 78 5665 5743
elsif ($relativeHeading == 270) { } 68 5597 5665
2876 74 return $x, $y - $units;
2877 } elsif ( $relativeHeading == 90 ) {
2878 71 return $x + $units, $y;
2879 } elsif ( $relativeHeading == 180 ) {
2880 78 return $x, $y + $units;
2881 } elsif ( $relativeHeading == 270 ) {
2882 68 return $x - $units, $y;
2883 }
2884  
2885 5597 ▶ until ( $relativeHeading < 90 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($relativeHeading < 90) 8615 5597 14212
2886 8615 $relativeHeading -= 90;
2887  
2888 8615 $quadrant += 1;
2889 8615 ▶ $quadrant = 0 if $quadrant > 3;
Branch: 1 branch
BranchTrueFalseTotal
if $quadrant > 3 0 8615 8615
2890 }
2891  
2892 5597 my $c = $units;
2893 5597 my ( $b, $a );
2894  
2895 5597 my $A = $relativeHeading;
2896 5597 my $C = 90;
2897 5597 my $B = 180 - 90 - $heading;
2898  
2899 5597 my $rad = deg2rad($A);
2900 5597 $a = sin($rad) * $c;
2901 5597 $b = cos($rad) * $c;
2902  
2903 5597 ▶ if ( $quadrant == 0 ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($quadrant == 0) { } 1226 4371 5597
elsif ($quadrant == 1) { } 1679 2692 4371
elsif ($quadrant == 2) { } 1140 1552 2692
2904 1226 $x += $a;
2905 1226 $y -= $b;
2906 } elsif ( $quadrant == 1 ) {
2907 1679 $x += $b;
2908 1679 $y += $a;
2909 } elsif ( $quadrant == 2 ) {
2910 1140 $x -= $a;
2911 1140 $y += $b;
2912 } else {
2913 1552 $x -= $b;
2914 1552 $y -= $a;
2915 }
2916  
2917 5597 return $x, $y;
2918 }
2919  
2920 2 ▶sub moire {
Subroutine moire: called CC=5 SCAR=16.1
Pod documented
2921 2 my %args = @_;
2922  
2923 2 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
200
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
2924 2 my $len = $args{len};
2925  
2926 2 ▶ $args{freq} ||= 64;
Condition100%2/2
$args{"freq"} ||= 64
l!l
11
MC/DC100%1/1
$args{"freq"} ||= 64
$args{"freq"}
Truth table100%2/2
A
A= $args{"freq"}
Aresult
11
00
2927 2 my $freq = $args{freq};
2928  
2929 2 %args = defaultArgs(%args);
2930  
2931 2 my $grid = grid( %args, len => $len );
2932  
2933 # Magic number is magic
2934 2 my $scale = ( .842 * ( $len / $freq ) ) / 4;
2935  
2936 2 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 32 2 34
2937 32 my $column = $grid->[$x];
2938  
2939 32 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 512 32 544
2940 $column->set( $y,
2941 512 sin( ( $x / $scale ) * ( $y / $scale ) / 180 * pi ) * $args{bias} );
2942 }
2943 }
2944  
2945 2 $grid = tile( $grid, %args );
2946  
2947 2 $grid = glow( $grid, %args );
2948  
2949 2 return $grid;
2950 }
2951  
2952 1 ▶sub textile {
Subroutine textile: called CC=1 SCAR=0.0
Pod documented
2953 1 my %args = defaultArgs(@_);
2954  
2955 1 my $grid = moire(
2956 %args,
2957 freq => ( ( 1024 + rand(1024) ) * 2 ) + 1,
2958 square => 1,
2959 );
2960  
2961 1 return smooth( $grid, %args );
2962 }
2963  
2964 1 ▶sub sparkle {
Subroutine sparkle: called CC=5 SCAR=16.2
Pod documented
2965 1 my %args = @_;
2966  
2967 1 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
100
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
2968 1 ▶ $args{freq} = $args{len} if !defined $args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"freq"} 1 0 1
2969  
2970 1 my $stars = stars(%args);
2971 1 $stars = lsmooth( $stars, %args );
2972  
2973 1 my $stars0 = stars( %args, amp => .25 );
2974  
2975 1 %args = defaultArgs(%args);
2976  
2977 1 my $out = grid(%args);
2978  
2979 1 my $len = $args{len};
2980  
2981 1 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 16 1 17
2982 16 my $col0 = $stars0->[$x];
2983 16 my $col1 = $stars->[$x];
2984 16 my $outColumn = $out->[$x];
2985  
2986 16 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 256 16 272
2987 256 my $cv = $col0->get($y);
2988 256 my $sv = $col1->get($y);
2989  
2990 256 $outColumn->set( $y, $sv + $cv );
2991 }
2992 }
2993  
2994 1 return glow( $out, %args );
2995 }
2996  
2997 0 ▶sub delta {
Subroutine delta: not called CC=3 SCAR=24.8
Pod documented
2998 0 my $noise1 = shift;
2999 0 my $noise2 = shift;
3000  
3001 0 my %args = defaultArgs(@_);
3002  
3003 0 $noise1 = grow($noise1, %args);
3004 0 $noise2 = grow($noise2, %args);
3005  
3006 0 my $len = $args{len};
3007 0 my $grid = grid(%args);
3008  
3009 0 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 0 0 0
3010 0 my $column = $grid->[$x];
3011 0 my $n1col = $noise1->[$x];
3012 0 my $n2col = $noise2->[$x];
3013  
3014 0 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 0 0 0
3015 0 $column->set( $y, abs( $n1col->get($y) - $n2col->get($y) ) );
3016 }
3017 }
3018  
3019 0 return $grid;
3020 }
3021  
3022 0 ▶sub chiral {
Subroutine chiral: not called CC=4 SCAR=30.0
Pod documented
3023 0 my $noise1 = shift;
3024 0 my $noise2 = shift;
3025  
3026 0 my %args = defaultArgs(@_);
3027  
3028 0 $noise1 = grow($noise1, %args);
3029 0 $noise2 = grow($noise2, %args);
3030  
3031 0 my $len = $args{len};
3032 0 my $grid = grid(%args);
3033  
3034 0 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 0 0 0
3035 0 my $column = $grid->[$x];
3036 0 my $n1col = $noise1->[$x];
3037 0 my $n2col = $noise2->[$x];
3038  
3039 0 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 0 0 0
3040 0 ▶ if ( $n1col->get($y) > $n2col->get($y) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n1col->get($y) > $n2col->get($y)) { } 0 0 0
3041 0 $column->set( $y, $n1col->get($y) );
3042 } else {
3043 0 $column->set( $y, $n2col->get($y) );
3044 }
3045 }
3046 }
3047  
3048 0 return $grid;
3049 }
3050  
3051 0 ▶sub add {
Subroutine add: not called CC=3 SCAR=24.8
Pod undocumented
3052 0 my $noise1 = shift;
3053 0 my $noise2 = shift;
3054  
3055 0 my %args = defaultArgs(@_);
3056  
3057 0 $noise1 = grow($noise1, %args);
3058 0 $noise2 = grow($noise2, %args);
3059  
3060 0 my $len = $args{len};
3061 0 my $grid = grid(%args);
3062  
3063 0 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 0 0 0
3064 0 my $column = $grid->[$x];
3065 0 my $n1col = $noise1->[$x];
3066 0 my $n2col = $noise2->[$x];
3067  
3068 0 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 0 0 0
3069 0 $column->set( $y, $n1col->get($y) + $n2col->get($y) );
3070 }
3071 }
3072  
3073 0 return $grid;
3074 }
3075  
3076 0 ▶sub avg {
Subroutine avg: not called CC=3 SCAR=24.8
Pod undocumented
3077 0 my $noise1 = shift;
3078 0 my $noise2 = shift;
3079  
3080 0 my %args = defaultArgs(@_);
3081  
3082 0 $noise1 = grow($noise1, %args);
3083 0 $noise2 = grow($noise2, %args);
3084  
3085 0 my $len = $args{len};
3086 0 my $grid = grid(%args);
3087  
3088 0 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 0 0 0
3089 0 my $column = $grid->[$x];
3090 0 my $n1col = $noise1->[$x];
3091 0 my $n2col = $noise2->[$x];
3092  
3093 0 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 0 0 0
3094 0 $column->set( $y, lerp($n1col->get($y), $n2col->get($y), .5) );
3095 }
3096 }
3097  
3098 0 return $grid;
3099 }
3100  
3101 0 ▶sub stereo {
Subroutine stereo: not called CC=4 SCAR=30.0
Pod documented
3102 0 my $noise = shift;
3103 0 my %args = @_;
3104  
3105 0 ▶ my $len = $args{len} || $DEFAULT_LEN;
Condition0%0/3
$args{'len'} || $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'len'} || $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{'len'} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table0%0/3
A || B
A= $args{'len'}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
3106  
3107 0 %args = defaultArgs(%args);
3108  
3109 0 my $map = densemap( $noise );
3110 0 my $out = grid(%args);
3111  
3112 0 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 0 0 0
3113 0 my $outcol = $out->[ $x / 2 ];
3114 0 my $outcol2 = $out->[ ( $x + $len ) / 2 ];
3115 0 my $mapcol = $map->[$x];
3116  
3117 0 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 0 0 0
3118 0 my $offset = ( $mapcol->get($y) / $MAX_COLOR ) * 16;
3119  
3120 0 $outcol->set( $y,
3121 $outcol->get($y) + noise( $noise, $x - $offset, $y ) / 2 );
3122 0 $outcol2->set( $y,
3123 $outcol2->get($y) + noise( $noise, $x + $offset, $y ) / 2 );
3124 }
3125 }
3126  
3127 0 return $out;
3128 }
3129  
3130 #
3131 # Julia distance
3132 #
3133 512 ▶sub jdist {
Subroutine jdist: called CC=3 SCAR=11.0
Pod undocumented
3134 512 my $Zx = shift;
3135 512 my $Zy = shift;
3136 512 my $Cx = shift;
3137 512 my $Cy = shift;
3138 512 my $iter_max = shift;
3139  
3140 512 my $x = $Zx;
3141 512 my $y = $Zy;
3142 512 my $xp = 1;
3143 512 my $yp = 0;
3144 512 my $nz = 0;
3145 512 my $nzp = 0;
3146  
3147 512 ▶ for ( my $i = 0 ; $i < $iter_max ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $iter_max) 50629 13 50642
3148 50629 $nz = 2 * ( $x * $xp - $y * $yp ) + 1;
3149 50629 $yp = 2 * ( $x * $yp + $y * $xp );
3150 50629 $xp = $nz;
3151  
3152 50629 $nz = $x * $x - $y * $y + $Cx;
3153 50629 $y = 2 * $x * $y + $Cy;
3154 50629 $x = $nz;
3155  
3156 50629 $nz = $x * $x + $y * $y;
3157 50629 $nzp = $xp * $xp + $yp * $yp;
3158 50629 ▶ last if $nzp > 1e60;
Branch: 1 branch
BranchTrueFalseTotal
if $nzp > "1e+60" 499 50130 50629
3159 }
3160  
3161 512 my $a = sqrt($nz);
3162  
3163 512 return 2 * $a * log($a) / sqrt($nzp);
3164 }
3165  
3166 1 ▶sub djulia {
Subroutine djulia: called CC=2 SCAR=7.0
Pod documented
3167 1 my %args = @_;
3168  
3169 1 my $xstart = rand(.05) - .05;
3170 1 my $ystart = rand(.05) - .05;
3171  
3172 1 my $flen = .0125 + rand(.0125);
3173  
3174 1 ▶ $args{maxiter} ||= 4096;
Condition50%1/2
$args{"maxiter"} ||= 4096
l!l
01
MC/DC0%0/1
$args{"maxiter"} ||= 4096
$args{"maxiter"}
Truth table50%1/2
A
A= $args{"maxiter"}
Aresult
11
00
3175  
3176 1 return tile( julia(
3177 %args,
3178 ZxMin => $xstart,
3179 ZyMin => $ystart,
3180 ZxMax => $xstart + $flen,
3181 ZyMax => $ystart + $flen,
3182 ), %args );
3183 }
3184  
3185 2 ▶sub julia {
Subroutine julia: called CC=16 SCAR=27.8
Pod documented
3186 2 my %args = @_;
3187  
3188 2 local $COLUMN_CLASS = "Tie::CDoubleArray";
3189  
3190 2 ▶ print "Generating Julia...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 2 2
3191  
3192 2 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
200
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
3193 2 ▶ $args{freq} = $args{len} if !defined $args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"freq"} 2 0 2
3194  
3195 2 %args = defaultArgs(%args);
3196  
3197 2 my $len = $args{freq};
3198  
3199 2 my $grid = grid( %args, len => $len );
3200  
3201 2 my @c = (
3202 [ -.74543, .11301 ],
3203  
3204 # [ .285, .01 ],
3205 # [ -.8, .156 ],
3206 );
3207  
3208 2 my $c = $c[ rand(@c) ];
3209  
3210 2 my $Cx = $c->[0];
3211 2 my $Cy = $c->[1];
3212  
3213 # my $Cx = -0.74543;
3214 # my $Cy = 0.11301;
3215  
3216 2 my $iX = 0;
3217 2 my $iY = 0;
3218  
3219 2 my $ZxMin = $args{ZxMin};
3220 2 my $ZxMax = $args{ZxMax};
3221 2 my $ZyMin = $args{ZyMin};
3222 2 my $ZyMax = $args{ZyMax};
3223  
3224 2 ▶ $ZxMin = -2 if !defined $ZxMin;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ZxMin 1 1 2
3225 2 ▶ $ZxMax = 2 if !defined $ZxMax;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ZxMax 1 1 2
3226 2 ▶ $ZyMin = -2 if !defined $ZyMin;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ZyMin 1 1 2
3227 2 ▶ $ZyMax = 2 if !defined $ZyMax;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ZyMax 1 1 2
3228  
3229 # This is really low because this function is really slow
3230 2 ▶ my $iters = $args{maxiter} || ( $MAX_COLOR * .75 );
Condition66%2/3
$args{'maxiter'} || $MAX_COLOR * 0.75
l!l&&r!l&&!r
110
MC/DC0%0/2
$args{'maxiter'} || $MAX_COLOR * 0.75
$args{'maxiter'} $MAX_COLOR * 0.75
Truth table66%2/3
A || B
A= $args{'maxiter'}B= $MAX_COLOR * 0.75
ABresult
1X1
011
000
3231  
3232 # $len *= 2;
3233  
3234 2 my $pixelWidth = ( $ZxMax - $ZxMin ) / $len;
3235 2 my $pixelHeight = ( $ZyMax - $ZyMin ) / $len;
3236  
3237 2 my $Zx = 0;
3238 2 my $Zy = 0;
3239 2 my $Z0x = 0;
3240 2 my $Z0y = 0;
3241 2 my $Zx2 = 0;
3242 2 my $Zy2 = 0;
3243  
3244 2 my $escapeRadius = 400;
3245 2 my $ER2 = $escapeRadius * $escapeRadius;
3246  
3247 2 my $distanceMax = $pixelWidth / 15;
3248  
3249 2 my $i;
3250  
3251 2 ▶ for ( $iY = 0 ; $iY < $len ; $iY++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iY < $len) 32 2 34
3252 32 $Z0y = $ZyMax - $iY * $pixelHeight;
3253 32 ▶ if ( abs($Z0y) < $pixelHeight / 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $Z0y < $pixelHeight / 2) 1 31 32
3254 1 $Z0y = 0;
3255 }
3256 32 ▶ for ( $iX = 0 ; $iX < $len ; $iX++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iX < $len) 512 32 544
3257 512 $Z0x = $ZxMin + $iX * $pixelWidth;
3258 512 $Zx = $Z0x;
3259 512 $Zy = $Z0y;
3260 512 $Zx2 = $Zx * $Zx;
3261 512 $Zy2 = $Zy * $Zy;
3262  
3263 512 ▶ for ( $i = 1 ; $i <= $iters && ( $Zx2 + $Zy2 ) < $ER2 ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $iters and $Zx2 + $Zy2 < $ER2) 49005 512 49517
Condition100%3/3
$i <= $iters and $Zx2 + $Zy2 < $ER2
!ll&&!rl&&r
1349949005
MC/DC100%2/2
$i <= $iters and $Zx2 + $Zy2 < $ER2
$i <= $iters $Zx2 + $Zy2 < $ER2
Truth table100%3/3
A and B
A= $i <= $itersB= $Zx2 + $Zy2 < $ER2
ABresult
0X0
100
111
3264 49005 $Zy = 2 * $Zx * $Zy + $Cy;
3265 49005 $Zx = $Zx2 - $Zy2 + $Cx;
3266 49005 $Zx2 = $Zx * $Zx;
3267 49005 $Zy2 = $Zy * $Zy;
3268 }
3269  
3270 512 my $color;
3271  
3272 512 ▶ if ( $i == $iters ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $iters) { } 0 512 512
3273 0 $color = 0;
3274 } else {
3275 512 my $distance = jdist( $Z0x, $Z0y, $Cx, $Cy, $iters );
3276 512 ▶ if ( $distance < $distanceMax ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distance < $distanceMax) { } 292 220 512
3277 292 $color = $distanceMax - $distance;
3278 } else {
3279 220 $color = 0;
3280 }
3281 }
3282  
3283 512 my $column = $grid->[$iX];
3284 512 $column->set( $iY, $column->get($iY) + $color );
3285 }
3286 }
3287  
3288 2 $grid = densemap( $grid );
3289  
3290 2 return grow( $grid, %args );
3291 }
3292  
3293 1 my @roots = ( [ 1, 0 ], [ -.5, sqrt(3) / 2 ], [ -.5, sqrt(3) / 2 * -1 ], );
3294  
3295 256 ▶sub nclass {
Subroutine nclass: called CC=6 SCAR=17.9
Pod undocumented
3296 256 my $x = shift;
3297 256 my $y = shift;
3298 256 my $maxiter = shift;
3299  
3300 256 my $numRoots = scalar(@roots);
3301  
3302 256 my $z = cplx( $x, $y );
3303  
3304 256 my $prev = cplx( 0, 0 );
3305  
3306 256 my $t_numerator = cplx( 0, 0 );
3307 256 my $t_denominator = cplx( 0, 0 );
3308 256 my $t_rootDist = cplx( 0, 0 );
3309 256 my $t_prevRrootDist = cplx( 0, 0 );
3310  
3311 256 my $dist;
3312  
3313 256 ▶ for ( my $i = 0 ; $i < $maxiter ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $maxiter) 1098 16 1114
3314 1098 ▶ for ( my $r = 0 ; $r < $numRoots ; $r++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r < $numRoots) 3066 858 3924
3315 3066 $t_rootDist->_set_cartesian( $roots[$r] );
3316 3066 $t_rootDist -= $z;
3317  
3318 3066 $dist = abs($t_rootDist);
3319 3066 ▶ last if $dist == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $dist == 0 2 3064 3066
3320  
3321 3064 ▶ if ( $dist <= .25 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist <= "0.25") 238 2826 3064
3322 238 $t_prevRrootDist->_set_cartesian( $roots[$r] );
3323 238 $t_rootDist -= $prev;
3324  
3325 238 my $lnPrevRrootDist = log( abs($t_prevRrootDist) );
3326  
3327 238 my $coded =
3328 ( log(.25) - $lnPrevRrootDist ) / ( log($dist) - $lnPrevRrootDist );
3329  
3330 238 $coded = $coded - int($coded);
3331 238 $coded = $r + $coded;
3332  
3333 # return $coded;
3334 238 return $i / $maxiter + $coded;
3335 }
3336 }
3337  
3338 860 ▶ if ( $z == $prev ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($z == $prev) 2 858 860
3339 2 return -1;
3340 }
3341  
3342 858 $t_numerator = $z;
3343 858 $t_numerator**= 3;
3344 858 $t_numerator *= 2;
3345 858 $t_numerator += 1;
3346  
3347 858 $t_denominator = $z;
3348 858 $t_denominator**= 2;
3349 858 $t_denominator *= 3;
3350  
3351 858 $prev = $z;
3352  
3353 858 $z = $t_numerator / $t_denominator;
3354 }
3355  
3356 16 return -1;
3357 }
3358  
3359 1 ▶sub newton {
Subroutine newton: called CC=11 SCAR=24.5
Pod documented
3360 1 my %args = @_;
3361  
3362 eval {
3363 1 ▶ use Math::Complex;
Subroutine BEGIN: called CC=1 SCAR=0.0
3364 1 };
3365  
3366 1 ▶ print "Generating Newton...\n" if !$QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Math::Fractal::Noisemaker::QUIET 0 1 1
3367  
3368 1 ▶ $args{len} ||= $DEFAULT_LEN;
Condition33%1/3
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
100
MC/DC0%0/2
$args{"len"} ||= $Math::Fractal::Noisemaker::DEFAULT_LEN
$args{"len"} $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A ||= B
A= $args{"len"}B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
3369 1 ▶ $args{freq} = $args{len} if !defined $args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"freq"} 1 0 1
3370  
3371 1 %args = defaultArgs(%args);
3372  
3373 1 my $len = $args{freq};
3374  
3375 1 my $ZxMin = $args{ZxMin};
3376 1 my $ZxMax = $args{ZxMax};
3377 1 my $ZyMin = $args{ZyMin};
3378 1 my $ZyMax = $args{ZyMax};
3379  
3380 1 ▶ $ZxMin = -2 if !defined $ZxMin;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ZxMin 1 0 1
3381 1 ▶ $ZxMax = 2 if !defined $ZxMax;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ZxMax 1 0 1
3382 1 ▶ $ZyMin = -2 if !defined $ZyMin;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ZyMin 1 0 1
3383 1 ▶ $ZyMax = 2 if !defined $ZyMax;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ZyMax 1 0 1
3384  
3385 1 ▶ my $iters = $args{maxiter} || 10;
Condition50%1/2
$args{'maxiter'} || 10
l!l
01
MC/DC0%0/1
$args{'maxiter'} || 10
$args{'maxiter'}
Truth table50%1/2
A
A= $args{'maxiter'}
Aresult
11
00
3386  
3387 1 my $grid = grid( %args, len => $len );
3388  
3389 1 my $pixelWidth = ( $ZxMax - $ZxMin ) / $len;
3390 1 my $pixelHeight = ( $ZyMax - $ZyMin ) / $len;
3391  
3392 1 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 16 1 17
3393 16 my $zx = $ZxMin + $x * $pixelWidth;
3394  
3395 16 my $column = $grid->[$x];
3396  
3397 16 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 256 16 272
3398 256 my $zy = $ZyMin + $y * $pixelHeight;
3399  
3400 256 my $result = nclass( $zx, $zy, $iters );
3401  
3402 256 $column->set( $y, $result * $MAX_COLOR / 2 );
3403 }
3404  
3405 16 printRow( $grid->[$x] );
3406 }
3407  
3408 1 $grid = grow( $grid, %args );
3409  
3410 1 return $grid;
3411 }
3412  
3413 1 ▶sub lumber {
Subroutine lumber: called CC=3 SCAR=11.0
Pod documented
3414 1 my %args = defaultArgs(@_);
3415  
3416 1 my $multires = multires( %args, octaves => 3, freq => 2, amp => 4 );
3417 1 my $grid = grid(%args);
3418  
3419 1 my $len = $args{len};
3420  
3421 1 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 16 1 17
3422 16 my $column = $grid->[$x];
3423 16 my $multiresColumn = $multires->[$x];
3424  
3425 16 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 256 16 272
3426 256 my $gray = noise( $multires, $x, 0 ) / 4;
3427  
3428 256 $column->set( $y,
3429 ( noise( $multires, $gray, $y ) + $multiresColumn->get($y) )
3430 % $MAX_COLOR );
3431 }
3432 }
3433  
3434 1 return glow($grid, %args);
3435 }
3436  
3437 #
3438 # I heartily endorse this event or product
3439 #
3440 1 ▶sub wormhole {
Subroutine wormhole: called CC=6 SCAR=18.0
Pod documented
3441 1 my %args = @_;
3442  
3443 1 ▶ $args{octaves} = 3 if !$args{octaves};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"octaves"} 1 0 1
3444 1 ▶ $args{freq} = 2 if !$args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"freq"} 1 0 1
3445 1 ▶ $args{amp} = 4 if !$args{amp};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"amp"} 1 0 1
3446  
3447 1 %args = defaultArgs(%args);
3448  
3449 1 my $len = $args{len} * 2;
3450 1 my $dist = sqrt($len);
3451  
3452 1 my $grid = grid( %args, bias => 0, len => $len );
3453 1 my $multires = multires( %args, len => $len );
3454  
3455 1 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 32 1 33
3456 32 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 1024 32 1056
3457 1024 my $amp = noise( $multires, $x, $y, $len ) / $MAX_COLOR;
3458  
3459 1024 do {
3460 1024 my ( $thisX, $thisY ) = translate( $x, $y, $amp * 360, $amp * $dist, );
3461  
3462 1024 $grid->[ $thisX % $len ]->set( $thisY % $len, abs($amp) );
3463 };
3464 }
3465 }
3466  
3467 1 $grid = shrink( $grid, %args );
3468  
3469 1 $grid = glow( $grid, %args );
3470  
3471 1 $grid = densemap( $grid );
3472  
3473 1 return $grid;
3474 }
3475  
3476 1 ▶sub flux {
Subroutine flux: called CC=10 SCAR=23.1
Pod documented
3477 1 my %args = @_;
3478  
3479 1 ▶ $args{len} = $DEFAULT_LEN if !$args{len};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"len"} 0 1 1
3480 1 ▶ $args{octaves} = 3 if !$args{octaves};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"octaves"} 1 0 1
3481 1 ▶ $args{freq} = 2 if !$args{freq};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"freq"} 1 0 1
3482  
3483 1 my $len = $args{len} * 2;
3484  
3485 1 ▶ $args{amp} = sqrt($len) * 2 if !$args{amp};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"amp"} 1 0 1
3486 1 ▶ $args{bias} = 0 if !$args{bias};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"bias"} 1 0 1
3487  
3488 1 my $dist = sqrt($len);
3489  
3490 1 %args = defaultArgs(%args);
3491  
3492 1 my $grid = grid( %args, bias => 0, len => $len );
3493  
3494 1 my $multires = multires( %args, freq => 2, len => $len );
3495  
3496 1 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 32 1 33
3497 32 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 1024 32 1056
3498 1024 my $amp = noise( $multires, $x, $y, $len ) / $MAX_COLOR;
3499  
3500 1024 do {
3501 1024 my $xAngle = xAngle( $multires, $x, $y );
3502 1024 my $yAngle = yAngle( $multires, $x, $y );
3503  
3504 1024 my $angle = sqrt( ( $xAngle**2 ) + ( $yAngle**2 ) );
3505  
3506 1024 my ( $thisX, $thisY ) =
3507 translate( $x, $y, $angle, ( $amp / $dist ) * $dist, );
3508  
3509 1024 $thisX %= $len;
3510 1024 $thisY %= $len;
3511  
3512 1024 my $column = $grid->[$thisX];
3513  
3514 1024 $column->set( $thisY, $column->get($thisY) + abs($amp) );
3515 };
3516 }
3517 }
3518  
3519 1 $grid = shrink( $grid, %args );
3520  
3521 1 $grid = glow( $grid, %args );
3522  
3523 1 $grid = densemap( $grid );
3524  
3525 1 ▶ for ( my $x = 0 ; $x < $len / 2 ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len / 2) 16 1 17
3526 16 my $column = $grid->[$x];
3527  
3528 16 ▶ for ( my $y = 0 ; $y < $len / 2 ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len / 2) 256 16 272
3529 256 $column->set( $y, $MAX_COLOR - $column->get($y) );
3530 }
3531 }
3532  
3533 1 return $grid;
3534 }
3535  
3536 1024 ▶sub xAngle {
Subroutine xAngle: called CC=1 SCAR=0.0
Pod undocumented
3537 1024 my $multires = shift;
3538 1024 my $x = shift;
3539 1024 my $y = shift;
3540  
3541 1024 my $left = noise( $multires, $x - 1, $y );
3542 1024 my $this = noise( $multires, $x, $y );
3543 1024 my $right = noise( $multires, $x + 1, $y );
3544  
3545 1024 my $delta = ( $left - $right ) / $MAX_COLOR;
3546  
3547 1024 return ( $delta * 360 );
3548 }
3549  
3550 1024 ▶sub yAngle {
Subroutine yAngle: called CC=1 SCAR=0.0
Pod undocumented
3551 1024 my $multires = shift;
3552 1024 my $x = shift;
3553 1024 my $y = shift;
3554  
3555 1024 my $up = noise( $multires, $x, $y - 1 );
3556 1024 my $this = noise( $multires, $x, $y );
3557 1024 my $down = noise( $multires, $x, $y + 1 );
3558  
3559 1024 my $delta = ( $up - $down ) / $MAX_COLOR;
3560  
3561 1024 return ( $delta * 360 );
3562 }
3563  
3564 1 ▶sub canvas {
Subroutine canvas: called CC=1 SCAR=0.0
Pod documented
3565 1 my %args = defaultArgs(@_);
3566  
3567 1 my $square = square( %args, smooth => 0 );
3568  
3569 $square =
3570 1 lsmooth( $square, %args, dirs => 4, angle => 90, rad => $args{len} / 16 );
3571  
3572 1 return $square;
3573 }
3574  
3575 #
3576 # Simplex gradient function
3577 #
3578 691 ▶sub _sgrad {
Subroutine _sgrad: called CC=5 SCAR=16.1
3579 691 my $hash = shift;
3580 691 my $x = shift;
3581 691 my $y = shift;
3582  
3583 691 my $h = $hash & 7;
3584  
3585 691 ▶ my $u = $h < 4 ? $x : $y;
Branch: 1 branch
BranchTrueFalseTotal
$h < 4 ? : 361 330 691
3586 691 ▶ my $v = $h < 4 ? $y : $x;
Branch: 1 branch
BranchTrueFalseTotal
$h < 4 ? : 361 330 691
3587  
3588 691 ▶ return ( ( $h & 1 ) ? $u * -1 : $u ) + ( ( $h & 2 ) ? $v * -1 : $v );
Branch: 2 branches
BranchTrueFalseTotal
$h & 1 ? : 254 437 691
$h & 2 ? : 341 350 691
3589 }
3590  
3591 1 my $F2 = 0.366025403;
3592 1 my $G2 = 0.211324865;
3593  
3594 #
3595 # Simplex noise lookup
3596 #
3597 272 ▶sub _snoise {
Subroutine _snoise: called CC=6 SCAR=17.9
3598 272 my $x = shift;
3599 272 my $y = shift;
3600 272 ▶ my $len = shift || $DEFAULT_LEN;
Condition33%1/3
shift() || $Math::Fractal::Noisemaker::DEFAULT_LEN
l!l&&r!l&&!r
27200
MC/DC0%0/2
shift() || $Math::Fractal::Noisemaker::DEFAULT_LEN
shift() $Math::Fractal::Noisemaker::DEFAULT_LEN
Truth table33%1/3
A || B
A= shift()B= $Math::Fractal::Noisemaker::DEFAULT_LEN
ABresult
1X1
011
000
3601  
3602 272 $x = ( ( $x * 1000 ) % ( $len * 1000 ) ) / 1000;
3603 272 $y = ( ( $y * 1000 ) % ( $len * 1000 ) ) / 1000;
3604  
3605 272 my ( $n0, $n1, $n2 );
3606  
3607 272 my $s = ( $x + $y ) * $F2;
3608 272 my $xs = $x + $s;
3609 272 my $ys = $y + $s;
3610  
3611 272 my $i = abs( int($xs) );
3612 272 my $j = abs( int($ys) );
3613  
3614 272 my $t = ( $i + $j ) * $G2;
3615 272 my $X0 = $i - $t;
3616 272 my $Y0 = $j - $t;
3617 272 my $x0 = $x - $X0;
3618 272 my $y0 = $y - $Y0;
3619  
3620 272 my ( $i1, $j1 );
3621  
3622 272 ▶ if ( $x0 > $y0 ) { $i1 = 1; $j1 = 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($x0 > $y0) { } 108 164 272
3623 164 else { $i1 = 0; $j1 = 1; }
3624  
3625 272 my $x1 = $x0 - $i1 + $G2;
3626 272 my $y1 = $y0 - $j1 + $G2;
3627 272 my $x2 = $x0 - 1 + 2 * $G2;
3628 272 my $y2 = $y0 - 1 + 2 * $G2;
3629  
3630 272 my $ii = $i % 256;
3631 272 my $jj = $j % 256;
3632  
3633 272 my $t0 = .5 - $x0 * $x0 - $y0 * $y0;
3634  
3635 272 ▶ if ( $t0 < 0 ) { $n0 = 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($t0 < 0) { } 17 255 272
3636 else {
3637 255 $t0 *= $t0;
3638 255 $n0 = $t0 * $t0 * _sgrad( $NUMS[ ( $ii + $NUMS[$jj] ) % 256 ], $x0, $y0 );
3639 }
3640  
3641 272 my $t1 = .5 - $x1 * $x1 - $y1 * $y1;
3642  
3643 272 ▶ if ( $t1 < 0 ) { $n1 = 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($t1 < 0) { } 80 192 272
3644 else {
3645 192 $t1 *= $t1;
3646 192 $n1 =
3647 $t1 * $t1 *
3648 _sgrad( $NUMS[ ( $ii + $i1 + $NUMS[ ( $jj + $j1 ) % 256 ] ) % 256 ],
3649 $x1, $y1 );
3650 }
3651  
3652 272 my $t2 = .5 - $x2 * $x2 - $y2 * $y2;
3653  
3654 272 ▶ if ( $t2 < 0 ) { $n2 = 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($t2 < 0) { } 28 244 272
3655 else {
3656 244 $t2 *= $t2;
3657 244 $n2 =
3658 $t2 * $t2 *
3659 _sgrad( $NUMS[ ( $ii + 1 + $NUMS[ ( $jj + 1 ) % 256 ] ) % 256 ],
3660 $x2, $y2 );
3661 }
3662  
3663 272 return ( $n0 + $n1 + $n2 );
3664 }
3665  
3666 2 ▶sub simplex {
Subroutine simplex: called CC=3 SCAR=11.0
Pod documented
3667 2 my %args = defaultArgs(@_);
3668  
3669 2 my $freq = $args{freq};
3670 2 my $len = $args{len};
3671 2 my $amp = $args{amp};
3672  
3673 2 my $grid = grid( %args, len => $len );
3674  
3675 2 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 20 2 22
3676 20 my $column = $grid->[$x];
3677  
3678 20 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 272 20 292
3679 272 my $thisX = ( $x / $len ) * $freq;
3680 272 my $thisY = ( $y / $len ) * $freq;
3681  
3682 272 $column->set( $y, _snoise( $thisX, $thisY, $len ) * $amp );
3683 }
3684 }
3685  
3686 2 return tile( $grid, %args );
3687 }
3688  
3689 1 ▶sub simplex2 {
Subroutine simplex2: called CC=1 SCAR=0.0
Pod documented
3690 1 my %args = defaultArgs(@_);
3691  
3692 1 my $grid = simplex( %args, len => $args{freq}, tile => 0 );
3693  
3694 1 return grow( $grid, %args );
3695 }
3696  
3697 0 ▶sub _test {
Subroutine _test: not called CC=3 SCAR=24.8
3698 0 my %args = defaultArgs(@_);
3699  
3700 0 my $grid = grid(%args);
3701  
3702 0 my $len = $args{len};
3703  
3704 0 ▶ for ( my $x = 0 ; $x < $len ; $x++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $len) 0 0 0
3705 0 ▶ for ( my $y = 0 ; $y < $len ; $y++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $len) 0 0 0
3706  
3707 }
3708 }
3709  
3710 0 return $grid;
3711 }
3712  
3713 1 our @chars = split( //, ' . .. .....:.::.:::::H:HH:HHHH#H##H#######');
3714  
3715 2080 ▶sub printRow {
Subroutine printRow: called CC=3 SCAR=21.6
Pod undocumented
3716 2080 ▶ return if $QUIET;
Branch: 1 branch
BranchTrueFalseTotal
if $Math::Fractal::Noisemaker::QUIET 2080 0 2080
3717  
3718 0 my $row = shift;
3719 0 my $len = $row->len();
3720  
3721 0 my $rows = 80;
3722 0 for my $i ( 0 .. $rows - 1 ) {
3723 0 my $pct = $i / $rows - 1;
3724 0 my $rowI = int( $pct * $len );
3725 0 my $val = $row->get( $rowI % $len );
3726  
3727 0 my $valPct = clamp($val) / $MAX_COLOR;
3728 0 my $char = $chars[ $valPct * ( @chars - 1 ) ];
3729  
3730 0 print $char;
3731 }
3732  
3733 0 print "\n";
3734 }
3735  
3736 0 ▶sub spamConsole {
Subroutine spamConsole: not called CC=3 SCAR=24.8
Pod undocumented
3737 0 my %args = @_;
3738  
3739 0 my $fmtstr = '%-10s %-10s %-10s %-10s %-4s %-4s %-4s %-4s %-4s';
3740  
3741 0 printf( $fmtstr, qw| type lbase ltype stype bias amp freq oct len | );
3742 0 print "\n";
3743  
3744 0 my $type = $args{type};
3745  
3746 0 ▶ if ( $type eq 'terra' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'terra') { } 0 0 0
elsif (grep {$_ eq $type;} @Math::Fractal::Noisemaker::PERLIN_TYPES) { } 0 0 0
3747 printf( $fmtstr,
3748 "terra", $args{lbase}, $args{ltype},
3749 $args{stype}, $args{bias}, $args{amp},
3750 $args{freq}, $args{octaves}, $args{len},
3751 0 );
3752 } elsif (
3753 grep {
3754 0 $_ eq $type
3755 } @PERLIN_TYPES
3756 )
3757 {
3758 printf( $fmtstr,
3759 $type, "n/a", "n/a",
3760 $args{stype}, $args{bias}, $args{amp},
3761 $args{freq}, $args{octaves}, $args{len},
3762 0 );
3763 } else {
3764 printf( $fmtstr,
3765 $type, "n/a", "n/a", "n/a", $args{bias},
3766 0 $args{amp}, $args{freq}, "n/a", $args{len}, );
3767 }
3768  
3769 0 print "\n";
3770 }
3771  
3772 1 1;
3773 __END__
↑ Summary