Colour pinstripe/Display: Difference between revisions

Content deleted Content added
SqrtNegInf (talk | contribs)
m →‎{{header|Perl 6}}: proper error message on file open failure, style tweaks
Line 776: Line 776:
close DISPLAY ;</lang>
close DISPLAY ;</lang>
=={{header|Perl 6}}==
=={{header|Perl 6}}==
{{works with|Rakudo|2016-01}}
{{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 { [$r, $g, $b] },
my @colors = map -> $r, $g, $b { [$r, $g, $b] },
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 "pinstripes.ppm", :w or die "Can't create pinstripes.ppm: $!";
my $img = open "pinstripes.ppm", :w orelse die "Can't create pinstripes.ppm: $_";


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


my $vzones = $VERT div 4;
my $vzones = $y div 4;
for 1..4 -> $w {
for 1..4 -> $width {
my $hzones = ceiling $HOR / $w / +@colors;
my $stripes = ceiling $x / $width / +@colors;
my $line = [((@colors Xxx $w) xx $hzones).flatmap: *.values].splice(0,$HOR);
my $row = [((@colors Xxx $width) xx $stripes).flatmap: *.values].splice(0,$x);
$PPM.put: $line for ^$vzones;
$img.put: $row for ^$vzones;
}
}


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


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