当前位置: 首页 > 工具软件 > Aseprite > 使用案例 >

aseprite 中心对称绘制脚本

傅浩漫
2023-12-01

自带的对称是轴对称,不是中心对称。中心对称有什么用呢,例如画扑克的三公牌,就可以用到了。

我用的是1.2.32,由于找不到获取鼠标位置的api,故而不能像原软件的对称那样实时绘制,只能用lua脚本做做样子,希望后面作者能把相关api给出来。。

亦或者等我有钱了换一台能装vs的电脑……我穷

以下是lua文件,其实是做成了扩展的形式

function init(plugin)
    print("Aseprite is initializing my plugin")

    -- we can use "plugin.preferences" as a table with fields for
    -- our plugin (these fields are saved between sessions)
    -- if plugin.preferences.count == nil then
    --  plugin.preferences.count = 0
    -- end

    function draw(dir)
		-- 这个脚本可以按要求把当前图层画面中的像素堆上/左/右半部分倒转画在下/右/左半部分,并且覆盖原来的下/右/左半部分像素。
        local cel = app.activeCel
		-- cel指的是图层中最小的像素堆范围,在调整中心对称之前最好在画布四个角各点上一点以保证cel范围与画布相同
		-- cel宽高为奇数时,中间行或列的像素们不会被调整。需要自行调整。
        if not cel then return app.alert("There is no active image") end
        local img = cel.image:clone()
        local w = cel.bounds.width
        local h = cel.bounds.height
        local offset = 0
        local pixelVal = 0
        if (dir == "v") then
			-- 把上半截的像素们倒过来画在下半截
            offset = math.floor(h / 2)
            for it in img:pixels() do
                if (it.y >= offset) then
                    pixelVal = img:getPixel(w - 1 - it.x, h - 1 - it.y)
                    if (pixelVal) then it(pixelVal) end
                end
            end
        elseif (dir==">") then
			-- 把左半截的像素们倒过来画在右半截
			offset = math.floor(w / 2)
            for it in img:pixels() do
                if (it.x >= offset) then
                    pixelVal = img:getPixel(w - 1 - it.x, h - 1 - it.y)
                    if (pixelVal) then it(pixelVal) end
                end
            end
		else
			-- 把右半截的像素们倒过来画在左半截
			-- dir=="<"
			offset = math.floor(w / 2)-1
            for it in img:pixels() do
                if (it.x <= offset) then
                    pixelVal = img:getPixel(w - 1 - it.x, h - 1 - it.y)
                    if (pixelVal) then it(pixelVal) end
                end
            end
		end

        cel.image = img
        app.refresh()
    end

	--鼠标右键点击时间轴里面当前图层的当前帧处,就可以看到这三项,设置快捷键更方便(搜索copy就能找到)
    plugin:newCommand{
        id = "copyuptodown",
        title = "copy up to down",
        group = "cel_popup_properties",
        onclick = function() draw("v") end
    }

	plugin:newCommand{
        id = "copylefttoright",
        title = "copy left to right",
        group = "cel_popup_properties",
        onclick = function() draw(">") end
    }

	plugin:newCommand{
        id = "copyrighttoleft",
        title = "copy right to left",
        group = "cel_popup_properties",
        onclick = function() draw("<") end
    }

end

function exit(plugin)
    print("Aseprite is closing my plugin")
end

 类似资料: