Jump to content




Rainbow Text!


  • You cannot reply to this topic
12 replies to this topic

#1 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 09 April 2013 - 10:14 AM

Well, here is the story behind me making this:

View Postoeed, on 02 April 2013 - 11:41 PM, said:

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.

#2 Symmetryc

  • Members
  • 434 posts

Posted 09 April 2013 - 02:50 PM

Lol :P, nice. You should make it with more than just for 6 colors though :P.

#3 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 09 April 2013 - 03:12 PM

It should be fully customizable (colour wise) as is.

#4 Spongy141

  • Members
  • 526 posts
  • Location'Merica

Posted 12 April 2013 - 04:38 PM

Amazing....

#5 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 14 April 2013 - 04:19 AM

View PostSpongy141, on 12 April 2013 - 04:38 PM, said:

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.

#6 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 18 April 2013 - 10: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

#7 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 18 April 2013 - 12:20 PM

View PostHellkid98, on 18 April 2013 - 10:08 AM, said:

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.

View PostHellkid98, on 18 April 2013 - 10:08 AM, said:

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

#8 Symmetryc

  • Members
  • 434 posts

Posted 18 April 2013 - 02:01 PM

View PostSuicidalSTDz, on 18 April 2013 - 12:20 PM, said:

View PostHellkid98, on 18 April 2013 - 10:08 AM, said:

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


#9 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 18 April 2013 - 02: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.

#10 Symmetryc

  • Members
  • 434 posts

Posted 18 April 2013 - 02:27 PM

View PostSuicidalSTDz, on 18 April 2013 - 02:06 PM, said:

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.

#11 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 19 April 2013 - 12: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

#12 Symmetryc

  • Members
  • 434 posts

Posted 19 April 2013 - 09:53 AM

View PostSuicidalSTDz, on 19 April 2013 - 12:26 AM, said:

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.

#13 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 19 April 2013 - 11:20 AM

View PostSymmetryc, on 19 April 2013 - 09:53 AM, said:

you meant that there was no way to do it :P.
There is nothing impossible to him who will try





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users