mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2025-12-21 03:29:22 +01:00
functions < math
This commit is contained in:
parent
542e312186
commit
00f19b2c46
30
lib/GUI.lua
30
lib/GUI.lua
@ -1321,8 +1321,8 @@ local function dropDownMenuItemDraw(item)
|
|||||||
return item
|
return item
|
||||||
end
|
end
|
||||||
|
|
||||||
local function dropDownMenuItemEventHandler(mainContainer, object, event)
|
local function dropDownMenuItemEventHandler(mainContainer, object, e1)
|
||||||
if event == "touch" then
|
if e1 == "touch" then
|
||||||
if object.type == GUI.dropDownMenuItemTypes.default then
|
if object.type == GUI.dropDownMenuItemTypes.default then
|
||||||
object.pressed = true
|
object.pressed = true
|
||||||
mainContainer:drawOnScreen()
|
mainContainer:drawOnScreen()
|
||||||
@ -1447,8 +1447,8 @@ local function dropDownMenuShow(menu)
|
|||||||
local mainContainer = GUI.fullScreenContainer()
|
local mainContainer = GUI.fullScreenContainer()
|
||||||
-- Удаляем олдпиксельсы, чтоб старое дерьмое не рисовалось во всяких комбобоксах
|
-- Удаляем олдпиксельсы, чтоб старое дерьмое не рисовалось во всяких комбобоксах
|
||||||
menu.oldPixels = nil
|
menu.oldPixels = nil
|
||||||
mainContainer:addChild(GUI.object(1, 1, mainContainer.width, mainContainer.height)).eventHandler = function(mainContainer, object, event)
|
mainContainer:addChild(GUI.object(1, 1, mainContainer.width, mainContainer.height)).eventHandler = function(mainContainer, object, e1)
|
||||||
if event == "touch" then
|
if e1 == "touch" then
|
||||||
buffer.paste(menu.x, menu.y, menu.oldPixels)
|
buffer.paste(menu.x, menu.y, menu.oldPixels)
|
||||||
buffer.draw()
|
buffer.draw()
|
||||||
mainContainer:stopEventHandling()
|
mainContainer:stopEventHandling()
|
||||||
@ -2429,8 +2429,8 @@ local function filesystemChooserSetMode(object, IOMode, filesystemMode)
|
|||||||
object.filesystemMode = filesystemMode
|
object.filesystemMode = filesystemMode
|
||||||
end
|
end
|
||||||
|
|
||||||
local function filesystemChooserEventHandler(mainContainer, object, event)
|
local function filesystemChooserEventHandler(mainContainer, object, e1)
|
||||||
if event == "touch" then
|
if e1 == "touch" then
|
||||||
object.pressed = true
|
object.pressed = true
|
||||||
mainContainer:drawOnScreen()
|
mainContainer:drawOnScreen()
|
||||||
|
|
||||||
@ -3329,8 +3329,8 @@ local function inputStartInput(input)
|
|||||||
mainContainer:drawOnScreen()
|
mainContainer:drawOnScreen()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function inputEventHandler(mainContainer, input, event)
|
local function inputEventHandler(mainContainer, input, e1)
|
||||||
if event == "touch" then
|
if e1 == "touch" then
|
||||||
input:startInput()
|
input:startInput()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -3428,14 +3428,14 @@ local function autoCompleteScroll(mainContainer, object, direction)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function autoCompleteEventHandler(mainContainer, object, e1, e2, e3, e4, ...)
|
local function autoCompleteEventHandler(mainContainer, object, e1, e2, e3, e4, e5, ...)
|
||||||
if e1 == "touch" then
|
if e1 == "touch" then
|
||||||
object.selectedItem = e4 - object.y + object.fromItem
|
object.selectedItem = e4 - object.y + object.fromItem
|
||||||
mainContainer:drawOnScreen()
|
mainContainer:drawOnScreen()
|
||||||
|
|
||||||
if object.onItemSelected then
|
if object.onItemSelected then
|
||||||
os.sleep(0.2)
|
os.sleep(0.2)
|
||||||
object.onItemSelected(mainContainer, object, e1, e2, e3, e4, ...)
|
object.onItemSelected(mainContainer, object, e1, e2, e3, e4, e5, ...)
|
||||||
end
|
end
|
||||||
elseif e1 == "scroll" then
|
elseif e1 == "scroll" then
|
||||||
autoCompleteScroll(mainContainer, object, -e5)
|
autoCompleteScroll(mainContainer, object, -e5)
|
||||||
@ -3443,7 +3443,7 @@ local function autoCompleteEventHandler(mainContainer, object, e1, e2, e3, e4, .
|
|||||||
elseif e1 == "key_down" then
|
elseif e1 == "key_down" then
|
||||||
if e4 == 28 then
|
if e4 == 28 then
|
||||||
if object.onItemSelected then
|
if object.onItemSelected then
|
||||||
object.onItemSelected(mainContainer, object, e1, e2, e3, e4, ...)
|
object.onItemSelected(mainContainer, object, e1, e2, e3, e4, e5, ...)
|
||||||
end
|
end
|
||||||
elseif e4 == 200 then
|
elseif e4 == 200 then
|
||||||
object.selectedItem = object.selectedItem - 1
|
object.selectedItem = object.selectedItem - 1
|
||||||
@ -3715,7 +3715,7 @@ function GUI.palette(x, y, startColor)
|
|||||||
local function paletteUpdateCrestsCoordinates()
|
local function paletteUpdateCrestsCoordinates()
|
||||||
bigCrest.localX = math.floor((bigImage.width - 1) * palette.color.hsb.saturation) - 1
|
bigCrest.localX = math.floor((bigImage.width - 1) * palette.color.hsb.saturation) - 1
|
||||||
bigCrest.localY = math.floor((bigImage.height - 1) - (bigImage.height - 1) * palette.color.hsb.brightness)
|
bigCrest.localY = math.floor((bigImage.height - 1) - (bigImage.height - 1) * palette.color.hsb.brightness)
|
||||||
miniCrest.localY = math.floor(palette.color.hsb.hue / 360 * miniImage.height)
|
miniCrest.localY = math.ceil(palette.color.hsb.hue / 360 * miniImage.height + 0.5)
|
||||||
end
|
end
|
||||||
|
|
||||||
local inputs
|
local inputs
|
||||||
@ -3865,7 +3865,7 @@ function GUI.palette(x, y, startColor)
|
|||||||
bigCrest.eventHandler = bigImage.eventHandler
|
bigCrest.eventHandler = bigImage.eventHandler
|
||||||
|
|
||||||
miniImage.eventHandler = function(mainContainer, object, e1, e2, e3, e4)
|
miniImage.eventHandler = function(mainContainer, object, e1, e2, e3, e4)
|
||||||
if event == "touch" or event == "drag" then
|
if e1 == "touch" or e1 == "drag" then
|
||||||
miniCrest.localY = e4 - palette.y + 1
|
miniCrest.localY = e4 - palette.y + 1
|
||||||
paletteSwitchColorFromHsb((e4 - miniImage.y) * 360 / miniImage.height, palette.color.hsb.saturation, palette.color.hsb.brightness)
|
paletteSwitchColorFromHsb((e4 - miniImage.y) * 360 / miniImage.height, palette.color.hsb.saturation, palette.color.hsb.brightness)
|
||||||
paletteRefreshBigImage()
|
paletteRefreshBigImage()
|
||||||
@ -3915,8 +3915,8 @@ function GUI.addFadeContainer(parentContainer, addPanel, addLayout, title)
|
|||||||
|
|
||||||
if addPanel then
|
if addPanel then
|
||||||
container.panel = container:addChild(GUI.panel(1, 1, container.width, container.height, 0x0, GUI.colors.fadeContainer.transparency))
|
container.panel = container:addChild(GUI.panel(1, 1, container.width, container.height, 0x0, GUI.colors.fadeContainer.transparency))
|
||||||
container.panel.eventHandler = function(parentContainer, object, event)
|
container.panel.eventHandler = function(parentContainer, object, e1)
|
||||||
if event == "touch" then
|
if e1 == "touch" then
|
||||||
container:delete()
|
container:delete()
|
||||||
parentContainer:drawOnScreen()
|
parentContainer:drawOnScreen()
|
||||||
end
|
end
|
||||||
|
|||||||
@ -14,8 +14,7 @@ local color = {}
|
|||||||
-- Optimized Lua 5.3 bitwise support
|
-- Optimized Lua 5.3 bitwise support
|
||||||
if computer.getArchitecture and computer.getArchitecture() == "Lua 5.3" then
|
if computer.getArchitecture and computer.getArchitecture() == "Lua 5.3" then
|
||||||
integerToRGB, RGBToInteger, blend, transition, to8Bit = load([[
|
integerToRGB, RGBToInteger, blend, transition, to8Bit = load([[
|
||||||
local palette = select(1, ...)
|
local mathHuge, palette = math.huge, select(1, ...)
|
||||||
local mathHuge = math.huge
|
|
||||||
|
|
||||||
return
|
return
|
||||||
function(integerColor)
|
function(integerColor)
|
||||||
@ -27,21 +26,19 @@ if computer.getArchitecture and computer.getArchitecture() == "Lua 5.3" then
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
function(color1, color2, transparency)
|
function(color1, color2, transparency)
|
||||||
local invertedTransparency, r1, g1, b1, r2, g2, b2 = 1 - transparency, color1 >> 16, color1 >> 8 & 0xFF, color1 & 0xFF, color2 >> 16, color2 >> 8 & 0xFF, color2 & 0xFF
|
local invertedTransparency = 1 - transparency
|
||||||
|
|
||||||
return
|
return
|
||||||
(r2 * invertedTransparency + r1 * transparency) // 1 << 16 |
|
((color2 >> 16) * invertedTransparency + (color1 >> 16) * transparency) // 1 << 16 |
|
||||||
(g2 * invertedTransparency + g1 * transparency) // 1 << 8 |
|
((color2 >> 8 & 0xFF) * invertedTransparency + (color1 >> 8 & 0xFF) * transparency) // 1 << 8 |
|
||||||
(b2 * invertedTransparency + b1 * transparency) // 1
|
((color2 & 0xFF) * invertedTransparency + (color1 & 0xFF) * transparency) // 1
|
||||||
end,
|
end,
|
||||||
|
|
||||||
function(color1, color2, position)
|
function(color1, color2, position)
|
||||||
local r1, g1, b1, r2, g2, b2 = color1 >> 16, color1 >> 8 & 0xFF, color1 & 0xFF, color2 >> 16, color2 >> 8 & 0xFF, color2 & 0xFF
|
local r1, g1, b1 = color1 >> 16, color1 >> 8 & 0xFF, color1 & 0xFF
|
||||||
|
|
||||||
return
|
return
|
||||||
(r1 + (r2 - r1) * position) // 1 << 16 |
|
(r1 + ((color2 >> 16) - r1) * position) // 1 << 16 |
|
||||||
(g1 + (g2 - g1) * position) // 1 << 8 |
|
(g1 + ((color2 >> 8 & 0xFF) - g1) * position) // 1 << 8 |
|
||||||
(b1 + (b2 - b1) * position) // 1
|
(b1 + ((color2 & 0xFF) - b1) * position) // 1
|
||||||
end,
|
end,
|
||||||
|
|
||||||
function(color24Bit)
|
function(color24Bit)
|
||||||
@ -67,8 +64,7 @@ if computer.getArchitecture and computer.getArchitecture() == "Lua 5.3" then
|
|||||||
]])(palette)
|
]])(palette)
|
||||||
else
|
else
|
||||||
integerToRGB, RGBToInteger, blend, transition, to8Bit = load([[
|
integerToRGB, RGBToInteger, blend, transition, to8Bit = load([[
|
||||||
local palette = select(1, ...)
|
local mathHuge, palette = math.huge, select(1, ...)
|
||||||
local mathHuge = math.huge
|
|
||||||
|
|
||||||
return
|
return
|
||||||
function(integerColor)
|
function(integerColor)
|
||||||
@ -91,18 +87,16 @@ else
|
|||||||
r1 = r1 - r1 % 1
|
r1 = r1 - r1 % 1
|
||||||
local g1 = (color1 - r1 * 65536) / 256
|
local g1 = (color1 - r1 * 65536) / 256
|
||||||
g1 = g1 - g1 % 1
|
g1 = g1 - g1 % 1
|
||||||
local b1 = color1 - r1 * 65536 - g1 * 256
|
|
||||||
|
|
||||||
local r2 = color2 / 65536
|
local r2 = color2 / 65536
|
||||||
r2 = r2 - r2 % 1
|
r2 = r2 - r2 % 1
|
||||||
local g2 = (color2 - r2 * 65536) / 256
|
local g2 = (color2 - r2 * 65536) / 256
|
||||||
g2 = g2 - g2 % 1
|
g2 = g2 - g2 % 1
|
||||||
local b2 = color2 - r2 * 65536 - g2 * 256
|
|
||||||
|
|
||||||
local r, g, b =
|
local r, g, b =
|
||||||
r2 * invertedTransparency + r1 * transparency,
|
r2 * invertedTransparency + r1 * transparency,
|
||||||
g2 * invertedTransparency + g1 * transparency,
|
g2 * invertedTransparency + g1 * transparency,
|
||||||
b2 * invertedTransparency + b1 * transparency
|
(color2 - r2 * 65536 - g2 * 256) * invertedTransparency + (color1 - r1 * 65536 - g1 * 256) * transparency
|
||||||
|
|
||||||
return
|
return
|
||||||
(r - r % 1) * 65536 +
|
(r - r % 1) * 65536 +
|
||||||
@ -121,12 +115,11 @@ else
|
|||||||
r2 = r2 - r2 % 1
|
r2 = r2 - r2 % 1
|
||||||
local g2 = (color2 - r2 * 65536) / 256
|
local g2 = (color2 - r2 * 65536) / 256
|
||||||
g2 = g2 - g2 % 1
|
g2 = g2 - g2 % 1
|
||||||
local b2 = color2 - r2 * 65536 - g2 * 256
|
|
||||||
|
|
||||||
local r, g, b =
|
local r, g, b =
|
||||||
r1 + (r2 - r1) * position,
|
r1 + (r2 - r1) * position,
|
||||||
g1 + (g2 - g1) * position,
|
g1 + (g2 - g1) * position,
|
||||||
b1 + (b2 - b1) * position
|
b1 + (color2 - r2 * 65536 - g2 * 256 - b1) * position
|
||||||
|
|
||||||
return
|
return
|
||||||
(r - r % 1) * 65536 +
|
(r - r % 1) * 65536 +
|
||||||
|
|||||||
@ -19,8 +19,8 @@ local unicodeLen, unicodeSub = unicode.len, unicode.sub
|
|||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
local function getCoordinates(index)
|
local function getCoordinates(index)
|
||||||
local integer, fractional = mathModf(index / bufferWidth)
|
local integer, fractional = index / bufferWidth, index % bufferWidth
|
||||||
return mathCeil(fractional * bufferWidth), integer + 1
|
return fractional, integer - fractional + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getIndex(x, y)
|
local function getIndex(x, y)
|
||||||
@ -133,7 +133,7 @@ end
|
|||||||
|
|
||||||
local function get(x, y)
|
local function get(x, y)
|
||||||
if x >= 1 and y >= 1 and x <= bufferWidth and y <= bufferHeight then
|
if x >= 1 and y >= 1 and x <= bufferWidth and y <= bufferHeight then
|
||||||
local index = getIndex(x, y)
|
local index = bufferWidth * (y - 1) + x
|
||||||
return newFrameBackgrounds[index], newFrameForegrounds[index], newFrameSymbols[index]
|
return newFrameBackgrounds[index], newFrameForegrounds[index], newFrameSymbols[index]
|
||||||
else
|
else
|
||||||
return 0x000000, 0x000000, " "
|
return 0x000000, 0x000000, " "
|
||||||
@ -142,13 +142,13 @@ end
|
|||||||
|
|
||||||
local function set(x, y, background, foreground, symbol)
|
local function set(x, y, background, foreground, symbol)
|
||||||
if x >= drawLimitX1 and y >= drawLimitY1 and x <= drawLimitX2 and y <= drawLimitY2 then
|
if x >= drawLimitX1 and y >= drawLimitY1 and x <= drawLimitX2 and y <= drawLimitY2 then
|
||||||
local index = getIndex(x, y)
|
local index = bufferWidth * (y - 1) + x
|
||||||
newFrameBackgrounds[index], newFrameForegrounds[index], newFrameSymbols[index] = background, foreground, symbol
|
newFrameBackgrounds[index], newFrameForegrounds[index], newFrameSymbols[index] = background, foreground, symbol
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function square(x, y, width, height, background, foreground, symbol, transparency)
|
local function square(x, y, width, height, background, foreground, symbol, transparency)
|
||||||
local index, indexStepOnReachOfSquareWidth = getIndex(x, y), bufferWidth - width
|
local index, indexStepOnReachOfSquareWidth = bufferWidth * (y - 1) + x, bufferWidth - width
|
||||||
for j = y, y + height - 1 do
|
for j = y, y + height - 1 do
|
||||||
if j >= drawLimitY1 and j <= drawLimitY2 then
|
if j >= drawLimitY1 and j <= drawLimitY2 then
|
||||||
for i = x, x + width - 1 do
|
for i = x, x + width - 1 do
|
||||||
@ -182,7 +182,7 @@ local function copy(x, y, width, height)
|
|||||||
for j = y, y + height - 1 do
|
for j = y, y + height - 1 do
|
||||||
for i = x, x + width - 1 do
|
for i = x, x + width - 1 do
|
||||||
if i >= 1 and j >= 1 and i <= bufferWidth and j <= bufferHeight then
|
if i >= 1 and j >= 1 and i <= bufferWidth and j <= bufferHeight then
|
||||||
index = getIndex(i, j)
|
index = bufferWidth * (j - 1) + i
|
||||||
tableInsert(copyArray, newFrameBackgrounds[index])
|
tableInsert(copyArray, newFrameBackgrounds[index])
|
||||||
tableInsert(copyArray, newFrameForegrounds[index])
|
tableInsert(copyArray, newFrameForegrounds[index])
|
||||||
tableInsert(copyArray, newFrameSymbols[index])
|
tableInsert(copyArray, newFrameSymbols[index])
|
||||||
@ -197,13 +197,13 @@ local function copy(x, y, width, height)
|
|||||||
return copyArray
|
return copyArray
|
||||||
end
|
end
|
||||||
|
|
||||||
local function paste(xStart, yStart, picture)
|
local function paste(startX, startY, picture)
|
||||||
local imageWidth = picture[1]
|
local imageWidth = picture[1]
|
||||||
local bufferIndex, imageIndex, bufferIndexStepOnReachOfImageWidth = getIndex(xStart, yStart), 3, bufferWidth - imageWidth
|
local bufferIndex, imageIndex, bufferIndexStepOnReachOfImageWidth = bufferWidth * (startY - 1) + startX, 3, bufferWidth - imageWidth
|
||||||
|
|
||||||
for y = yStart, yStart + picture[2] - 1 do
|
for y = startY, startY + picture[2] - 1 do
|
||||||
if y >= drawLimitY1 and y <= drawLimitY2 then
|
if y >= drawLimitY1 and y <= drawLimitY2 then
|
||||||
for x = xStart, xStart + imageWidth - 1 do
|
for x = startX, startX + imageWidth - 1 do
|
||||||
if x >= drawLimitX1 and x <= drawLimitX2 then
|
if x >= drawLimitX1 and x <= drawLimitX2 then
|
||||||
newFrameBackgrounds[bufferIndex] = picture[imageIndex]
|
newFrameBackgrounds[bufferIndex] = picture[imageIndex]
|
||||||
newFrameForegrounds[bufferIndex] = picture[imageIndex + 1]
|
newFrameForegrounds[bufferIndex] = picture[imageIndex + 1]
|
||||||
@ -293,7 +293,7 @@ end
|
|||||||
|
|
||||||
local function text(x, y, textColor, data, transparency)
|
local function text(x, y, textColor, data, transparency)
|
||||||
if y >= drawLimitY1 and y <= drawLimitY2 then
|
if y >= drawLimitY1 and y <= drawLimitY2 then
|
||||||
local charIndex, bufferIndex = 1, getIndex(x, y)
|
local charIndex, bufferIndex = 1, bufferWidth * (y - 1) + x
|
||||||
|
|
||||||
for charIndex = 1, unicodeLen(data) do
|
for charIndex = 1, unicodeLen(data) do
|
||||||
if x >= drawLimitX1 and x <= drawLimitX2 then
|
if x >= drawLimitX1 and x <= drawLimitX2 then
|
||||||
@ -313,7 +313,7 @@ end
|
|||||||
|
|
||||||
local function formattedText(x, y, data)
|
local function formattedText(x, y, data)
|
||||||
if y >= drawLimitY1 and y <= drawLimitY2 then
|
if y >= drawLimitY1 and y <= drawLimitY2 then
|
||||||
local charIndex, bufferIndex, textColor, char, number = 1, getIndex(x, y), 0xFFFFFF
|
local charIndex, bufferIndex, textColor, char, number = 1, bufferWidth * (y - 1) + x, 0xFFFFFF
|
||||||
|
|
||||||
while charIndex <= unicodeLen(text) do
|
while charIndex <= unicodeLen(text) do
|
||||||
if x >= drawLimitX1 and x <= drawLimitX2 then
|
if x >= drawLimitX1 and x <= drawLimitX2 then
|
||||||
@ -335,13 +335,13 @@ local function formattedText(x, y, data)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function image(xStart, yStart, picture, blendForeground)
|
local function image(startX, startY, picture, blendForeground)
|
||||||
local imageWidth = picture[1]
|
local imageWidth = picture[1]
|
||||||
local bufferIndex, imageIndex, bufferIndexStepOnReachOfImageWidth, imageIndexPlus1, imageIndexPlus2, imageIndexPlus3 = getIndex(xStart, yStart), 3, bufferWidth - imageWidth
|
local bufferIndex, imageIndex, bufferIndexStepOnReachOfImageWidth, imageIndexPlus1, imageIndexPlus2, imageIndexPlus3 = bufferWidth * (startY - 1) + startX, 3, bufferWidth - imageWidth
|
||||||
|
|
||||||
for y = yStart, yStart + picture[2] - 1 do
|
for y = startY, startY + picture[2] - 1 do
|
||||||
if y >= drawLimitY1 and y <= drawLimitY2 then
|
if y >= drawLimitY1 and y <= drawLimitY2 then
|
||||||
for x = xStart, xStart + imageWidth - 1 do
|
for x = startX, startX + imageWidth - 1 do
|
||||||
if x >= drawLimitX1 and x <= drawLimitX2 then
|
if x >= drawLimitX1 and x <= drawLimitX2 then
|
||||||
imageIndexPlus1, imageIndexPlus2, imageIndexPlus3 = imageIndex + 1, imageIndex + 2, imageIndex + 3
|
imageIndexPlus1, imageIndexPlus2, imageIndexPlus3 = imageIndex + 1, imageIndex + 2, imageIndex + 3
|
||||||
|
|
||||||
@ -424,12 +424,12 @@ end
|
|||||||
local function semiPixelSet(x, y, color)
|
local function semiPixelSet(x, y, color)
|
||||||
local yFixed = mathCeil(y / 2)
|
local yFixed = mathCeil(y / 2)
|
||||||
if x >= drawLimitX1 and yFixed >= drawLimitY1 and x <= drawLimitX2 and yFixed <= drawLimitY2 then
|
if x >= drawLimitX1 and yFixed >= drawLimitY1 and x <= drawLimitX2 and yFixed <= drawLimitY2 then
|
||||||
semiPixelRawSet(getIndex(x, yFixed), color, y % 2 == 0)
|
semiPixelRawSet(bufferWidth * (yFixed - 1) + x, color, y % 2 == 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function semiPixelSquare(x, y, width, height, color)
|
local function semiPixelSquare(x, y, width, height, color)
|
||||||
local index, indexStepForward, indexStepBackward, jPercentTwoEqualsZero, jFixed = getIndex(x, mathCeil(y / 2)), (bufferWidth - width), width
|
local index, indexStepForward, indexStepBackward, jPercentTwoEqualsZero, jFixed = bufferWidth * (mathCeil(y / 2) - 1) + x, (bufferWidth - width), width
|
||||||
for j = y, y + height - 1 do
|
for j = y, y + height - 1 do
|
||||||
jPercentTwoEqualsZero = j % 2 == 0
|
jPercentTwoEqualsZero = j % 2 == 0
|
||||||
|
|
||||||
@ -603,10 +603,12 @@ end
|
|||||||
local function draw(force)
|
local function draw(force)
|
||||||
-- local oldClock = os.clock()
|
-- local oldClock = os.clock()
|
||||||
|
|
||||||
local index, indexStepOnEveryLine, changes = getIndex(drawLimitX1, drawLimitY1), (bufferWidth - drawLimitX2 + drawLimitX1 - 1), {}
|
local index, indexStepOnEveryLine, changes = bufferWidth * (drawLimitY1 - 1) + drawLimitX1, (bufferWidth - drawLimitX2 + drawLimitX1 - 1), {}
|
||||||
local x, equalChars, charX, charIndex, currentForeground
|
local x, equalChars, equalCharsIndex, charX, charIndex, currentForeground
|
||||||
local currentFrameBackground, currentFrameForeground, currentFrameSymbol, changesCurrentFrameBackground, changesCurrentFrameBackgroundCurrentFrameForeground
|
local currentFrameBackground, currentFrameForeground, currentFrameSymbol, changesCurrentFrameBackground, changesCurrentFrameBackgroundCurrentFrameForeground
|
||||||
|
|
||||||
|
local changesCurrentFrameBackgroundCurrentFrameForegroundIndex
|
||||||
|
|
||||||
for y = drawLimitY1, drawLimitY2 do
|
for y = drawLimitY1, drawLimitY2 do
|
||||||
x = drawLimitX1
|
x = drawLimitX1
|
||||||
while x <= drawLimitX2 do
|
while x <= drawLimitX2 do
|
||||||
@ -624,7 +626,7 @@ local function draw(force)
|
|||||||
currentFrameSymbols[index] = currentFrameSymbol
|
currentFrameSymbols[index] = currentFrameSymbol
|
||||||
|
|
||||||
-- Look for pixels with equal chars from right of current pixel
|
-- Look for pixels with equal chars from right of current pixel
|
||||||
equalChars, charX, charIndex = {currentFrameSymbol}, x + 1, index + 1
|
equalChars, equalCharsIndex, charX, charIndex = {currentFrameSymbol}, 2, x + 1, index + 1
|
||||||
while charX <= drawLimitX2 do
|
while charX <= drawLimitX2 do
|
||||||
-- Pixels becomes equal only if they have same background and (whitespace char or same foreground)
|
-- Pixels becomes equal only if they have same background and (whitespace char or same foreground)
|
||||||
if
|
if
|
||||||
@ -639,7 +641,7 @@ local function draw(force)
|
|||||||
currentFrameForegrounds[charIndex] = newFrameForegrounds[charIndex]
|
currentFrameForegrounds[charIndex] = newFrameForegrounds[charIndex]
|
||||||
currentFrameSymbols[charIndex] = newFrameSymbols[charIndex]
|
currentFrameSymbols[charIndex] = newFrameSymbols[charIndex]
|
||||||
|
|
||||||
tableInsert(equalChars, currentFrameSymbols[charIndex])
|
equalChars[equalCharsIndex], equalCharsIndex = currentFrameSymbols[charIndex], equalCharsIndex + 1
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -650,14 +652,15 @@ local function draw(force)
|
|||||||
-- Group pixels that need to be drawn by background and foreground
|
-- Group pixels that need to be drawn by background and foreground
|
||||||
changes[currentFrameBackground] = changes[currentFrameBackground] or {}
|
changes[currentFrameBackground] = changes[currentFrameBackground] or {}
|
||||||
changesCurrentFrameBackground = changes[currentFrameBackground]
|
changesCurrentFrameBackground = changes[currentFrameBackground]
|
||||||
changesCurrentFrameBackground[currentFrameForeground] = changesCurrentFrameBackground[currentFrameForeground] or {}
|
changesCurrentFrameBackground[currentFrameForeground] = changesCurrentFrameBackground[currentFrameForeground] or {index = 1}
|
||||||
changesCurrentFrameBackgroundCurrentFrameForeground = changesCurrentFrameBackground[currentFrameForeground]
|
changesCurrentFrameBackgroundCurrentFrameForeground = changesCurrentFrameBackground[currentFrameForeground]
|
||||||
|
changesCurrentFrameBackgroundCurrentFrameForegroundIndex = changesCurrentFrameBackgroundCurrentFrameForeground.index
|
||||||
|
|
||||||
tableInsert(changesCurrentFrameBackgroundCurrentFrameForeground, x)
|
changesCurrentFrameBackgroundCurrentFrameForeground[changesCurrentFrameBackgroundCurrentFrameForegroundIndex], changesCurrentFrameBackgroundCurrentFrameForegroundIndex = x, changesCurrentFrameBackgroundCurrentFrameForegroundIndex + 1
|
||||||
tableInsert(changesCurrentFrameBackgroundCurrentFrameForeground, y)
|
changesCurrentFrameBackgroundCurrentFrameForeground[changesCurrentFrameBackgroundCurrentFrameForegroundIndex], changesCurrentFrameBackgroundCurrentFrameForegroundIndex = y, changesCurrentFrameBackgroundCurrentFrameForegroundIndex + 1
|
||||||
tableInsert(changesCurrentFrameBackgroundCurrentFrameForeground, tableConcat(equalChars))
|
changesCurrentFrameBackgroundCurrentFrameForeground[changesCurrentFrameBackgroundCurrentFrameForegroundIndex], changesCurrentFrameBackgroundCurrentFrameForegroundIndex = tableConcat(equalChars), changesCurrentFrameBackgroundCurrentFrameForegroundIndex + 1
|
||||||
|
|
||||||
x, index = x + #equalChars - 1, index + #equalChars - 1
|
x, index, changesCurrentFrameBackgroundCurrentFrameForeground.index = x + equalCharsIndex - 2, index + equalCharsIndex - 2, changesCurrentFrameBackgroundCurrentFrameForegroundIndex
|
||||||
end
|
end
|
||||||
|
|
||||||
x, index = x + 1, index + 1
|
x, index = x + 1, index + 1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user