Skip to content

Latest commit

 

History

History
48 lines (42 loc) · 1.44 KB

scratch.md

File metadata and controls

48 lines (42 loc) · 1.44 KB

Scratch

I don't know what's happening so I'm just gonna put stuff here.

Speed up your mapPixel functions with FFI

You should probably use a shader for this.

sapper's grayscale shader colorizer

pDraw = love.graphics.newShader([[
    extern Image pal;
    extern number size;
    vec4 effect(vec4 c,Image tex,vec2 tx,vec2 pc){
        vec4 cr = Texel(tex,tx);
        vec4 r = Texel(pal,vec2(cr.r+(.5 / size),.5));
        return vec4(r.r,r.g,r.b,cr.a);
    }
]])
function palConvert(image,palette)
    local img,pal = image:getData(),palette:getData()
    img:mapPixel(function(x,y,r,g,b,a)
        local wid = pal:getWidth()
        for i=1,wid do
            local pix = {pal:getPixel(i-1,0)}
            if tEqual(pix,{r,g,b,a}) then
                local n = math.max(((i-1) * wid)-1,0)
                return n,n,n,255
            end
        end
        return 0,0,0,0
    end)
    return love.graphics.newImage(img)
end

A Palette Shader

Simple Conway Implementations

Rectangular Decomposition

Turn a bunch of rectangles into smaller rectangles.