Posted 06 February 2015 - 01:50 AM
I am making a program to connect to tny.cz (like pastebin) using the http API. But the reason I'm asking about this is my loading screen. When I start the program, the loading screen flashes. I want the loading circle to sort of spin.
loading = 5
loadStage = 0
printActive = false
rednet.open("top")
function refreshLink()
h = http.get("http://tny.cz/57e18bf1")
y = h.readAll()
end
function checkPaste()
sleep(0)
if string.find(y,"ason") then
autoSpawner = true
else
autoSpawner = false
end
end
function getPrintableVars()
if autoSpawner == true then
autoSpawnerPrint = "on"
autoSpawnColor = colors.lime
else
autoSpawnerPrint = "off"
autoSpawnColor = colors.red
end
end
function printState()
printActive = true
term.clear()
term.setCursorPos(1,1)
term.setTextColor(autoSpawnColor)
print("Auto Spawner is ".. autoSpawnerPrint)
sleep(0)
printActive = false
end
function loading()
loading = 5
repeat
refreshLink()
checkPaste()
getPrintableVars()
screenX, screenY = term.getSize()
screenX = screenX/2
screenY = screenY/2
term.clear()
term.setCursorPos(screenX-14,screenY-1)
term.setTextColor(colors.yellow)
print("InternetCraft Version Beta 1.0")
term.setCursorPos(screenX-3,screenY)
.setTextColor(colors.red)
print("Loading...")
stage()
loadingCircle()
loading = loading - 1
until loading == 0
end
function stage()
sleep(0)
loadStage = loadStage + 1
if loadStage == 5 then
loadStage = 1
end
loadColor1 = colors.white
loadColor2 = colors.white
loadColor3 = colors.white
loadColor4 = colors.white
if loadStage == 1 then
loadColor1 = colors.gray
elseif loadStage == 2 then
loadColor2 = colors.gray
elseif loadStage == 3 then
loadColor3 = colors.gray
elseif loadStage == 4 then
loadColor4 = colors.gray
end
end
function loadingCircle()
stage()
term.setBackgroundColor(loadColor1)
term.setCursorPos(screenX-1,screenY+2)
print(" ")
term.setBackgroundColor(loadColor2)
term.setCursorPos(screenX+1,screenY+2)
print(" ")
term.setBackgroundColor(loadColor4)
term.setCursorPos(screenX-1,screenY+4)
print(" ")
term.setBackgroundColor(loadColor3)
term.setCursorPos(screenX+1,screenY+4)
print(" ")
term.setBackgroundColor(colors.black)
end
loading()
while true do
if loading == 0 then
checkPaste()
getPrintableVars()
sleep(1)
refreshLink()
if printActive == false then
printState()
end
end
end