Imagerで破線を表現する
昨日描いたグラフで破線が使いたくなったので、
目盛の一部を破線に変更してみた。
sub draw_graduation {
my ( $img, $color ) = @_;
$img->box( filled => 1, color => 'black' );
for ( 0..6 ) {
my $x = $x0 + ((($graph_width - 1) / 5) * $_);
$img->line(
x1 => $x, y1 => $y0,
x2 => $x, y2 => $y0 - (($graph_height - 1) * 1.2),
color => $color );
}
for ( 0..12 ) {
my $y = $y0 - ((SCALE_Y / 10) * $_);
my $x_end = $x0 + $graph_width - 1;
if ( $_ % 5 ) {
my $stroke = 3;
my $space = 3;
my ( $x1, $x2 ) = ( $x0, $x0 + $stroke );
while ( $x2 <= $x_end ) {
$img->line(
x1 => $x1, y1 => $y,
x2 => $x2 - 1, y2 => $y,
color => $color );
$x1 = $x2 + $space;
$x2 = $x1 + $stroke;
}
if ( $x1 < $x_end ) {
$img->line(
x1 => $x1, y1 => $y,
x2 => $x_end, y2 => $y,
color => $color );
}
}
else {
$img->line(
x1 => $x0, y1 => $y,
x2 => $x_end, y2 => $y,
color => $color );
}
}
}
一番下の関数を修正して、y軸の0.0と0.5と1.0を強調してみた。
どうせだったら、色も明るくした方が良かったかなって思う。
おしまい。

Leave a Comment