This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
SuicidalSTDz's profile picture

Rainbow Text!

Started by SuicidalSTDz, 09 April 2013 - 09:14 AM
SuicidalSTDz #1
Posted 09 April 2013 - 11:14 AM
Well, here is the story behind me making this:

This is pretty cool… as long as we don't start seeing rainbow text everywhere :P/>/>

There are two forms of this script, function adapted(ran behind code), or file adapted (Being ran in the CraftOS command-line like 'edit <path>') I basically made this just for fun, well, and to make oeed mad of course ;)/>

--[[Function Adapted]]--
local roygbiv = {
  colours.red,
  colours.orange,
  colours.yellow,
  colours.lime,
  colours.lightBlue,
  colours.blue,
  colours.purple
}

local function rainbow(text)
  local num = 1
  for i = 1,#text do
	local letter = string.sub(text,i,i)
	if num > #roygbiv then num = 1 end
	term.setTextColour(roygbiv[num])
	term.write(letter)
	num = num+1
  end
end

--Example:
--rainbow("Rainbow")

Or:

--[[File Adapted]]
local tArgs = {...}

if #tArgs <= 0 then
  print("Usage: "..shell.getRunningProgram().." <text>")
  return
end

local roygbiv = {
  colours.red,
  colours.orange,
  colours.yellow,
  colours.lime,
  colours.lightBlue,
  colours.blue,
  colours.purple
}

local num = 1
for i = 1,#tArgs[1] do
  local letter = string.sub(tArgs[1],i,i)
  if num > #roygbiv then num = 1 end
  term.setTextColour(roygbiv[num])
  term.write(letter)
  if num == #tArgs[1] then
	print("")
  end
  num = num+1
end

With the commandline version just type:
programName <textToColor>

Pastebin for File Adapted:
a7274dDs

Pastebin for Function Adapted:
Gks7iSKG

Also, you may use this in your Graphical Shells as long as I am given full credit. This code CAN be modified for personal use, but nothing more.
Symmetryc #2
Posted 09 April 2013 - 03:50 PM
Lol :P/>, nice. You should make it with more than just for 6 colors though :P/>.
SuicidalSTDz #3
Posted 09 April 2013 - 04:12 PM
It should be fully customizable (colour wise) as is.
Spongy141 #4
Posted 12 April 2013 - 05:38 PM
Amazing….
SuicidalSTDz #5
Posted 14 April 2013 - 05:19 AM
Amazing….
It is indeed amazing what you can do with the proper knowledge. Now it's your turn. Excite our community and flourish into something incredible.
TheOddByte #6
Posted 18 April 2013 - 11:08 AM
You could also do this for random colors, Just saying..

term.setTextColor(2 ^ math.random(1,15) )

But anyway this is pretty awesome as it is and I like it..
So you like rainbows? :3
SuicidalSTDz #7
Posted 18 April 2013 - 01:20 PM
You could also do this for random colors, Just saying..

term.setTextColor(2 ^ math.random(1,15) )
Yes, yes I could. But this is fully customizable with interchangeable colours. So that is not an option.

But anyway this is pretty awesome as it is and I like it..
So you like rainbows? :3
Thanks, and I like rainbows to an extent. I don't really care for rainbow text all that much :P/>
Symmetryc #8
Posted 18 April 2013 - 03:01 PM
You could also do this for random colors, Just saying..

term.setTextColor(2 ^ math.random(1,15) )
Yes, yes I could. But this is fully customizable with interchangeable colours. So that is not an option.
Here you go :P/>.

local roygbiv = {
<Put Color 1 Here>;
<Put Color 2 Here>;
<Continue for as many colors as you want>;
}
local function rainbow(text)
  for i=1, #text do
	term.setTextColor(roygbiv[math.random(1, #roygbiv)]
	write(text:sub(i, i))
  end
end
SuicidalSTDz #9
Posted 18 April 2013 - 03:06 PM
I purposely made it a larger script than usual, so clueless members would understand what is happening on each line. I may compact it further, however it will stay as is for now.
Symmetryc #10
Posted 18 April 2013 - 03:27 PM
I purposely made it a larger script than usual, so clueless members would understand what is happening on each line. I may compact it further, however it will stay as is for now.
I wasn't compacting it, I was giving you a version that uses math.random() instead of ordered colors because you said that it's not an option because you couldn't customized the colors, but you can :P/>.
SuicidalSTDz #11
Posted 19 April 2013 - 01:26 AM
The colours MUST go in order. If I wanted to randomize it, I would've ;)/> I didn't see the math.random in your script which is why I thought you were trying to compact it :P/>
Symmetryc #12
Posted 19 April 2013 - 10:53 AM
The colours MUST go in order. If I wanted to randomize it, I would've ;)/>/> I didn't see the math.random in your script which is why I thought you were trying to compact it :P/>/>
Ah, OK, by "not an option" I thought you meant that there was no way to do it :P/>.
SuicidalSTDz #13
Posted 19 April 2013 - 12:20 PM
you meant that there was no way to do it :P/>.
There is nothing impossible to him who will try