Jump to content




vertically scrolling text


5 replies to this topic

#1 xbsktball10x

  • Members
  • 26 posts

Posted 23 January 2014 - 01:12 AM


Text = {
"The year was 2025. Aerial drones had revealed a large weapons cache in Siberia.",
" ",
"United Nations investigators were sent to investigate.",
" ",
"Once they got there they were met by Russian military. ",
" ",
"The Russians captured and executed the agents.",
" ",
"What were once thought to be nuclear weapons were soon revealed as anti-matter.",
" ",
"A weapon like no one had ever seen. A global scare prompted a new kind of space race.",
" ",
"A secret task force assembled to begin work on what only science fiction had thought possible before.",
" ",
"They started to build deep space vessels capable of supporting life.",
" ",
"They believed there was a possibility of life on other planets.",
" ",
"As work neared completion of the Icarus; the Russians found out.",
" ",
"Only a portion of the life support was completed when the war began.",
" ",
"Knowing that this would be the end of earth a rash decision was made,",
" ",
"they were going to launch the Icarus and head for the moon.",
" ",
"Only one section of the ship had breathable air,",
" ",
"this is where they setup a station to refill breathable tanks so that people could survive in space.",
" ",
"In the first year of the war Russia had expanded its territory to berlin.",
" ",
"As there was no slowing them down the Icarus was launched.",
" ",
"Upon reaching the moon it had been revealed that in our 55 year absence a new species had inhabited the moon.",
" ",
"The powers of the tesseract were revealed and teleportation finally became a reality.",
" ",
"Several years had passed and thousands of drones later they had found a suitable planet.",
" ",
"With little life support leaders believed the best way of reaching this planet would be",
" ",
"to send small settler groups to the planet and begin colonizing it.",
" ",
"The settlers began to plant trees, grow crops and create breathable oxygen levels.",
" ",
"However, soon it was discovered that this planet had resources like no one had seen",
" ",
"People knew they could profit from this world and began to mine its resources.",
" ",
" Soon factions were forming, and small warfare was beginning to break out across this new planet….",
" ",
" ",
" ",
" ",

"Here we are today; this is the first bunker created by the Terra Nova Army",
" ",
"and serves as the hub for new survivors to get a new start on the world",
" ",
"we know today as INSERT WORLD NAME HERE.",
" ",
"You can buy supplies and view the ranks in the terra nova army.",
" ",
"New world rules will be in the main atrium along with ranks",
" ",
"and items that have been banished from the new world so that it does not have the same fate as earth.",
" ",
"Please view the rules or your fate could very well be decided by the military leaders.",
" ",
"Earth is still habitable however riddled with radiation it is very dangerous.",
" ",
"War still rages there and bombs fall frequently.",
" ",
"Resources are still there however death is almost emanate.",
" ",
"Travel there at your own risk.",
" ",
}
mon = peripheral.wrap("top")
mon.clear()
wScreen, hScreen = mon.getSize()

function Vertical()
for i = -#Text, hScreen do
	  for t = 1,#Text do
		mon.setCursorPos(1,i+t)
		mon.write(Text[t])
print(i+t.." "..i.." "..t)


	  end
   mon.setCursorPos(1,i)
   sleep(.8)
   mon.clear()
  end
end

while true do
Vertical()
end


Hey guys im trying to make the text scroll up. So its like star wars intro text. This code make it scroll downward so it starts from the last line and scrolls down so that the beggining of the paragraph is the last thing shown. I have tried to change the numbers around but cant think of the way to make it go the other way. Can anyone help

#2 CometWolf

  • Members
  • 1,283 posts

Posted 23 January 2014 - 01:21 AM

This will make the for loop run backwards. The 3rd arg is what to increase t by for every loop, if it's not given it will use 1.
for t=#text,1,-1


#3 xbsktball10x

  • Members
  • 26 posts

Posted 23 January 2014 - 02:31 AM

That did not work

#4 CometWolf

  • Members
  • 1,283 posts

Posted 23 January 2014 - 03:10 AM

Obviously it won't work since your placing the text based on the t number, which will be higher than the actual terminal size most if the time. As such i have my doubts that it worked properly the other way in the first place. Im just saying if you want to run the loop backwards, that's how you do it.
Doing this properly would be something like
for t = 1,#text do
  for i = 1,termY do
    term.setCursorPos(1,i)
    term.write(tText[i+t])
  end
  sleep(0.8)
end


#5 MR_nesquick

  • Members
  • 106 posts
  • LocationNorway

Posted 23 January 2014 - 10:24 AM

this does work.. you were close. :)
function Vertical()
for i = hScreen,-#text,-1 do
  for t = 1,#text do
	mon.setCursorPos((wScreen/2)-(#text[t]/2)+1,i+t)
	mon.write(text[t])
  end
sleep(.8)
mon.clear()
end
end

Edited by MR_nesquick, 23 January 2014 - 12:34 PM.


#6 surferpup

  • Members
  • 286 posts
  • LocationUnited States

Posted 23 January 2014 - 04:52 PM

I dusted off a few of my older routines and put together what you are looking for. I plan on turning it into an API. Try this:

Vertical Scroll Program

The code is only around 130 lines long, and then there is your Text Array which takes up another 80+ lines. The main function that does the work is the scrollPrint() function. It takes the following arguments:
  • _textArray, -- the text table of strings to print
  • _startingVerticalPosition -- the y-position to begin on the monitor
  • _maximumVerticalPosition, -- the maximum y-position to go to
  • _sleepInterval, -- delay between printed lines
  • _outputDevice) -- the output device (term or monitor peripheral)
I have some built in error checking, although I would like to do more. Also, I started on color support and highlighted text, however, that is not complete in this version. Filally, I think this would make a good API, so I will try and finish this up as well. I tried to make all of the variable names and function names make sense. If a variable is an argument to a function, it begins with an underscore (ie. _argument). If a variable does not begin with an underscore, it is defined as a local variable.

To use it, create your text table as you have done already and fill in the main function call. In the example, that call is:

scrollPrint(Text,1,15,1,peripheral.wrap("top"))

In the example, your Text Table is scrolled through. The first lines starts centered on line 1 of the monitor. It then continues adding lines until it hits line 15 of the monitor. From then on, it prints each new line on line 15 and scrolls the older lines up and out of view (much like a normal terminal display would do). If you want it to start on line 15 and scroll up, change the _startingVerticalPosition to 15. If you want it to use the whole screen, set the _startingVerticalPosition argument to 1 and _maximumVerticalPosition argument to _ (underscore). Ex.

scrollPrint(Text,1,_,1,peripheral.wrap("top"))

I also don't clear the monitor. Instead, I only write over used lines with spaces. I think this allows for a smother display. It also allows for you to have other text (or graphics) on say the bottom half of the monitor while the text scrolls in the top half.

I auto-scale to the largest scale that will fit the width of all of the text strings. If you are using a terminal, autoscale is ignored. If it can't fit text on a line, it left justifies and fits as much as it can.

Let me know if you need help sorting out any of the functions.

Edited by surferpup, 23 January 2014 - 05:19 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users