Rainbow: Difference between revisions

909 bytes added ,  2 months ago
Added a Dart example.
m (→‎{{header|Phix}}: added library header)
(Added a Dart example.)
 
(2 intermediate revisions by 2 users not shown)
Line 108:
<div style="background-color:#F6F6F6;padding:1em;">
<font color="#FF0000">R</font><font color="#FF8000">A</font><font color="#FFFF00">I</font><font color="#00FF00">N</font><font color="#0000FF">B</font><font color="#4B0082">O</font><font color="#8000FF">W</font><br></div>
 
=={{header|Dart}}==
<syntaxhighlight lang="Dart">
import 'dart:io';
 
void main() {
const rainbow = 'RAINBOW';
const spectrum = [
[255, 0, 0], // red
[255, 165, 0], // orange
[255, 255, 0], // yellow
[0, 128, 0], // green
[0, 0, 255], // blue
[75, 0, 130], // indigo
[238, 130, 238], // violet
];
 
for (int i = 0; i < rainbow.length; i++) {
final red = spectrum[i][0];
final green = spectrum[i][1];
final blue = spectrum[i][2];
stdout.write('\x1B[38;2;${red};${green};${blue}m${rainbow[i]}\x1B[0m');
}
}
</syntaxhighlight>
 
=={{header|Factor}}==
Line 198 ⟶ 223:
</syntaxhighlight>
[[File:Rainbow.png|center|thumb]]
 
=={{header|Perl}}==
<syntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Rainbow
use warnings;
use List::AllUtils qw( zip_by );
 
print zip_by { "\e[38;2;$_[1]m$_[0]\e[m" } [ split //, 'RAINBOW' ],
[qw( 255;0;0 255;128;0 255;255;0 0;255;0 0;0;255 75;0;130 128;0;255 )];
print "\n";</syntaxhighlight>
 
=={{header|Phix}}==
Line 258 ⟶ 294:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var colors = [
[255, 0, 0], // red
[255, 128, 0], // orange
1

edit