"John W. Krahn" wrote:
>
> Jenda Krynicky wrote:
> >
> > From: Konrad Foerstner <[EMAIL PROTECTED]>
> >
> > > I have a strange error in my script. It should
> > > paint a column of lines next to each other in
> > > colors which are determinated by a given sequence
> > > of letters. It works...but only to the position
> > > of 251. After this point all lines have the color
> > > of the line at position 251...even when I use
> > > a different letter sequence.
> > >
> > > Is this a sign? The 251? ;) Nope, any hints?
> > >
> > > Here is the basic sheme. I hope I did't kill
> > > an impotant detail.
> > >
> > >
> > > my $seq = $_[0];
> > > my @seq_s = split ('',$seq);
> > >
> > > my $length = length $seq;
> > >
> > > $pic_length = $length +100;
> > >
> > > my $img = new GD::Image($pic_length,30);
> > >
> > > for (my $pos = '0'; $pos < ($length-1); ++$pos)
> > > {
> > > my $aa = $seq_s[$pos];
> > >
> > > my $color;
> > >
> > > if ($aa eq 'A')
> > > {$color = $img->colorAllocate(255,0,0);}
> > > elsif ($aa eq 'B')
> > > {$color = $img->colorAllocate(255,0,0);}
> > > elsif ($aa eq 'C')
> > > {$color = $img->colorAllocate(0,0,255);}
> > > elsif ($aa eq 'D')
> > > {$color = $img->colorAllocate(0,0,255);}
> > >
> > > $img->line($pos,1,$pos,21,$color);
> > > }
> >
> > Why do you keep allocating colors you aready have?
> >
> > I would suggest something like this :
> >
> > %colors = (
> > 'A' => $img->colorAllocate(255,0,0),
> > 'B' => $img->colorAllocate(255,0,0),
> > 'C' => $img->colorAllocate(0,0,255),
> > 'D' => $img->colorAllocate(0,0,255),
> > );
> >
> > for (my $pos = '0'; $pos < ($length-1); ++$pos) {
> > my $aa = $seq_s[$pos];
> > my $color = $colors{$aa};
> > $img->line($pos,1,$pos,21,$color);
> > }
>
> my @seq_s = split //, $_[0];
> my $img = new GD::Image( @seq_s + 100, 30 );
> my %colors = (
> A => $img->colorAllocate( 255, 0, 0 ),
> B => $img->colorAllocate( 255, 0, 0 ),
> C => $img->colorAllocate( 0, 0, 255 ),
> D => $img->colorAllocate( 0, 0, 255 ),
> );
>
> for my $pos ( 0 .. @seq_s - 2 ) {
> $img->line( $pos, 1, $pos, 21, $colors{$seq_s[$pos]} );
> }
Or even: :-)
local $_ = shift;
my $img = new GD::Image( 100 + length, 30 );
my %colors = (
A => $img->colorAllocate( 255, 0, 0 ),
B => $img->colorAllocate( 255, 0, 0 ),
C => $img->colorAllocate( 0, 0, 255 ),
D => $img->colorAllocate( 0, 0, 255 ),
);
$img->line( pos()-1, 1, pos()-1, 21, $colors{$1} ) while /(.)(?=..)/g;
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]