There are two ways of doing this:
- Print it character by character, where everyone has randomized color
- Generate a randomized string and write it at once using term.blit (it takes three strings, one for the text, and two for the foreground an background color)
Way one:
function rainbowWrite(text)
local cx, cy = term.getCursorPos()
for x = 1, #text do
term.setCursorPos(cx+x-1, cy)
term.setTextColor(c[math.random(1, 15)])
term.write(string.sub(text, x, x))
end
end
Way 2:
Your
c table has to be filled with
paint color codes
function rainbowWrite(text)
local textColorString = ""
local backgroundColorString = ""
for x = 1, #text do
colorString = colorString..c[math.random(1, 15)]
backgroundColorString = backgroundColorString.."0"
--# the background will always be 0
end
term.blit(text, textColorString, backgroundColorString)
end
Edited by Jummit, 16 October 2018 - 11:36 AM.