DLA/GrowUp.pm untested

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 33 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 134 CC 6 SCAR 31.7
CC
6
Cov
0%
generate
42.0
new
2.0
BEGIN
2.0
CRAP 23.8
1 package Math::Fractal::DLA::GrowUp;
2
3 use Math::Fractal::DLA qw(:all);
4 use strict;
5 use warnings;
6 use Exporter;
7
8 our @ISA = qw(Math::Fractal::DLA Exporter);
9
10 our @EXPORT_OK = qw(generate);
11 our @EXPORT = qw();
12
13 our $VERSION = 0.21;
14
15 sub new
16 {
17 my $param = shift;
18 my $class = ref($param) || $param;
19 my $self = new Math::Fractal::DLA;
20 bless ($self,$class);
21 return $self;
22 } # new
23
24 sub generate
25 {
26 my $self = $_[0];
27
28 $self->addLogMessage("Fractal mode Grow Up");
29
30 my $width = $self->{IMG_WIDTH};
31 my $height = $self->{IMG_HEIGHT};
32 my $maxpoints = $self->{POINTS};
33 my $x = 0; my $y = 0;
34 my $setpoints = 0;
35 my $y_line = $height - 2;
36 my $color_interval = int($maxpoints / $self->{COLORS});
37 my $color_value = 0;
38
39 while ($setpoints < $maxpoints)
40 {
41 if (($setpoints % $color_interval) == 0)
42 { $color_value ++; $self->addLogMessage("New color $color_value after $setpoints points"); }
43
44 $x = sprintf("%.0f",rand($width));
45 $y = $y_line;
46 my $set = 0;
47 while ($set == 0)
48 {
49 if (($y == $height) ||
50 ($self->{MATRIX}->[$x][$y+1] > 0) ||
51 (($x > 0) && ($self->{MATRIX}->[$x-1][$y] > 0)) ||
52 (($x < $width) && ($self->{MATRIX}->[$x+1][$y] > 0)))
53 {
54 $set = 1; $setpoints ++;
55 $self->{MATRIX}->[$x][$y] = $color_value;
56 if (($y == $y_line) && ($y_line > 0)) { $y_line --; }
57 }
58 $y ++;
59
60 # Random to left or right
61 my $dir = $self->getDirection();
62 if (($x > 0) && (($dir == 0) || ($dir == 1))) { $x --; }
63 if (($x < $width) && (($dir == 2) || ($dir == 3))) { $x ++; }
64 }
65 }
66 $self->createImage();
67
68 } # generate
69
70 1;
71
72 __END__