Rainbow is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task
Print out the word 'RAINBOW' to the screen with every character being a different color of the rainbow.



This is a boot sector program. Compile it with fasm. Run it as a floppy image in Qemu. You can write it to a floppy disk and boot it with an old computer. I have not tried that. This program writes the message directly to the screen always on the 8th line. No software interrupts are used to print the message.
Run this program in your browser

 
use16
org 0x7c00

    mov ax, 0xb800    ;set ax to the mode3 screen buffer
    mov es, ax        ;set es segment register to screen buffer
    mov si, rainbow   ;set source index to the message
    mov di, 1280      ;set destination index to position on screen
    mov cx, 7         ;set counter register to loop 7 times
@@:
    movsw             ;mov 2 bytes from message to mode3 screen
    loop @b           ;decrement cx, jump to last @@, if cx isn't 0

    jmp $             ;halt



rainbow:
;     char| attr|char| attr|char| attr|char| attr
    db 'R', 0x04, 'A', 0x06, 'I', 0x0e, 'N', 0x0a
    db 'B', 0x09, 'O', 0x01, 'W', 0x05

    times 510 - ($ - $$) db 0
    dw 0xaa55

Using ANSI escape sequences.

with Ada.Text_IO; use Ada.Text_IO;

procedure Main is
   ESC : constant Character := Character'Val (27);
begin
   Put (ESC & "[31" & "mR");
   Put (ESC & "[32" & "mA");
   Put (ESC & "[33" & "mI");
   Put (ESC & "[34" & "mN");
   Put (ESC & "[35" & "mB");
   Put (ESC & "[36" & "mO");
   Put (ESC & "[37" & "mW");
   New_Line;
end Main;

Generates an SVG document, you can redirect the output to a .svg file and open it in a browser or other SVG viewer.

BEGIN # generate SVG to show the word RAINBOW in the colours of the spectrum #
    PROC max = ( INT a, b )INT: IF a < b THEN b ELSE a FI;
    STRING text = "RAINBOW";
    []STRING colour = ( "red", "orange", "yellow", "green", "blue", "indigo", "violet" );
    INT      c len  = ( UPB colour - LWB colour ) + 1;   # number of colours #
    INT      x     := 30;
    INT      y      = 30;
    print( ( "<svg xmlns='http://www.w3.org/2000/svg' width='"
           , whole( ( c len * 20 ) + 60, 0 ), "' "
           , "height='50' style='font:bold 30px monospace'>", newline
           , "  <rect width='100%' height='100%' fill='grey'/>", newline
           )
         );
    FOR i FROM LWB text TO UPB text DO
        STRING c name = colour[ max( 1, i MOD ( c len + 1 ) ) ];
        print( ( "  <text x='", whole( x, 0 ), "' y='", whole( y, 0 ), "' " ) );
        print( ( "fill='", c name, "' stroke='", c name, "'>", text[ i ], "</text>", newline ) );
        x +:= 20
    OD;
    print( ( "</svg>", newline ) )
END
Output:
<svg xmlns='http://www.w3.org/2000/svg' width='200' height='50' style='font:bold 30px monospace'>
  <rect width='100%' height='100%' fill='grey'/>
  <text x='30' y='30' fill='red' stroke='red'>R</text>
  <text x='50' y='30' fill='orange' stroke='orange'>A</text>
  <text x='70' y='30' fill='yellow' stroke='yellow'>I</text>
  <text x='90' y='30' fill='green' stroke='green'>N</text>
  <text x='110' y='30' fill='blue' stroke='blue'>B</text>
  <text x='130' y='30' fill='indigo' stroke='indigo'>O</text>
  <text x='150' y='30' fill='violet' stroke='violet'>W</text>
</svg>

...which should appear as:  

