DogLua - Lua scripting for Project Dogwaffle:

the Grid Filter

back

 DogLua:   Overview - Downloading - Reference Guide - more Scripts - Lua Browser
  see also:  GUI Server - more SDK Info

 
the Grid Filter.......

Here's a grid filter as a Lua script.  It will help with a variety of projects where a set of vertical and horizontal lines are needed.



 











--
filename: Grid_gui.lua

function grid(size, color_r, color_g, color_b)

local x, y, r, g, b
for y = 0, height - 1 do

  for x = 0, width - 1 do
    r, g, b = get_rgb(x, y)

    if (math.mod( x, size ) == 0) or (math.mod( y, size ) == 0) then
       r,g,b=color_r, color_g, color_b
    end

    set_rgb(x, y, r, g, b)
  end
  progress(y / height)
end

end





-- the main program.

local size = 10
local color, color_r, color_g, color_b

Dog_SaveUndo()

GUI_SetCaption("Grid")
h1 = GUI_AddControl("Scroller", "Size", 10, 0, 100)
h2 = GUI_AddControl("Colorbox", "", hex("224488") ,0, 0)

GUI_OpenPanel()


--event loop.  Repeat until ok or cancel pressed (index of -1 or -2)

repeat
idx, retval, retstr = GUI_WaitOnEvent()

    size = GUI_GetSettings(h1)
    color = GUI_GetSettings(h2)
    --convert the color values to independant r,g,b values.
    color_r, color_g, color_b = decimal2rgb(color)


if (idx>-1) then
   grid (size,color_r, color_g, color_b)
   Dog_Refresh()
end

until idx < 0 --repeat until


GUI_ClosePanel()


if idx == -2 then
--Restore the image
Dog_RestoreUndo()
Dog_GetBuffer()
end