Colour bars/Display: Difference between revisions

Content added Content deleted
m (→‎{{header|Go}}: Removed top and bottom blank lines from code window.)
m (→‎{{header|Perl 6}}: proper error message on file open failure, style tweaks)
Line 984: Line 984:
close DISPLAY ;#to be watched with <image viewer> testprogram.png</lang>
close DISPLAY ;#to be watched with <image viewer> testprogram.png</lang>
=={{header|Perl 6}}==
=={{header|Perl 6}}==
{{works with|Rakudo|2015.12}}
{{works with|Rakudo|2018.10}}
<lang perl6>my $HOR = 1280;
<lang perl6>my ($x,$y) = 1280, 720;
my $VERT = 720;


my @colors = map -> $r, $g, $b { Buf.new: |(($r, $g, $b) xx $HOR div 8) },
my @colors = map -> $r, $g, $b { Buf.new: |(($r, $g, $b) xx $x div 8) },
0, 0, 0,
0, 0, 0,
255, 0, 0,
255, 0, 0,
0,255, 0,
0, 255, 0,
0, 0,255,
0, 0, 255,
255, 0,255,
255, 0, 255,
0,255,255,
0, 255, 255,
255,255, 0,
255, 255, 0,
255,255,255;
255, 255, 255;


my $PPM = open "colorbars.ppm", :w or die "Can't create colorbars.ppm: $!";
my $img = open "colorbars.ppm", :w orelse die "Can't create colorbars.ppm: $_";


$PPM.print: qq:to/EOH/;
$img.print: qq:to/EOH/;
P6
P6
# colorbars.ppm
# colorbars.ppm
$HOR $VERT
$x $y
255
255
EOH
EOH


for ^$VERT -> $v {
for ^$y {
for ^@colors -> $h {
for ^@colors -> $h {
$PPM.write: @colors[$h];
$img.write: @colors[$h];
}
}
}
}


$PPM.close;</lang>
$img.close;</lang>


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