Hi folks,
I'm having some trouble allocating colors with GD. Right now, I have the following code:
my %angles; #I get angles from a file
my ($key1, $key2, @colors);
my ($i, $j) = 0;
my $red_val= 0;
my $yellow_val = 90;
my $green_val = 180;
my $angle;
my $im = new GD::Image (150, 1500);
foreach $key1 (sort (keys %angles)) {
foreach $key2 (sort (keys %{$angles{$key1}})) {
$angle = ${$angles{$key1}}{$key2}
if ($angle <= $yellow_val) {
$colors[$i]->[$j] = $im->colorAllocate(255, 255*(($ang
+le-$red_val)/($yellow_val-$red_val)), 0);
} else {
$colors[$i]->[$j] = $im->colorAllocate(255*(($green_v
+al - $angle)/($yellow_val - $red_val)), 255*(1-(1-($angle-$green_val)
+/($yellow_val-$green_val)))*.5, 0);
}
$j++;
}
$j = 0;
$i++;
}
My problem is that when I allocate all these colors (%angles contains about 1000 values) the $im turns a funny color, and I can't print anything. What I'm trying to do is print 1000 of these circles out onto a file and display it. Thanks for any help you can give!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.