Here's a wave deformation filter
as a Lua script. Perfect if you want to make variants of it, with more
hot spots, or just one at a different location, etc.
The code shown here puts one hotspot wave deformer in the middle of the
document. If you have a selection mask present, only the selected parts
will be affacted, as shown in the example here: only the lower part is
deformed (but the center of deformation is of course still in the
middle of the image buffer)
baby seals photo courtesy of Klipsi
|
-- filename: wave.lua
function wave(frequency, power)
local x, y, r, g, b,v
local x2, y2
for y = 0, height - 1 do
for x = 0, width - 1 do
x2=((x/width)-.5)*frequency
y2=((y/height)-.5)*frequency
v=((math.cos((math.sqrt(x2*x2+y2*y2))*.01745)))
v=v*power
x2=x+v
y2=y+v
if x2<0 then x2=0 end
if y2<0 then y2=0 end
if x2>(width-1) then x2=(width-1) end
if y2>(height-1) then y2=(height-1)
end
r, g, b = get_rgb(x2, y2)
set_rgb(x, y, r, g, b)
end
progress(y / height)
end
end
-- the main program.
Dog_SaveUndo()
GUI_SetCaption("Wave")
h1 = GUI_AddControl("Scroller", "Power", 50, 0, 100)
h2 = GUI_AddControl("Scroller", "Frequency", 5000, 0, 10000)
GUI_OpenPanel()
--event loop. Repeat until ok or cancel pressed (index of -1 or
-2)
repeat
idx, retval, retstr = GUI_WaitOnEvent()
power, string=GUI_GetSettings(h1)
frequency, string=GUI_GetSettings(h2)
if (idx>-1) then
wave(frequency, power)
Dog_Refresh()
end
until idx < 0 --repeat until
GUI_ClosePanel()
if idx == -2 then
--Restore the image
Dog_RestoreUndo()
Dog_GetBuffer()
end
|
|