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

[Lua][Question] Scrolling Intro?

Started by Henness, 01 April 2012 - 06:17 AM
Henness #1
Posted 01 April 2012 - 08:17 AM
How could I go about making a scrolling intro for my program? The only way I have come up is to clear the screen and then print every thing agin and agin.
Is there a simple way of doing this? I want to basicly make some ASCII art scroll from right to left it will look weird if i post it here but Ill do it anyway.

	   d8888	  888												  888	  88888888888								  888
	  d88888	  888												  888		  888									  888
	 d88P888	  888												  888		  888									  888
	d88P 888  .d88888 888  888  8888b.  88888b.   .d8888b .d88b.   .d88888		  888  888  888 88888b.  88888b.   .d88b.  888
   d88P  888 d88" 888 888  888	 "88b 888 "88b d88P"   d8P  Y8b d88" 888		  888  888  888 888 "88b 888 "88b d8P  Y8b 888
  d88P   888 888  888 Y88  88P .d888888 888  888 888	 88888888 888  888		  888  888  888 888  888 888  888 88888888 888
d8888888888 Y88b 888  Y8bd8P  888  888 888  888 Y88b.   Y8b.	 Y88b 888		  888  Y88b 888 888  888 888  888 Y8b.	 888
d88P	 888  "Y88888   Y88P   "Y888888 888  888  "Y8888P "Y8888   "Y88888		  888   "Y88888 888  888 888  888  "Y8888  888 
Casper7526 #2
Posted 01 April 2012 - 08:48 AM
Well, you can clear only the lines that need updating, but if your making a sizeable intro, then you might as well clear the whole screen.
Henness #3
Posted 01 April 2012 - 09:21 AM
So there is no way to scroll some art across the screen with out doing this code 200 times?

term.clear()
term.setCursorPos( 1, 3 )
print ( [[Text]] )
sleep(0.5)
Henness #4
Posted 01 April 2012 - 10:50 AM
Here is my finished intro code its super repetitive, is there something i can do about that?
intro = true
if intro == true then
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
								  
								  
								  
								  
								  
								  
								  d
								 d8
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
								  
								  
								  d
								 d8
							    d88
							   d88P
							  d8888
							 d88P 
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
							    d88
							   d888
							  d88P8
							 d88P 8
						    d88P  8
						   d88P   8
						  d88888888
						 d88P	 8
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
						    d8888 
						   d88888 
						  d88P888 
						 d88P 888 
					    d88P  888 d
					   d88P   888 8
					  d8888888888 Y
					 d88P	 888 
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
					    d8888	 
					   d88888	 
					  d88P888	 
					 d88P 888  .d88
				    d88P  888 d88"
				   d88P   888 888 
				  d8888888888 Y88b
				 d88P	 888  "Y88
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
				    d8888	  888
				   d88888	  888
				  d88P888	  888
				 d88P 888  .d88888
			    d88P  888 d88" 888
			   d88P   888 888  888
			  d8888888888 Y88b 888
			 d88P	 888  "Y88888
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
			    d8888	  888	
			   d88888	  888	
			  d88P888	  888	
			 d88P 888  .d88888 888
		    d88P  888 d88" 888 888
		   d88P   888 888  888 Y88
		  d8888888888 Y88b 888  Y8b
		 d88P	 888  "Y88888   Y8
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
		    d8888	  888		
		   d88888	  888		
		  d88P888	  888		
		 d88P 888  .d88888 888  888
	    d88P  888 d88" 888 888  888
	   d88P   888 888  888 Y88  88P
	  d8888888888 Y88b 888  Y8bd8P
	 d88P	 888  "Y88888   Y88P 
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
	    d8888	  888			
	   d88888	  888			
	  d88P888	  888			
	 d88P 888  .d88888 888  888  88
    d88P  888 d88" 888 888  888   
   d88P   888 888  888 Y88  88P .d8
  d8888888888 Y88b 888  Y8bd8P  888
d88P	 888  "Y88888   Y88P   "Y8
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
    d8888	  888				
   d88888	  888				
  d88P888	  888				
d88P 888  .d88888 888  888  8888b.
d88P  888 d88" 888 888  888	 "88
88P   888 888  888 Y88  88P .d88888
888888888 Y88b 888  Y8bd8P  888  88
P	 888  "Y88888   Y88P   "Y88888
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
d8888	  888					
88888	  888					
8P888	  888					
P 888  .d88888 888  888  8888b.  88
  888 d88" 888 888  888	 "88b 88
  888 888  888 Y88  88P .d888888 88
