Rainbow: Difference between revisions
Content added Content deleted
(Added Chipmunk Basic, GW-BASIC and True BASIC) |
|||
Line 14: | Line 14: | ||
text i*8,150, mid(s$,i,1) |
text i*8,150, mid(s$,i,1) |
||
next i</syntaxhighlight> |
next i</syntaxhighlight> |
||
==={{header|Chipmunk Basic}}=== |
|||
{{works with|Chipmunk Basic|3.6.4}} |
|||
<syntaxhighlight lang="qbasic">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</syntaxhighlight> |
|||
==={{header|FreeBASIC}}=== |
==={{header|FreeBASIC}}=== |
||
Line 33: | Line 47: | ||
Sleep</syntaxhighlight> |
Sleep</syntaxhighlight> |
||
==={{header|GW-BASIC}}=== |
|||
{{works with|PC-BASIC|any}} |
|||
{{works with|QBasic}} |
|||
<syntaxhighlight lang="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</syntaxhighlight> |
|||
==={{header|True BASIC}}=== |
|||
<syntaxhighlight lang="qbasic">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</syntaxhighlight> |
|||
=={{header|Python}}== |
=={{header|Python}}== |
Revision as of 22:42, 16 July 2023
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.
BASIC
BASIC256
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
Chipmunk Basic
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
FreeBASIC
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(i,i,i)
Print Mid(s, i, 1);
Next i
Sleep
GW-BASIC
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
True BASIC
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
Python
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}')
Raku
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".
Another phrase that happens to contain the word "Rainbow".
Wren
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()