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

Complete Noob...

Started by Pirate, 17 April 2013 - 06:18 PM
Pirate #1
Posted 17 April 2013 - 08:18 PM
Hi guys. Complete coding noob here. Has anyone written a simple program to display flashing text in the center of the screen/monitor?
GravityScore #2
Posted 17 April 2013 - 09:30 PM

side = "right" -- replace right with the side your monitor is on, or with nothing if you want to display it on the computer screen
text = "hello" -- replace hello with the text you want displayed
flashSpeed = 2 -- replace with the speed you want to flash at, measured in seconds

if side ~= "" then term.redirect(peripheral.wrap(side)) end
w, h = term.getSize()
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)

while true do
  term.clear()
  sleep(flashSpeed)
  term.setCursorPos((w + 1)/2 - text:len()/2, h/2)
  term.write(text)
  sleep(flashSpeed)
end

There you go. It will display text in the center of a monitor or screen, depending on the side variable. If you want me to explain it, just ask. :)/>
Cruor #3
Posted 18 April 2013 - 01:38 AM
Moved to Ask a Pro.
TheOddByte #4
Posted 18 April 2013 - 11:18 AM
What do you mean with flashing?
Do you mean as GravityScore showed or with colors?

--[[
Flashing Text
]]--
w,h = term.getSize()

function clear()
  term.clear()
	 term.setCursorPos(1,1)
  end

function centerPrint(y,text)
  term.setCursorPos(w/2 - #text/2, y)
   write(text)
end


function main(t)
while true do
clear()
  term.setTextColor(2 ^ math.random(1,15) )
centerPrint(h/2,"Enter Message Here!")
 sleep(t)
  end
end

main(0.1)

Otherwise you'll have to explain better what you mean with flashing text..
But anyway, Hope you liked this ;)/>