88888 Y88b 888  Y8bd8P  888  888 88
  888  "Y88888   Y88P   "Y888888 88
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
8	  888						
8	  888						
8	  888						
8  .d88888 888  888  8888b.  88888b
8 d88" 888 888  888	 "88b 888 "8
8 888  888 Y88  88P .d888888 888  8
8 Y88b 888  Y8bd8P  888  888 888  8
8  "Y88888   Y88P   "Y888888 888  8
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
   888							
   888							
   888							
d88888 888  888  8888b.  88888b.  
8" 888 888  888	 "88b 888 "88b d
8  888 Y88  88P .d888888 888  888 8
8b 888  Y8bd8P  888  888 888  888 Y
Y88888   Y88P   "Y888888 888  888 
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
88								
88								
88								
88 888  888  8888b.  88888b.   .d88
88 888  888	 "88b 888 "88b d88P"
88 Y88  88P .d888888 888  888 888 
88  Y8bd8P  888  888 888  888 Y88b.
88   Y88P   "Y888888 888  888  "Y88
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
								  
								  
								  
88  888  8888b.  88888b.   .d8888b
88  888	 "88b 888 "88b d88P"   d
88  88P .d888888 888  888 888	 8
Y8bd8P  888  888 888  888 Y88b.   Y
Y88P   "Y888888 888  888  "Y8888P
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
								  
								  
								  
888  8888b.  88888b.   .d8888b .d88
888	 "88b 888 "88b d88P"   d8P 
88P .d888888 888  888 888	 88888
8P  888  888 888  888 Y88b.   Y8b.
P   "Y888888 888  888  "Y8888P "Y88
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
								  
								  
								  
8888b.  88888b.   .d8888b .d88b.  
   "88b 888 "88b d88P"   d8P  Y8b d
d888888 888  888 888	 88888888 8
88  888 888  888 Y88b.   Y8b.	 Y
Y888888 888  888  "Y8888P "Y8888  
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
								  
								  
								  
b.  88888b.   .d8888b .d88b.   .d88
88b 888 "88b d88P"   d8P  Y8b d88"
888 888  888 888	 88888888 888 
888 888  888 Y88b.   Y8b.	 Y88b
888 888  888  "Y8888P "Y8888   "Y88
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
							   888
							   888
							   888
88888b.   .d8888b .d88b.   .d88888
888 "88b d88P"   d8P  Y8b d88" 888
888  888 888	 88888888 888  888
888  888 Y88b.   Y8b.	 Y88b 888
888  888  "Y8888P "Y8888   "Y88888
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
						   888	
						   888	
						   888	
8b.   .d8888b .d88b.   .d88888	
"88b d88P"   d8P  Y8b d88" 888	
888 888	 88888888 888  888	
888 Y88b.   Y8b.	 Y88b 888	
888  "Y8888P "Y8888   "Y88888	
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
					   888	  888
					   888		
					   888		
  .d8888b .d88b.   .d88888		
d88P"   d8P  Y8b d88" 888		
888	 88888888 888  888		
Y88b.   Y8b.	 Y88b 888		
  "Y8888P "Y8888   "Y88888		
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
				   888	  8888888
				   888		  888
				   888		  888
8888b .d88b.   .d88888		  888
P"   d8P  Y8b d88" 888		  888
	 88888888 888  888		  888
b.   Y8b.	 Y88b 888		  888
8888P "Y8888   "Y88888		  888
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
			   888	  88888888888
			   888		  888   
			   888		  888   
b .d88b.   .d88888		  888  88
d8P  Y8b d88" 888		  888  88
88888888 888  888		  888  88
Y8b.	 Y88b 888		  888  Y8
P "Y8888   "Y88888		  888   "
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
		   888	  88888888888   
		   888		  888	   
		   888		  888	   
88b.   .d88888		  888  888  8
  Y8b d88" 888		  888  888  8
88888 888  888		  888  888  8
.	 Y88b 888		  888  Y88b 8
8888   "Y88888		  888   "Y888
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
	   888	  88888888888	   
	   888		  888		   
	   888		  888		   
   .d88888		  888  888  888 8
b d88" 888		  888  888  888 8
8 888  888		  888  888  888 8
  Y88b 888		  888  Y88b 888 8
   "Y88888		  888   "Y88888 8
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
   888	  88888888888		   
   888		  888			   
   888		  888			   
