-- a checkerboard filter implemented in lua
--@TBCONFIG SLIDER: XBoxes, 8.0
--@TBCONFIG SLIDER: YBoxes, 8.0
--@TBCONFIG SLIDER: Random Seed, 0
--@TBCONFIG STYLE: Even Squares, 1,Black,White,Transparent,Random,Color1,Color2,Color3,Color4
--@TBCONFIG STYLE: Odd Squares, 2,Black,White,Transparent,Random,Color1,Color2,Color3,Color4
horizontal = sliderVal1 * width / 4 + 1
vertical = sliderVal2 * height / 4 + 1
math.randomseed(sliderVal3 * 1000)

local x,y
local hpix=width/horizontal
local vpix=height/vertical
local r, g, b, a

function SetFillColor(even)
local fillMode 
	if even == true then
		fillMode = styleVal1
	else
		fillMode = styleVal2
	end
	if fillMode == 1 then		-- black
		r = 0; g = 0; b = 0; a = 1
	elseif fillMode ==2 then 	-- white
		r = 1; g = 1; b = 1; a = 1
	elseif fillMode ==3 then	-- transparent
		r = 0; g = 0; b = 0; a = 0
	elseif fillMode ==4 then	-- Random
		r = math.random(); a = 1
		g = math.random(); a = 1
		b = math.random(); a = 1
	elseif fillMode ==5 then	-- color 1
		r, g, b = get_color1(); a = 1
	elseif fillMode ==6 then	-- color 2
		r, g, b = get_color2(); a = 1
	elseif fillMode ==7 then	-- color 3
		r, g, b = get_color3(); a = 1
	elseif fillMode ==8 then	-- color 4
		r, g, b = get_color4(); a = 1
	end			
end
-- step through each box
local even 
for xx = 0, horizontal do 
	for yy = 0, vertical do 
		if ((math.mod(xx,2)==0) and (math.mod(yy,2)==1))
		or ((math.mod(xx,2)==1) and (math.mod(yy,2)==0)) then    -- odd color
			even = false
		else
			even = true
		end
		SetFillColor(even)
		for x = 0, hpix do
			for y = 0, vpix do 
				set_rgba(xx * hpix + x, yy * vpix + y, r, g, b, a)
			end
		end
	end
end



