I have another topic related to this program, but the purpose of that thread has been accomplished. I now need help changing the textscale, color, and background color for the monitor. It also has random characters that show up after the message. Can anyone help me out?
Here is the code.
Spoiler
scroll = 12
speed = 0.2
text = "Welome"
w,h = term.getSize()
posTexty = math.floor(h/2 + scroll/1.5)
posTextx = math.floor(w/2+12)
function vertical(text, lines, a, xpos, ypos)
for b = lines,1, -1 do
term.setCursorPos(xpos, ypos-(b+1))
if a-b < string.len(text)+1 and a-b > 0 then
print(string.sub( text, a-b, a-b ))
else print(" ")
end
end
end
scroll = 12
speed = 0.2
w,h = term.getSize()
posTexty = math.floor(h/2 + scroll/1.5)
posTextx = math.floor(w/2+12)
function vertical(text, lines, a, xpos, ypos)
for b = lines,1, -1 do
term.setCursorPos(xpos, ypos-(b+1))
if a-b < string.len(text)+1 and a-b > 0 then
print(string.sub( text, a-b, a-b ))
else print(" ")
end
end
end
while true do
term.redirect( peripheral.wrap( "right" ) )
term.clear()
for a = 1,string.len(text)+scroll+1 do
sleep(speed)
vertical(text, scroll, a, posTextx, posTexty)
end
term.restore()
end
I would like to point out you pasted the function vertical twice there… That will cause a problem. Also on the other thread where this code is posted, I made changes that fixed the problem, The program is reading the size of the terminal and not the monitor. They were my mistakes. * I also fixed them and made it work properly again.
To change the size of the text on the monitor you would need "monitor.setTextScale(2)" The program I wrote has been modified since so I could make it a Message of the day board. … Editable text
here is what I made…
term.clear() -- start by clearing the terminal
mon = peripheral.wrap("right") -- wrap our monitor to the right
mon.setTextScale(2.5) -- set our text scale on the monitor to x.x ( 1 to 5.5 limits )
scroll = 8 -- we are showing 6 characters on the screen on our upwards scroll...
speed = 0.5 -- length of sleep
w,h = mon.getSize() -- get screen size
posTexty = math.floor( h/2 + scroll/1.5 ) -- some strange math but /2 gave a odd effect so /1.5 works better
posTextx = math.floor( w/2 ) -- our x pos on the screen (i want a center text)
-- our Vertical print function
function vertical(text, lines, a, xpos, ypos) -- text, number of lines, our pos in the text, x loc, y loc.
for b = lines,1, -1 do -- for each line of our scroll...
mon.setCursorPos(xpos, ypos-(b+1)) -- set pos on screen
if a-b < string.len(text)+1 and a-b > 0 then -- if we have text to display from our string...
mon.write(string.sub( text, a-b, a-b )) -- write that text to the screen.
else mon.clearLine() -- otherwise just clear the line so we don't leave a text trail.
end -- end the if a-b ...
end -- end the for b = ...
end -- return from function
-- setup screen colors
mon.setBackgroundColor(colors.white) -- setup screen color
mon.setTextColor(colors.black) -- setup text color
mon.clear() -- clear the monitor to apply the settings.
-- Main program
while true do
e={} -- setup our events table
term.setCursorPos(1,2) -- Position for us to write the message
term.clearLine() -- Clear the line of old text just incase.
write("Input Message : ") -- ask user to input the message to display
text = read() -- get the message they type
if text == "" then -- if nothing typed then use default message
text = "MOTD - Welcome!" -- our message default
end
term.setCursorPos(1,2) -- location of our last message
term.clearLine() -- clear that one line of all text.
term.setCursorPos(43,19) -- where we want our exit command for new text to be inserted
term.clearLine() -- clear the line of old text
term.write("2 to exit") -- Print the key to press to enter the new text (2)
loop = true -- we want our text to scroll untill we stop it with key 2
while loop do -- while loop == true we repeat this loop
for a = 1,string.len(text)+scroll+1 do -- do our string length + scroll + 1 (so the last char is not missed)
-- sleep(speed) -- the speed of our scroll.
vertical(text, scroll, a, posTextx, posTexty) -- call the function.
os.startTimer(speed) -- the speed of our scroll and our escape key capture
e = {os.pullEvent()} -- pull events as a table
if e[2] == 3 then -- if the value of event is 3 ( key press 2 ) then
loop = false -- we break the while loop .
mon.clear() -- clear the monitor
break -- break the for loop and return to requesting a new message
end
end
end
sleep(1) -- we pause to let the stack empty.
end
-- EOF!!