aseprite 中心对称绘制脚本

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

我用的是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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值