| 1 | |||
| 2 | # styles for Points and LinesPoints classes | ||
| 3 | |||
| 4 | use v5.12; | ||
| 5 | |||
| 6 | package Chart::BrushStyles; | ||
| 7 | our $VERSION = 'v2.403.9'; | ||
| 8 | |||
| 9 | use Carp; | ||
| 10 | use GD; | ||
| 11 | use Chart::Constants; | ||
| 12 | use Chart::Base; | ||
| 13 | |||
| 14 | |||
| 15 | |||
| 16 | ## @fn OpenCircle | ||
| 17 | # @param[in] *GD::Image $rbrush Reference to GD::Image | ||
| 18 | # @param[in] int $radius Radius of the point in pixels | ||
| 19 | # @param[in] int $color | ||
| 20 | # | ||
| 21 | # @brief Set the gdBrush object to have nice brushed object | ||
| 22 | # representing a circle of the size \$radius. | ||
| 23 | # | ||
| 24 | # @details | ||
| 25 | # Called by\n | ||
| 26 | # use Chart::BrushStyles;\n | ||
| 27 | # \@Chart::Points::ISA = qw(Chart::BrushStyles);\n | ||
| 28 | # \$self->OpenCircle(\\\$rbrush,\$radius, \$newcolor);\n | ||
| 29 | # to plot the GD::Image representing an open circle as the point | ||
| 30 | # | ||
| 31 | sub OpenCircle | ||
| 32 | { | ||
| 33 | my $self = shift; | ||
| 34 | my $rbrush = shift; # reference to GD::Image | ||
| 35 | my $radius = shift; # radius of the point in pixels | ||
| 36 | my $color = shift; # Color of the not filled point | ||
| 37 | |||
| 38 | # draw a filled circle | ||
| 39 | if ( $radius < 2 ) { $radius = 2; } | ||
| 40 | |||
| 41 | $$rbrush->arc( $radius, $radius, $radius, $radius, 0, 360, $color ); | ||
| 42 | } | ||
| 43 | |||
| 44 | ## @fn FilledCircle | ||
| 45 | # @param[in] *GD::Image $rbrush Reference to GD::Image | ||
| 46 | # @param[in] int $radius Radius of the point in pixels | ||
| 47 | # @param[in] int $color Color of the filled point | ||
| 48 | # @return nothing | ||
| 49 | # | ||
| 50 | # @brief Set the gdBrush object to have nice brushed object | ||
| 51 | # representing a point of the size \$radius. | ||
| 52 | # | ||
| 53 | # @details | ||
| 54 | # Called by\n | ||
| 55 | # use Chart::BrushStyles;\n | ||
| 56 | # \@Chart::Points::ISA = qw(Chart::BrushStyles);\n | ||
| 57 | # \$self->FilledCircle(\\\$rbrush,\$radius, \$color);\n | ||
| 58 | # to plot the GD::Image representing a filled circle as the point | ||
| 59 | # | ||
| 60 | sub FilledCircle | ||
| 61 | { | ||
| 62 | my $self = shift; | ||
| 63 | my $rbrush = shift; # reference to GD::Image | ||
| 64 | my $radius = shift; | ||
| 65 | my $color = shift; | ||
| 66 | |||
| 67 | # draw a filled circle | ||
| 68 | if ( $radius < 2 ) { $radius = 2; } | ||
| 69 | |||
| 70 | $$rbrush->arc( $radius, $radius, $radius, $radius, 0, 360, $color ); | ||
| 71 | |||
| 72 | # and fill it | ||
| 73 | $$rbrush->fill( $radius, $radius, $color ); | ||
| 74 | } | ||
| 75 | |||
| 76 | ## @fn Star | ||
| 77 | # @param[in] *GD::Image $rbrush Reference to GD::Image | ||
| 78 | # @param[in] int $radius Radius of the star in pixels | ||
| 79 | # @param[in] int $color Color of the star | ||
| 80 | # @return nothing | ||
| 81 | # | ||
| 82 | # @brief Set the gdBrush object to have nice brushed object | ||
| 83 | # representing a star of the size \$radius. | ||
| 84 | # | ||
| 85 | # @details | ||
| 86 | # Called by\n | ||
| 87 | # use Chart::BrushStyles;\n | ||
| 88 | # \@Chart::Points::ISA = qw(Chart::BrushStyles);\n | ||
| 89 | # \$self->Star(\\\$rbrush,\$radius, \$color);\n | ||
| 90 | # to get back an GD::Image representing a star as the point | ||
| 91 | # | ||
| 92 | sub Star | ||
| 93 | { | ||
| 94 | my $self = shift; | ||
| 95 | my $rbrush = shift; # reference to GD::Image | ||
| 96 | my $radius = shift; | ||
| 97 | my $color = shift; | ||
| 98 | |||
| 99 | my $R = $self->maximum( 2, int( $radius + 0.5 ) ); | ||
| 100 | my $r = $self->maximum( 1, int( $R / 3 + 0.5 ) ); | ||
| 101 | my $lRadius = $R; | ||
| 102 | my $x1 = $lRadius + $R; # =$R*cos(0) + $R; | ||
| 103 | my $y1 = $R; # =$R*sin(0) + $R | ||
| 104 | my ( $x2, $y2 ); | ||
| 105 | |||
| 106 | for ( my $iAngleCounter = 1 ; $iAngleCounter < 16 ; $iAngleCounter++ ) | ||
| 107 | { | ||
| 108 | my $phi = $iAngleCounter * Chart::Constants::PI / 8; | ||
| 109 | $lRadius = ( ( $iAngleCounter & 1 ) == 0 ) ? $R : $r; | ||
| 110 | $x2 = $lRadius * cos($phi); | ||
| 111 | $y2 = $lRadius * sin($phi); | ||
| 112 | $x2 += $R; | ||
| 113 | $y2 += $R; | ||
| 114 | |||
| 115 | #printf("$iAngleCounter: %4f, %4f %4f,%4f\n", $x1,$y1,$x2,$y2); | ||
| 116 | $$rbrush->line( $x1, $y1, $x2, $y2, $color ); | ||
| 117 | |||
| 118 | $x1 = $x2; | ||
| 119 | $y1 = $y2; | ||
| 120 | } | ||
| 121 | |||
| 122 | # draw to the first point | ||
| 123 | $x2 = $R + $R; | ||
| 124 | $y2 = $R; | ||
| 125 | $$rbrush->line( $x1, $y1, $x2, $y2, $color ); | ||
| 126 | } | ||
| 127 | |||
| 128 | ## @fn FilledDiamond | ||
| 129 | # @param[in] *GD::Image $rbrush Reference to GD::Image | ||
| 130 | # @param[in] int $radius Radius of the diamond in pixels | ||
| 131 | # @param[in] int $color Color of the filled diamond | ||
| 132 | # @return nothing | ||
| 133 | # | ||
| 134 | # @brief Set the gdBrush object to have nice brushed object | ||
| 135 | # representing a filled diamond of the size \$radius. | ||
| 136 | # | ||
| 137 | # @details | ||
| 138 | # Called by\n | ||
| 139 | # use Chart::BrushStyles;\n | ||
| 140 | # \@Chart::Points::ISA = qw(Chart::BrushStyles);\n | ||
| 141 | # \$self->FilledDiamond(\\\$rbrush,\$radius, \$color);\n | ||
| 142 | # to get back an GD::Image representing a filled diamond as the point | ||
| 143 | # | ||
| 144 | sub FilledDiamond | ||
| 145 | { | ||
| 146 | my $self = shift; | ||
| 147 | my $rbrush = shift; # reference to GD::Image | ||
| 148 | my $radius = shift; | ||
| 149 | my $color = shift; | ||
| 150 | |||
| 151 | my $R = $self->maximum( 2, int( $radius + 0.5 ) ); | ||
| 152 | my $R2 = $R * 2; | ||
| 153 | $$rbrush->line( $R, 1, $R2 - 1, $R, $color ); | ||
| 154 | $$rbrush->line( $R2, $R, $R, $R2 - 1, $color ); | ||
| 155 | $$rbrush->line( $R, $R2 - 1, 1, $R, $color ); | ||
| 156 | $$rbrush->line( 1, $R, $R, 1, $color ); | ||
| 157 | |||
| 158 | # and fill it | ||
| 159 | $$rbrush->fill( $radius - 1, $radius - 1, $color ); | ||
| 160 | } | ||
| 161 | |||
| 162 | ## @fn OpenDiamond | ||
| 163 | # @param[in] *GD::Image $rbrush Reference to GD::Image | ||
| 164 | # @param[in] int $radius Radius of the diamond in pixels | ||
| 165 | # @param[in] int $color Color of the diamond | ||
| 166 | # @return nothing | ||
| 167 | # | ||
| 168 | # @brief Set the gdBrush object to have nice brushed object | ||
| 169 | # representing a diamond of the size \$radius-1. | ||
| 170 | # | ||
| 171 | # @details | ||
| 172 | # Called by\n | ||
| 173 | # use Chart::BrushStyles;\n | ||
| 174 | # \@Chart::Points::ISA = qw(Chart::BrushStyles);\n | ||
| 175 | # \$self->OpenDiamond(\\\$rbrush,\$radius, \$color);\n | ||
| 176 | # to get back an GD::Image representing a diamond as the point | ||
| 177 | # | ||
| 178 | sub OpenDiamond | ||
| 179 | { | ||
| 180 | my $self = shift; | ||
| 181 | my $rbrush = shift; # reference to GD::Image | ||
| 182 | my $radius = shift; | ||
| 183 | my $color = shift; | ||
| 184 | |||
| 185 | my $R = $self->maximum( 2, int( $radius + 0.5 ) ); | ||
| 186 | my $R2 = $R * 2; | ||
| 187 | $$rbrush->line( $R, 1, $R2 - 1, $R, $color ); | ||
| 188 | $$rbrush->line( $R2, $R, $R, $R2 - 1, $color ); | ||
| 189 | $$rbrush->line( $R, $R2 - 1, 1, $R, $color ); | ||
| 190 | $$rbrush->line( 1, $R, $R, 1, $color ); | ||
| 191 | } | ||
| 192 | |||
| 193 | ## @fn OpenRectangle | ||
| 194 | # @param[in] *GD::Image $rbrush Reference to GD::Image | ||
| 195 | # @param[in] int $radius Radius of the rectangle in pixels | ||
| 196 | # @param[in] int $color Color of the rectangle | ||
| 197 | # @return nothing | ||
| 198 | # | ||
| 199 | # @brief Set the gdBrush object to have nice brushed object | ||
| 200 | # representing a rectangle of the height \$radius-1 and width of $radius/2. | ||
| 201 | # | ||
| 202 | # @details | ||
| 203 | # Called by\n | ||
| 204 | # use Chart::BrushStyles;\n | ||
| 205 | # \@Chart::Points::ISA = qw(Chart::BrushStyles);\n | ||
| 206 | # \$self->OpenDiamond(\\\$rbrush,\$radius, \$color);\n | ||
| 207 | # to get back an GD::Image representing a rectangle as the point | ||
| 208 | # | ||
| 209 | sub OpenRectangle | ||
| 210 | { | ||
| 211 | my $self = shift; | ||
| 212 | my $rbrush = shift; # reference to GD::Image | ||
| 213 | my $radius = shift; | ||
| 214 | my $color = shift; | ||
| 215 | |||
| 216 | if ( $radius < 2 ) { $radius = 2; } | ||
| 217 | my $height = $radius; | ||
| 218 | my $width = $radius / 2; | ||
| 219 | if ( $width < 1 ) { $width = 1; } | ||
| 220 | |||
| 221 | # draw a filled circle | ||
| 222 | $$rbrush->line( -$width, -$height, $width, -$height, $color ); | ||
| 223 | |||
| 224 | #$$rbrush->line( $width, -$height, $width, $height, $color ); | ||
| 225 | #$$rbrush->line( $width, $height, -$width, $height, $color ); | ||
| 226 | #$$rbrush->line( -$width, $height, -$width ,-$height,$color ); | ||
| 227 | } | ||
| 228 | |||
| 229 | 1; |