mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-14 12:29:30 -07:00
"Flattening" the faded images and glyphs into a 2D array of images reduces the number of draw calls per update to one per changed glyph
This commit is contained in:
@@ -8,18 +8,17 @@ local numRows <const> = math.floor(screenHeight / glyphWidth)
|
|||||||
local numCells <const> = numColumns * numRows
|
local numCells <const> = numColumns * numRows
|
||||||
|
|
||||||
local numGlyphs <const> = 133
|
local numGlyphs <const> = 133
|
||||||
|
local numFades <const> = 15
|
||||||
|
local blackImage = gfx.image.new(glyphWidth, glyphWidth, gfx.kColorBlack)
|
||||||
local glyphTable = gfx.imagetable.new('images/matrix')
|
local glyphTable = gfx.imagetable.new('images/matrix')
|
||||||
|
local ditherType = gfx.image.kDitherTypeAtkinson
|
||||||
local glyphs = {}
|
local glyphs = {}
|
||||||
for i = 1, numGlyphs do
|
for i = 1, numGlyphs do
|
||||||
glyphs[i] = glyphTable[i]
|
glyphs[i] = {}
|
||||||
end
|
local glyph = glyphTable[i]
|
||||||
|
for j = 1, numFades do
|
||||||
local ditherType = gfx.image.kDitherTypeAtkinson
|
glyphs[i][j] = glyph:blendWithImage(blackImage, 1 - j / numFades, ditherType)
|
||||||
local image = gfx.image.new(glyphWidth, glyphWidth, gfx.kColorBlack)
|
end
|
||||||
local numFades <const> = 15
|
|
||||||
local fades = {}
|
|
||||||
for i = 1, numFades do
|
|
||||||
fades[i] = image:fadedImage(i / numFades, ditherType)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local minSpeed <const> = 0.15
|
local minSpeed <const> = 0.15
|
||||||
@@ -91,8 +90,7 @@ function playdate.update()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if mustDraw then
|
if mustDraw then
|
||||||
glyphs[cell.glyphIndex]:draw((cell.x - 1) * glyphWidth, (cell.y - 1) * glyphWidth)
|
glyphs[cell.glyphIndex][cell.fadeIndex]:draw((cell.x - 1) * glyphWidth, (cell.y - 1) * glyphWidth)
|
||||||
fades[cell.fadeIndex]:draw((cell.x - 1) * glyphWidth, (cell.y - 1) * glyphWidth)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user