-- For luminance calculation formula look at: http://en.wikipedia.org/wiki/Grayscale

local function IsDark(color)
	local cieLuminance = 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b
	return cieLuminance < 0.4
end

local function LerpColor(startColor, endColor, duration)
	local startTime = tick()
	while tick() - startTime < duration do
		wait(1 / MAX_STEPS)
		local lerpedVec = startColor:Lerp(endColor, (tick() - startTime) / duration)
		COLOR = Color3.new(lerpedVec.x,lerpedVec.y,lerpedVec.z)
		if lerpedVec.x < 1 and lerpedVec.y < 1 and lerpedVec.z < 1 and lerpedVec.x > 0 and lerpedVec.y > 0 and lerpedVec.z > 0 then
			script.Parent.Value = Color3.new(lerpedVec.x,lerpedVec.y,lerpedVec.z)
		end
	end
end

while true do
	if tick() - t >= 30 then math.randomseed(tick()/2) end
	t=tick()
	local newcolor
	repeat newcolor = BrickColor.Random()
	until not IsDark(newcolor.Color)
	print(newcolor)
	LerpColor(Vector3.new(COLOR.r,COLOR.g,COLOR.b),Vector3.new(newcolor.Color.r,newcolor.Color.g,newcolor.Color.b),2)
end
