[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] CGI-Images



Here is some code I found:

use GD;

# create a new image
$im = new GD::Image(100,100);

# allocate some colors
$white = $im->colorAllocate(255,255,255);
$black = $im->colorAllocate(0,0,0);
$red = $im->colorAllocate(255,0,0);
$green = $im->colorAllocate(0,255,0);
$blue = $im->colorAllocate(0,0,255);

# make the background transparent and interlaced
$im->transparent($white);
$im->interlaced('true');

# Put a black frame around the picture
#$im->rectangle(0,0,99,99,$black);

# Draw a blue oval
$im->arc(50,50,100,100,0,180,$red);  #represents 50%
$im->arc(50,50,100,100,180,234,$green);  #represents 15%
$im->arc(50,50,100,100,234,360,$blue);  #represents 35%

$im->line(50,50,25,25,$green);  #Can this be put in polar coordinates?

# And fill it with red
#$im->fill(50,50,$red); #How would I tell it to fill in the middle of a
particular segment?  Polar Coordinates?

# make sure we are writing to a binary stream
binmode STDOUT;

# Convert the image to GIF and print it on standard output
print $im->gif;


It works good for drawing boxes and circles.  Anyway, I am trying to
write a program that will produce a pie chart.
How do I go about drawing a line from the center of the circle to the
outside edge and stop at that point?  Is it possible to use polar
coordinates instead of the regular coordinates to draw the line?  Also,
with doing a fill command, can it also be done in polar coordinates as
well?  The data will be fluctuating on a regular bases.  I have looked
around and can not find any more info about this type of code.

An example set of data would be:

data1 = 50%
data2 = 15%
data3 = 35%

I am trying to take that data and produce a pie chart where 50% is red,
15% is green, and 35% is blue.  The data will vary.

Any help would be greatly appreciated.  Thanks in advance.

--
Michael D. Kirkpatrick
Vice-President
Web Builders Internet Services Inc.
http://www.webbuilders.com



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org