loop [
    #red "R"
    #orange "A"
    #yellow "I"
    #green "N"
    #blue "B"
    #indigo "O"
    #violet "W"
] [c l] -> prints color c l
# syntax: GAWK -f RAINBOW.AWK
# 8 colors are used: gray red green yellow blue magenta cyan white
BEGIN {
    n = split("RAINBOW,RosettaCode.org",arr,",")
    for (i=1; i<=n; i++) {
      for (j=1; j<=length(arr[i]); j++) {
        color = 90 + j % 8
        printf("\033[%dm%s",color,substr(arr[i],j,1))
      }
      printf("\n\n")
    }
    exit(0)
}
Output:

 

 
Output
SCREEN 1,640,200,3,2
WINDOW 2,"Rainbow text",(0,10)-(320,50),15,1
LOCATE 3,18
s$="RAINBOW"
PALETTE 0,.8,.8,.8
FOR i=1 TO 7
  READ r,g,b
  PALETTE i,r,g,b
  COLOR i
  PRINT MID$(s$,i,1);
NEXT
WHILE INKEY$=""
WEND
SCREEN CLOSE 1

DATA .93,.11,.14
DATA 1,.5,.15
DATA 1,.95,0
DATA .13,.69,.3
DATA 0,.64,.91
DATA .25,.28,.8
DATA .64,.29,.65
 1  GR : DEF  FN C(I) =  ASC ( MID$ (A$,I)) - 58: FOR C = 1 TO 7: READ A$: COLOR=  FN C(1): FOR I = 2 TO  LEN (A$) STEP 3: VLIN  FN C(I), FN C(I + 1) AT  FN C(I + 2): NEXT I,C
 2  DATA"K?E?@BA??@CC@DEA",S@EC??DCCD@EE,W?EG,V?EI@AJBCK?EL,Q?EN??OBBOEEO@APCDP,L@DR??SEES@DT,M?EVCDWABXCDY?EZ
 
Output in MAME
10 PRINT CHR$(11)
20 PRINT "RAINBOW"
30 CS=13393
40 FOR I=0 TO 6
50 READ C
60 C=16*C+7
70 POKE CS+I,C
80 NEXT
90 DATA 1,3,2,6,4,10,5
dim colors$(6)
colors$ = {red, orange, yellow, green, blue, darkblue, cyan}

clg
s$ = "RAINBOW"
for i = 1 to length(s$)
	color colors$[i-1]
	text i*8,150, mid(s$,i,1)
next i
 
Output
10 MODE 2
20 S$="RAINBOW"
30 FOR I=1 to 7
40 READ C
50 COLOUR C
60 PRINT MID$(S$,I,1);
70 NEXT
80 PRINT
90 DATA 1,2,3,7,6,4,5
Works with: Chipmunk Basic version 3.6.4
100 graphics 0
110 dim colors(6,6,6)
120 data 255,0,0,255,128,0,255,255,0,0,255,0,0,0,255,75,0,130,128,0,255
130 s$ = "RAINBOW"
140 for i = 1 to 7
150   read a,b,c
160   graphics color a,b,c
170   graphics moveto i*10,10
180   graphics text mid$(s$,i,1);
190 next i
200 end
 
Output in VICE C64 emulator
10 S$="RAINBOW":POKE 53281,1
20 FOR I=1 TO 7
30 READ C:POKE 646,C
40 PRINT MID$(S$,I,1);
50 NEXT
60 DATA 2,8,7,5,3,6,4
 
Dim As Integer colors(6, 2) => { _
{255,   0,   0}, _ ' red
{255, 128,   0}, _ ' orange
{255, 255,   0}, _ ' yellow
{  0, 255,   0}, _ ' green
{  0,   0, 255}, _ ' blue
{75,    0, 130}, _ ' indigo
{128,   0, 255}} _ ' violet

Cls
Dim As String s = "RAINBOW"
For i As Byte = 1 To Len(s)
    Color Rgb(colors(i,2),colors(i,2),colors(i,2))
    Print Mid(s, i, 1);
Next i

Sleep
Works with: PC-BASIC version any
Works with: QBasic
10 CLS
20 DATA 4,6,14,2,1,11,13
30 S$ = "RAINBOW"
40 FOR I = 1 TO 7
50 READ C
60   COLOR C
70   PRINT MID$(S$, I, 1);
80 NEXT I
90 END
 
Output in CPCBasic
10 mode 0:ink 0,10:locate 7,10:s$="RAINBOW"
20 for i=1 to 7
30 read col:ink i,col:pen i
40 print mid$(s$,i,1);
50 next
60 goto 60
70 data 6,15,24,18,2,5,8
CLEAR
DATA 4, 6, 14, 2, 1, 11, 13
LET s$ = "RAINBOW"
FOR i = 1 to 7
    READ c
    SET COLOR c
    PRINT (s$)[i:i+1-1];
NEXT i
END
 
Output
10 PAPER 0
20 LET s$="RAINBOW"
30 FOR i=1 TO 7
40 READ c
50 INK c
60 PRINT s$(i TO i);
70 NEXT i
80 PAPER 7
90 DATA 2,4,6,7,5,1,3

C

#include <stdio.h>

int main() {
    int i, clrs[7][3] = {
        {255,   0,   0}, // red
        {255, 128,   0}, // orange
        {255, 255,   0}, // yellow
        {  0, 255,   0}, // green
        {  0,   0, 255}, // blue
        { 75,   0, 130}, // indigo
        {128,   0, 255}, // violet
    };
    const char *s = "RAINBOW";
    for (i = 0; i < 7; ++i) {
        printf("\x1B[38;2;%d;%d;%dm%c", clrs[i][0], clrs[i][1], clrs[i][2], s[i]);
    }
    printf("\n");
    return 0;
}
Output:
RAINBOW
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

int main() {
	// ANSI escape code constants for foreground text colours
	const std::string RED =    "\u001B[38;2;255;0;0m";
	const std::string ORANGE = "\u001B[38;2;255;128;0m";
	const std::string YELLOW = "\u001B[38;2;255;255;0m";
	const std::string GREEN =  "\u001B[38;2;0;255;0m";
	const std::string BLUE =   "\u001B[38;2;0;0;255m";
	const std::string INDIGO = "\u001B[38;2;75;0;130m";
	const std::string VIOLET = "\u001B[38;2;128;0;255m";

	// ANSI escape code constant to reset the terminal to its default values
	const std::string RESET = "\u001B[0m";

	const std::vector<std::string> colours = { RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET };

	const std::string rainbow = "RAINBOW";

	for ( uint32_t i = 0; i < 7; ++i ) {
		std::cout << colours[i] << rainbow[i];
	}
	std::cout << RESET << std::endl;
}
Output:
RAINBOW
require "colorize"

"RAINBOW".chars.zip([:red, Colorize::ColorRGB.new(255, 140, 0), # orange
                     :yellow, :green, :cyan, :blue,
                     Colorize::ColorRGB.new(200, 0, 200)]       # violet
                   ) do |letter, color|
  print letter.colorize(color)
end
puts
Output:

 

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');
  }
}

Run it

s$[] = strchars "RAINBOW"
cols[] = [ 900 950 990 090 009 306 509 ]
gtextsize 15
gbackground 000
gclear
for i to 7
   gcolor cols[i]
   gtext i * 11.5 60 s$[i]
.
USING: colors grouping hashtables io.styles qw sequences ui
ui.gadgets.panes ;

"RAINBOW" 1 group
qw{ red orange yellow green blue indigo violet } [
    [ named-color foreground associate format ] 2each
] make-pane "Rainbow" open-window
Output:
 


Requires FB 7.0.31 or newer to compile macOS app.

_window = 1
begin enum 1
  _txtField
end enum

CFMutableAttributedStringRef local fn ColoredCharacters( string as CFStringRef )
  CFMutableAttributedStringRef aString = fn MutableAttributedStringWithString( string )
  
  for int i = 0 to len(string) -1
    CGFloat red   = rnd(256) / 255.0
    CGFloat green = rnd(256) / 255.0
    CGFloat blue  = rnd(256) / 255.0
    ColorRef randomColor = fn ColorWithSRGB( red, green, blue, 1.0 )
    MutableAttributedStringSetForegroundColorInRange( aString, randomColor, fn RangeMake( i, 1 ) )
  next
  MutableAttributedStringSetAlignment( aString, NSTextAlignmentCenter )
  MutableAttributedStringSetFontWithName( aString, @"Times Bold", 60.0 )
end fn = aString

void local fn BuildWindow
  CGRect r = fn CGRectMake( 0, 0, 340, 100 )
  window _window, @"Colored Characters", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable
  WindowSetBackgroundColor( _window, fn ColorWhite )
  
  r = fn CGRectMake( 0, 25, 340, 60 )
  textfield _txtField, YES, ,r, _window
  TextFieldSetBezeled(  _txtField, NO )
  TextFieldSetBordered( _txtField, NO )
  TextFieldSetDrawsBackground( _txtField, NO )
  TextFieldSetPlaceholderAttributedString( _txtField, fn ColoredCharacters( @"RAINBOW" ) )
end fn

random
fn BuildWindow

HandleEvents
Output:

 


Translation of: C
package main

import "fmt"

func main() {
    clrs := [7][3]int{
        {255, 0, 0},   // red
        {255, 128, 0}, // orange
        {255, 255, 0}, // yellow
        {0, 255, 0},   // green
        {0, 0, 255},   // blue
        {75, 0, 130},  // indigo
        {128, 0, 255}, // violet
    }
    s := "RAINBOW"
    for i := 0; i < 7; i++ {
        fmt.Printf("\x1B[38;2;%d;%d;%dm%c", clrs[i][0], clrs[i][1], clrs[i][2], s[i])
    }
    fmt.Println()
}
Output:
As C example.
<!DOCTYPE html>
<html>
<head>
    <title>Text in Multiple Colors (No Spaces)</title>
</head>
<body>
    <p>
        <span style="color: red">R</span><span style="color: orange">A</span><span style="color: yellow">I</span><span style="color: green">N</span><span style="color: blue">B</span><span style="color: indigo">O</span><span style="color: violet">W</span>
    </p>
</body>
</html>
import java.util.List;

public final class Rainbow {

	 public static void main(String[] args) {        
	    	// ANSI escape code constants for foreground text colours
	        final String RED =    "\u001B[38;2;255;0;0m";
	        final String ORANGE = "\u001B[38;2;255;128;0m";
	        final String YELLOW = "\u001B[38;2;255;255;0m";
	        final String GREEN =  "\u001B[38;2;0;255;0m";
	        final String BLUE =   "\u001B[38;2;0;0;255m";
	        final String INDIGO = "\u001B[38;2;75;0;130m";
	        final String VIOLET = "\u001B[38;2;128;0;255m";
	        
	        // ANSI escape code constant to reset the terminal to its default values
	        final String RESET = "\u001B[0m";
	        
	        List<String> colours = List.of( RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET );
	        
	        String rainbow = "RAINBOW";
	        
	        for ( int i = 0; i < 7; i++ ) {
	        	System.out.print(colours.get(i) + rainbow.charAt(i));
	        }
	        System.out.println(RESET);
	    }

}
Output:
RAINBOW

J

load 'viewmat'
viewmat ,./ (>:i.7) * (0 0),~"1 (7 7 $ ])"1 #: 547643488084546 546543585190081 558828949210239 289227815346625 547643487986044 405806095814940 288124008817846

 

The following assumes the terminal supports the ANSI RGB codes, and has been tested using iTerm2.

def colors: [
    [255,   0,   0],  # red
    [255, 128,   0],  # orange
    [255, 255,   0],  # yellow
    [  0, 255,   0],  # green
    [  0,   0, 255],  # blue
    [ 75,   0, 130],  # indigo
    [128,   0, 255]   # violet
  ];

def rainbow($s):
    # ;38 is the extended foreground color code 
    # ;2 indicates RGB digits follow
    def e: "\u001B";  # ESCAPE
    reduce range(0; $s|length) as $j ("";
      ($j % 7) as $i
      | . + "\(e)[38;2;\(colors[$i][0]);\(colors[$i][1]);\(colors[$i][2])m\($s[$i:$i+1])" )
    + "\(e)[0m";

rainbow("RAINBOW")

Invocation: jq -nr -f rainbow.jq

using Crayons

for (letter, color) in [("R", crayon"red"), ("A", crayon"ff7f00"),
                        ("I", crayon"yellow"), ("N", crayon"green"),
                        ("B", crayon"blue"), ("O", crayon"4b0082"), ("W", crayon"7f00ff")]
    print(color, letter, " ");
