The shrinker is done, but the expander is a WIP.
function ftgl_proprect(property,value,firstx,firsty,secondx,secondy)--A function from my graphics lib used here
for x=firstx,secondx do
for y=firsty,secondy do
tpt.set_property(property,value,x,y)
end
end
end
deco_shrink = function ( scale )
for x = 1, 610 do
for y = 1, 380 do
newx = x / scale
newy = y / scale
currentcolor = tpt.get_property( "dcolor", x, y )
if newx <= 610 and newy <= 380 then
tpt.set_property( "dcolor", currentcolor, newx, newy )
end
end
end
end
deco_expand = function ( scale ) -- Work in progress
for x = 1, 610 do
for y = 1, 380 do
newx = 610 - ( x * scale )
newy = 380 - ( y * scale )
currentcolor = tpt.get_property( "dcolor", x, y )
if newx <= 600 - scale and newy <= 370 - scale and newx >= 0 and newy >= 0 then
ftgl_proprect("dcolor", currentcolor, 610 - newx, 380 - newy, 610 - ( newx - scale ) , 380 - ( newy - scale ))
end
end
end
end
The expander needs some work, help would be greatly appreciated.
Well, I'm not exactly an expert like you. Maybe could you point me in the right direction?
How would I average a series of numbers in Lua?
function avg(t)
local sum = 0
for _, v in ipairs(t) do
sum=sum+v
end
return sum/#t
end
-- Usage:
-- avg{1, 2, 3, 4, 5}
Thanks! (BTW: @Mniip; I know that much, I was asking for in code.)
function avg(t) -- Thanks to Poorsoft for this one.
local sum = 0
for _, v in ipairs(t) do
sum=sum+v
end
return sum/#t
end
deco_mixcolors = function ( mixX, mixY, sizeX, sizeY, blending )
iteration = 1
colormatrix = {0}
for step = 1, blending do
for currentX = mixX, mixX + sizeX do
for currentY = mixY, mixY + sizeY do
colormatrix[iteration] = bit.tobit ( tpt.get_property ( "dcolor", currentX, currentY ) )
end
end
end
currentMix = avg(colormatrix)
end
deco_shrink = function ( scale, blending )
for x = 1, 610 do
for y = 1, 380 do
newx = x / scale
newy = y / scale
deco_mixcolors ( x, y, 1/scale, 1/scale, blending )
if newx <= 610 and newy <= 380 then
tpt.set_property ( "dcolor", currentMix, newx, newy )
end
end
end
end
Why won't this work?