Skip to content

Instantly share code, notes, and snippets.

@mes51
Last active January 10, 2021 14:59
Show Gist options
  • Save mes51/f90331af552231f39adb5ed3847ebe86 to your computer and use it in GitHub Desktop.
Save mes51/f90331af552231f39adb5ed3847ebe86 to your computer and use it in GitHub Desktop.
UnMult的なスクリプト
obj.pixeloption("type", "rgb")
local w, h = obj.getpixel()
local inf = 1 / 0
for y = 0, h - 1 do
for x = 0, w - 1 do
local r, g, b, a = obj.getpixel(x, y)
if a < 255 then
r = (r * a) / 256
g = (g * a) / 256
b = (b * a) / 256
end
local rate = 255 / math.max(math.max(r, g), b)
if rate ~= inf then
local tr = r * rate
local tg = g * rate
local tb = b * rate
if tb > 0 then
a = (b * 256) / tb
elseif tg > 0 then
a = (g * 256) / tg
elseif tr > 0 then
a = (r * 256) / tr
else
a = 0
end
obj.putpixel(x, y, math.min(tr, 255), math.min(tg, 255), math.min(tb, 255), math.min(a, 255))
else
obj.putpixel(x, y, 0, 0, 0, 0)
end
end
end
@mes51
Copy link
Author

mes51 commented Jan 2, 2021

使い方

  • αを付けたいオブジェクトにアニメーション効果で乗せるだけ
  • パラメータはなし

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment