[kansaipm] Re: 舟木さんへー株のPLOT

mishima at momo.so-net.ne.jp mishima at momo.so-net.ne.jp
Sat Apr 22 19:00:22 CDT 2000


三嶋です。

From: "ivanov simeon" <bate_simo at hotmail.com>
Subject: [kansaipm] 舟木さんへー株のPLOT
Date: Fri, 21 Apr 2000 18:14:39 JST

> たとえば、GD.pm とか、Image::Magickを使って、簡単な
> Graphicsは10分で出来ます。GD.pm はWindows
> の上で使えるかどうかがわかりませんけどImage::Magickは
> 絶対使える。Unicodeを使ったら、TTFフォント
> もつかえるから、株のtickerには十分と思います。

とりあえず、GD.pm を Win98SE+ActivePerl5.6 で試してみました。
TrueTypeFontも使えるし日本語(UTF8)もすんなり通りました。
インストールも PPM で簡単にできます。

C:\> set http_proxy=http://プロキシサーバ/
C:\> ppm
PPM> install GD

> Simple example code + image付

同じく。
-------------- next part --------------
A non-text attachment was scrubbed...
Name: chart.png
Type: image/png
Size: 1149 bytes
Desc: not available
Url : http://mail.pm.org/archives/kansai-pm/attachments/20000423/614ec98e/chart.png
-------------- next part --------------
use GD;
use Jcode;
my $font = 'c:/WINDOWS/FONTS/MSGOTHIC.TTC';
my ($width, $height, $old_x, $old_y, $max_x, $max_y);

# create a new image
$width = $height= 250;
my $img = new GD::Image($width,$height);
my $white = $img->colorAllocate(255,255,255);
my $black = $img->colorAllocate(0,0,0);       
my $red   = $img->colorAllocate(255,0,0);      
my $blue  = $img->colorAllocate(0,0,255);

# create a brush pattern
my $brush = new GD::Image(3,3);
$brush->filledRectangle(0,0,3,3,$brush->colorAllocate(255,255,0));
$img->setBrush($brush);

# data 
my @data = qw(1 1 2 1 3 3 5 3 6 4 7 4 8 1 9 10); #data as pairs x,y
$old_x = $old_y = 0; 
$max_x = $max_y = 10;

# plot
while (@data) {
	($x,$y) = splice @data, 0, 2, ();
	$x *= $width/$max_x; $y *= $height/$max_y;
	$y = $width - $y; # because the top-left coord of image is 0

	# draw line connecting points
	$img->line( $old_x, $old_y, $x, $y, gdBrushed );

	# draw the points
	$img->arc( $x, $y, 10, 10, 0, 360, $blue );
	$img->fillToBorder( $x, $y, $blue, $blue );

	$old_x = $x; $old_y = $y;
}

# put a title on the top of the image
$img->stringTTF($red, $font, 14, 0, $width/2-7, 14, jcode('株')->utf8);

binmode STDOUT;
print $img->png; # write out to STDOUT; You should redirect STDOUT to file.


More information about the Kansai-pm mailing list