Colour bars/Display: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl}}: future-proof for 5.36, tidy code)
Line 1,486: Line 1,486:


=={{header|Perl}}==
=={{header|Perl}}==
<syntaxhighlight lang="perl">#!/usr/bin/perl -w
<syntaxhighlight lang="perl">use strict;
use strict ;
use warnings;
use GD ;
use GD;


my %colors = ( white => [ 255 , 255 , 255 ] , red => [255 , 0 , 0 ] ,
my %colors = (
green => [ 0 , 255 , 0 ] , blue => [ 0 , 0 , 255 ] ,
white => [255,255,255], red => [255, 0, 0], green => [ 0,255, 0], blue => [ 0, 0,255],
magenta => [ 255 , 0 , 255 ] , yellow => [ 255 , 255 , 0 ] ,
magenta => [255, 0,255], yellow => [255,255, 0], cyan => [ 0,255,255], black => [ 0, 0, 0]);

cyan => [ 0 , 255 , 255 ] , black => [ 0 , 0 , 0 ] ) ;
my $barwidth = 160 / 8 ;
my $start = 0;
my $image = new GD::Image( 160 , 100 ) ;
my $barwidth = 160 / 8;
my $start = 0 ;
my $image = GD::Image->new( 160 , 100 );

foreach my $rgb ( values %colors ) {
for my $rgb ( values %colors ) {
my $paintcolor = $image->colorAllocate( @$rgb ) ;
$image->filledRectangle( $start * $barwidth , 0 , $start * $barwidth +
$image->filledRectangle( $start * $barwidth , 0 , $start * $barwidth +
$barwidth - 1 , 99 , $paintcolor ) ;
$barwidth - 1 , 99 , $image->colorAllocate( @$rgb ) );
$start++ ;
$start++ ;
}
}
open ( DISPLAY , ">" , "testprogram.png" ) || die ;
open ( DISPLAY , ">" , "bars.png" ) or die;
binmode DISPLAY ;
binmode DISPLAY;
print DISPLAY $image->png ;
print DISPLAY $image->png;
close DISPLAY ;#to be watched with <image viewer> testprogram.png</syntaxhighlight>
close DISPLAY;</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==