d88888		  888  888  888 88888
8" 888		  888  888  888 888 "
8  888		  888  888  888 888 
8b 888		  888  Y88b 888 888 
Y88888		  888   "Y88888 888 
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
88	  88888888888			   
88		  888				   
88		  888				   
88		  888  888  888 88888b. 
88		  888  888  888 888 "88b
88		  888  888  888 888  888
88		  888  Y88b 888 888  888
88		  888   "Y88888 888  888
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
    88888888888				   
	    888					   
	    888					   
	    888  888  888 88888b.  8888
	    888  888  888 888 "88b 888
	    888  888  888 888  888 888
	    888  Y88b 888 888  888 888
	    888   "Y88888 888  888 888
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
88888888888					   
    888						   
    888						   
    888  888  888 88888b.  88888b.
    888  888  888 888 "88b 888 "88b
    888  888  888 888  888 888  888
    888  Y88b 888 888  888 888  888
    888   "Y88888 888  888 888  888
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
8888888						   
888							   
888							   
888  888  888 88888b.  88888b.   .d
888  888  888 888 "88b 888 "88b d8P
888  888  888 888  888 888  888 888
888  Y88b 888 888  888 888  888 Y8b
888   "Y88888 888  888 888  888  "Y
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
888							   
								  
								  
888  888 88888b.  88888b.   .d88b.
888  888 888 "88b 888 "88b d8P  Y8
888  888 888  888 888  888 8888888
Y88b 888 888  888 888  888 Y8b.  
  "Y88888 888  888 888  888  "Y8888
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
								 88
								 88
								 88
  888 88888b.  88888b.   .d88b.  88
  888 888 "88b 888 "88b d8P  Y8b 88
  888 888  888 888  888 88888888 88
b 888 888  888 888  888 Y8b.	 88
88888 888  888 888  888  "Y8888  88
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
							 888  
							 888  
							 888  
8 88888b.  88888b.   .d88b.  888  
8 888 "88b 888 "88b d8P  Y8b 888  
8 888  888 888  888 88888888 888  
8 888  888 888  888 Y8b.	 888  
8 888  888 888  888  "Y8888  888  
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
						 888	  
						 888	  
						 888	  
888b.  88888b.   .d88b.  888	  
8 "88b 888 "88b d8P  Y8b 888	  
8  888 888  888 88888888 888	  
8  888 888  888 Y8b.	 888	  
8  888 888  888  "Y8888  888	  
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
					 888		  
					 888		  
					 888		  
.  88888b.   .d88b.  888		  
8b 888 "88b d8P  Y8b 888		  
88 888  888 88888888 888		  
88 888  888 Y8b.	 888		  
88 888  888  "Y8888  888		  
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
				 888			  
				 888			  
				 888			  
8888b.   .d88b.  888			  
88 "88b d8P  Y8b 888			  
88  888 88888888 888			  
88  888 Y8b.	 888			  
88  888  "Y8888  888			  
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
			 888				  
			 888				  
			 888				  
b.   .d88b.  888				  
88b d8P  Y8b 888				  
888 88888888 888				  
888 Y8b.	 888				  
888  "Y8888  888				  
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
		 888					  
		 888					  
		 888					  
.d88b.  888					  
d8P  Y8b 888					  
88888888 888					  
Y8b.	 888					  
"Y8888  888					  
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
	 888						  
	 888						  
	 888						  
8b.  888						  
Y8b 888						  
8888 888						  
	 888						  
888  888						  
]] )
sleep(0.001)
term.clear()
term.setCursorPos( 1, 3 )
print ( [[
888							  
888							  
888							  
888							  
888							  
888							  
888							  
888							  
]] )
term.clear()
sleep(1.0)
end
MysticT #5
Posted 01 April 2012 - 02:15 PM
You could save the lines in a variable and then make a function and use string.sub to get the part you need to draw. Something like this:

local tLines = {
"Line 1",
"Line 2",
"Line 3"
}
local nScreenW, nScreenH = term.getSize()

local function draw(n)
  term.clear()
  for y, line in ipairs(tLines) do
    local sTxt = string.sub(line, n, n + nScreenW)
    term.setCursorPos(1, y)
    term.write(sTxt)
  end
end

for i = 1, 6 do -- Change 6 to your text lenght
  draw(i)
end
I haven't tested it, so you may have to make some changes, but it's a start :)/>/>
Advert #6
Posted 01 April 2012 - 05:28 PM
You could use term.scroll, if you wanted to:


local text = {
	"Once upon a time",
	"In a world not so far, far away",
	"There was a block of TNT -- You.",
	"Steve had placed you.",
	"He held a redstone torch.",
	"You were scared.",
	"As Steve was about to place the torch,",
	"A creeper blew him up. The end."
}

local x, y = term.getSize()
term.clear()
for i = 1, #text do
	term.scroll(1)
	term.setCursorPos(8, y)
	term.write(text[i])
	sleep(4)
end

Edit: I seem to have missed the left/right part :)/>/>

MysticT's example works well.