Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bEnableAnimations = true
- function enable()
- bEnableAnimations = true
- end
- function disable()
- bEnableAnimations = false
- end
- local function getTableSize (tTable)
- local nSize = 0
- for _, __ in pairs (tTable) do
- nSize = nSize + 1
- end
- return nSize
- end
- local function getShrunkBuffer (tBuffer, nWidthScale, nHeightScale)
- nHeightScale = math.floor (nHeightScale)
- nWidthScale = math.floor (nWidthScale)
- -- Gotta set up new width and height dimensions so getChunks doesn't freak out!
- local tShrunkBuffer = {
- tText = {},
- tTextColors = {},
- tBackColors = {},
- tTerm = tBuffer.tTerm,
- bCursorBlink = false
- }
- local nShrunkLineNumber = 1
- local nLeftConstraint = tBuffer.nWidth / 2 - nWidthScale
- local nRightConstraint = tBuffer.nWidth / 2 + nWidthScale
- for nLineNumber = math.floor (tBuffer.nHeight / 2 - nHeightScale), math.floor (tBuffer.nHeight / 2 + nHeightScale) do
- if nLineNumber >= 1 and nLineNumber <= tBuffer.nHeight then
- tShrunkBuffer.tText[nShrunkLineNumber] = tBuffer.tText[nLineNumber]:sub (nLeftConstraint, nRightConstraint)
- tShrunkBuffer.tTextColors[nShrunkLineNumber] = tBuffer.tTextColors[nLineNumber]:sub (nLeftConstraint, nRightConstraint)
- tShrunkBuffer.tBackColors[nShrunkLineNumber] = tBuffer.tBackColors[nLineNumber]:sub (nLeftConstraint, nRightConstraint)
- end
- nShrunkLineNumber = nShrunkLineNumber + 1
- end
- tShrunkBuffer.nHeight = getTableSize (tShrunkBuffer.tText)
- return tShrunkBuffer
- end
- function openCenter (tBuffer, nRunTime, nModifier)
- if bEnableAnimations then
- local nModifier = nModifier or 1
- local nRequiredIterations = math.min (tBuffer.nWidth, tBuffer.nHeight)
- local nSleepTime = nRunTime / nRequiredIterations
- -- Step needs to be the amount of growth per sleep time to make it under the run time!
- local nWidthStep = tBuffer.nWidth / nRequiredIterations
- local nHeightStep = tBuffer.nHeight / nRequiredIterations
- local nWidthScale = nWidthStep
- local nHeightScale = nHeightStep
- for nTime = 0, nRunTime, nSleepTime * nModifier do
- local tShrunkBuffer = setmetatable (getShrunkBuffer (tBuffer, nWidthScale, nHeightScale), { __index = tBuffer })
- if #tShrunkBuffer.tText > 0 then
- tShrunkBuffer.x = tBuffer.nWidth / 2 - tShrunkBuffer.tText[1]:len() / 2
- tShrunkBuffer.y = math.max (tBuffer.nHeight / 2 - tShrunkBuffer.nHeight / 2, tBuffer.y)
- tBuffer.render (tShrunkBuffer)
- else
- break
- end
- sleep (nSleepTime)
- nWidthScale = nWidthScale + nWidthStep * nModifier
- nHeightScale = nHeightScale + nHeightStep * nModifier
- end
- end
- return tBuffer:render()
- end
- function openCenterColoredRectangle (nColor, nWidth, nHeight, nRunTime, nModifier)
- openCenter (
- Buffer.new (nWidth, nHeight, 1, 1, term.current()):setBackgroundColor (nColor):clear(),
- nRunTime,
- nModifier
- )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement