Deco layer Shrinker/Expander

  • FeynmanLogomaker
    15th Jun 2013 Member 0 Permalink

    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.

  • mniip
    15th Jun 2013 Developer 0 Permalink
    @FeynmanLogomaker (View Post)
    there are a few problems with this though, i'd even say a lot
    You don't use the right algorithm
  • FeynmanLogomaker
    15th Jun 2013 Member 0 Permalink

    Well, I'm not exactly an expert like you. Maybe could you point me in the right direction?

  • mniip
    15th Jun 2013 Developer 0 Permalink
    in first one you iterate over pixels of target, looking into source for color, that's wrong, you should iterate over source mixing the color on the target.
    in second you iterate over pixels of source, creating blocks of same color on the output, again, wrong, you should iterate over pixels, interpolate the source
  • boxmein
    15th Jun 2013 Former Staff 0 Permalink
    If you'd like implement this then it'd be lovely :D
  • FeynmanLogomaker
    16th Jun 2013 Member 0 Permalink

    How would I average a series of numbers in Lua?

  • mniip
    16th Jun 2013 Developer 0 Permalink
    @FeynmanLogomaker (View Post)
    sum and divide by amount
  • boxmein
    16th Jun 2013 Former Staff 0 Permalink
    @FeynmanLogomaker (View Post)
    Just as you'd average any set of numbers:
    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}
  • FeynmanLogomaker
    16th Jun 2013 Member 0 Permalink

    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?

  • mniip
    16th Jun 2013 Developer 0 Permalink
    @FeynmanLogomaker (View Post)
    nonoonono, that's not how you mix rgb colors, you need to separate the 4 components and mix each separately