end
 

M2000 Interpreter has own console which we can draw on it.

FORM 20, 16
MODULE CHECK {
	MODULE RAINBOW{
		OLDPEN=PEN
		CLS #1F3F1F, 0
		FLUSH    ' empty stack
		DATA #FF0000, color(255, 128,0),14, 3, #2F2FFF, color(135,64,210), #7F1FAA
		LET s$ = "RAINBOW"
		FOR i = 1 to 7
		    READ c
		    PEN c
		    PRINT MID$(s$,i,1);
		NEXT i
		PRINT
		PEN OLDPEN
		END
	}
	RAINBOW
	DRAWING {
		RAINBOW  
	} AS DRW1  ' THIS IS AN EMF DATA IN RAM FILE
	MOVE 6000,6000
	' DRAW GRAPH WIDH 6000 TWIPS, HEIGHT CALCULATING AUTOMATIC, 30 DEGREE SLOPE
	IMAGE DRW1, 6000,,30
	PEN 11 {WIDTH 10 {CIRCLE 4000}}
}
CHECK
PUSH KEY$:DROP
FORM 80, 38
Output:
 
M2000 RAINBOW
Translation of: C++
from terminal import ansiResetCode

const
  RED =    "\e[38;2;255;0;0m"
  ORANGE = "\e[38;2;255;128;0m"
  YELLOW = "\e[38;2;255;255;0m"
  GREEN =  "\e[38;2;0;255;0m"
  BLUE =   "\e[38;2;0;0;255m"
  INDIGO = "\e[38;2;75;0;130m"
  VIOLET = "\e[38;2;128;0;255m"  

  COLORS = [RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET]
  RAINBOW = "RAINBOW"

for i in 0..<7:
  stdout.write(COLORS[i] & RAINBOW[i])
stdout.write(ansiResetCode)
Output:
RAINBOW
#!/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";


Library: Phix/xpGUI
with javascript_semantics
requires("1.0.6")
include xpGUI.e

constant rainbow = {{"R",XPG_RED},
                    {"A",XPG_ORANGE},
                    {"I",XPG_YELLOW},
                    {"N",XPG_GREEN},
                    {"B",XPG_BLUE},
                    {"O",XPG_INDIGO},
                    {"W",XPG_PURPLE}}

function get_data(integer idx)
    return iff(idx<=0?1:rainbow)
end function

gdx list = gList(get_data,"=BGCLR",{#F0F0F0}),
    vbox = gVbox({list},`MARGIN=10`),
    dialog = gDialog(vbox,"Rainbow",`SIZE=240x62`)
gShow(dialog)
gMainLoop()
Output:
 
Translation of: Wren
Library: Wren-ansi

For consistency with the Wren example, I've composed the colors from their RGB components rather than use the standard colors on my Ubuntu terminal some of which look rather washed out to me - yellow looks more like brown!

require "ansi"

local colors = { 
    {255,   0,   0}, -- red
    {255, 128,   0}, -- orange
    {255, 255,   0}, -- yellow
    {  0, 255,   0}, -- green
    {  0,   0, 255}, -- blue
    { 75,   0, 130}, -- indigo
    {128,   0, 255}  -- violet
}

local rainbow = "RAINBOW":split("")
for i, c in rainbow do
    local col = screen.rgb(colors[i]:unpack())
    screen.write(c, col)
end
print()
Output:
RAINBOW

This version only uses ISO standard predicates and should work on most Prolog runtimes.

:- write('\e[91mR\e[33mA\e[92mI\e[32mN\e[36mB\e[94mO\e[35mW\e[0m'), nl.
Works with: SWI-Prolog version 9.2.9

This version uses a SWI-Prolog specific module, trading portability for legibility.

:- use_module(library(ansi_term)).

:-  ansi_format([fg(255,  10,  10)], 'R',   []),
    ansi_format([fg(240, 120,   0)], 'A',   []),
    ansi_format([fg(200, 220,   0)], 'I',   []),
    ansi_format([fg(  0, 225,  40)], 'N',   []),
    ansi_format([fg(  0, 200, 240)], 'B',   []),
    ansi_format([fg(  0,   0, 255)], 'O',   []),
    ansi_format([fg(240,   0, 240)], 'W~n', []).

Colored

from colored import Fore, Style
red: str = f'{Fore.rgb(255, 0, 0)}'
orange: str = f'{Fore.rgb(255, 128, 0)}'
yellow: str = f'{Fore.rgb(255, 255, 0)}'
green: str = f'{Fore.rgb(0, 255, 0)}'
blue: str = f'{Fore.rgb(0, 0, 255)}'
indigo: str = f'{Fore.rgb(75, 0, 130)}'
violet: str = f'{Fore.rgb(128, 0, 255)}'
print(f'{red}R{Style.reset}' + f'{orange}A{Style.reset}' + f'{yellow}I{Style.reset}' + f'{green}N{Style.reset}' + f'{blue}B{Style.reset}' + f'{indigo}O{Style.reset}' + f'{violet}W{Style.reset}')
Output:

RAINBOW


  [ char m join
    $ /
print(("\033["+string_from_stack()),end='')
     / python ]                             is colour ( $ --> )

  [ $ "31" colour ]                         is red    (   --> )
  [ $ "38;5;208" colour ]                   is orange (   --> )
  [ $ "33" colour ]                         is yellow (   --> )
  [ $ "32" colour ]                         is green  (   --> )
  [ $ "34" colour ]                         is blue   (   --> )
  [ $ "38;5;54" colour ]                    is indigo (   --> )
  [ $ "35" colour ]                         is violet (   --> )
  [ $ "30" colour ]                         is black  (   --> )

  $ "RAINBOW"
  ' [ red orange yellow green blue indigo violet ] 
  witheach [ do behead emit ]
  drop 
  black
Output:
 

R

png(filename="Rainbow-R.png", height=200, width=600)
plot(x=NA, xlim=c(0, 1), ylim=c(0, 1), xlab=NA, ylab=NA, axes=FALSE)
coords <- seq(0.1, 0.9, length.out=7)
chars <- c("R", "A", "I", "N", "B", "O", "W")
pal <- c("red", "orange", "yellow", "green", "blue", "purple", "violet")
for(i in 1:7) text(x=coords[i], y=0.5, labels=chars[i], col=pal[i], cex=5)
dev.off()
Output:

 

use Color::Names:api<2>;
use Color::Names::X11 :colors;

for 'RAINBOW',
    'Another phrase that happens to contain the word "Rainbow".'
  -> $rainbow-text {
    for $rainbow-text.comb Z, flat(<red orange yellow green blue indigo violet> xx *) -> ($l, $c) {
        print "\e[38;2;{COLORS{"{$c}-X11"}<rgb>.join(';')}m$l\e[0"
    }
    say '';
}
Output:

Displayed here as HTML as ANSI colors don't show up on web interfaces.

RAINBOW
Another phrase that happens to contain the word "Rainbow".

(this is also the output from the Algol 68 sample)

<svg xmlns='http://www.w3.org/2000/svg' width='200' height='50' style='font:bold 30px monospace'>
  <rect width='100%' height='100%' fill='grey'/>
  <text x='30' y='30' fill='red' stroke='red'>R</text>
  <text x='50' y='30' fill='orange' stroke='orange'>A</text>
  <text x='70' y='30' fill='yellow' stroke='yellow'>I</text>
  <text x='90' y='30' fill='green' stroke='green'>N</text>
  <text x='110' y='30' fill='blue' stroke='blue'>B</text>
  <text x='130' y='30' fill='indigo' stroke='indigo'>O</text>
  <text x='150' y='30' fill='violet' stroke='violet'>W</text>
</svg>

 

echo "$(tput setaf 1)R $(tput setaf 7)A $(tput setaf 3)I $(tput setaf 2)N $(tput setaf 4)B $(tput setaf 6)O $(tput setaf 5)W $(tput sgr0)"

— Ken McLeod

Works with: Uiua version 0.18.0

Uses experimental Layout feature. Try it here!

# Experimental!
L ← ≡₀×⊙(¤¤)layout 100
[{@R 1_0_0} {@A 1_0.5_0}{@I 1_1_0}{@N 0_1_0}{@B 0.3_0.3_1}{@O 0.5_0_1}{@W 0.7_0_0.7}]
/≡⊂≡(L∩°□°⊟)
Output:

 

var colors = [
    [255,   0,   0], // red
    [255, 128,   0], // orange
    [255, 255,   0], // yellow
    [  0, 255,   0], // green
    [  0,   0, 255], // blue
    [ 75,   0, 130], // indigo
    [128,   0, 255]  // violet
]

var s = "RAINBOW"
for (i in 0..6) {
    var fore = "\e[38;2;%(colors[i][0]);%(colors[i][1]);%(colors[i][2])m"
    System.write("%(fore)%(s[i])")
}
System.print()
Output:
RAINBOW
Translation of: XPL0

Twenty-six byte executable program. Output is same as XPL0. Assemble with: tasm; tlink /t

0000                                 .model  tiny
0000                                 .code
                                     org     100h
                             ;MS-DOS loads .com files with registers set this way:
                             ; ax=0, bx=0, cx=00FFh, dx=cs, si=0100h, di=-2, bp=09xx, sp=-2, es=ds=cs=ss
                             ;The direction flag (d) is clear (incrementing).
0100  52 41 49 4E 42 4F 57   start:  db      "RAINBOW"       ;executed as code shown below
                             ;push dx    inc cx    dec cx    DEC SI    inc dx    dec di    push di
0107  B0 13                          mov     al, 13h         ;call BIOS to set graphic mode 13h (ah=0)
0109  CD 10                          int     10h             ; 320x200 with 256 colors
010B  B3 1E                          mov     bl, 32-2        ;base of rainbow colors
010D  B1 08                          mov     cl, 1+7         ;number of characters to display + null in PSP
010F  B4 0E                          mov     ah, 0Eh         ;write character in teletype mode
0111  AC                     rb10:   lodsb                   ;fetch char to write: al:= ds:[si++]
0112  CD 10                          int     10h
0114  43                             inc     bx              ;next color
0115  43                             inc     bx
0116  E2 F9                          loop    rb10            ;loop for all 1+7 characters (cx--)
0118  EB FE                          jmp     $               ;lock up
                                     end     start
 

The Raspberry Pi versions of the language require a graphic mode for colored text (unlike the MS-DOS versions), but they compensate by supporting this unusual string indexing (which only works with the interpreted MS-DOS version).

char I;
[SetVid($13);                   \set 320x200x8 VGA graphics
for I:= 0 to 6 do
        [Attrib(32+I+I);        \set color attribute
        ChOut(6, I("RAINBOW "));
        ];
]
Translation of: Wren
fn main() {
    let colors: (int, int, int)[7] = [
        (255,   0,   0), // red
        (255, 128,   0), // orange
        (255, 255,   0), // yellow
        (  0, 255,   0), // green
        (  0,   0, 255), // blue
        ( 75,   0, 130), // indigo
        (128,   0, 255)  // violet
    ];
    let s = "RAINBOW";
    for i in 0..7 {
        let fore = "\e[38;2;{colors[i].0};{colors[i].1};{colors[i].2}m";
        print "{fore}{s[i]:c}";
    }
    println "";
}
Output:
RAINBOW
Translation of: C
const std = @import("std");

pub fn main() void {
    const clrs = [7][3]u8{
        [_]u8{255, 0, 0},   // red
        [_]u8{255, 128, 0}, // orange
        [_]u8{255, 255, 0}, // yellow
        [_]u8{0, 255, 0},   // green
        [_]u8{0, 0, 255},   // blue
        [_]u8{75, 0, 130},  // indigo
        [_]u8{128, 0, 255}, // violet
    };
    const s = "RAINBOW";
    for(0..7) |i| {
        std.debug.print("\x1B[38;2;{d};{d};{d}m{c}", .{clrs[i][0], clrs[i][1], clrs[i][2], s[i]});
    }
    std.debug.print("\n", .{});
}
Output:
RAINBOW