Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Add threshold arg to Emphasise
Browse files Browse the repository at this point in the history
  • Loading branch information
cxmeel committed Mar 28, 2021
1 parent b8410aa commit 6d9e366
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Emphasise.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local GetLuminance = require(script.Parent.GetLuminance)
local Lighten = require(script.Parent.Lighten)
local Darken = require(script.Parent.Darken)

return function(colour: Color3, coefficient: number): Color3
return GetLuminance(colour) > .5 and Darken(colour, coefficient) or Lighten(colour, coefficient)
return function(colour: Color3, coefficient: number, threshold: number?): Color3
threshold = type(threshold) == "number" and threshold or .5
return GetLuminance(colour) > threshold and Darken(colour, coefficient) or Lighten(colour, coefficient)
end
10 changes: 10 additions & 0 deletions src/Emphasise.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@ return function()
local colour = Color3.fromRGB(250, 240, 230)
expect(Emphasise(colour, .3)).to.equal(Darken(colour, .3))
end)

it("lightens a light colour with a high threshold", function()
local colour = Color3.fromRGB(230, 220, 210)
expect(Emphasise(colour, .1, .9)).to.equal(Lighten(colour, .1))
end)

it("darkens a dark colour with a low threshold", function()
local colour = Color3.new(.2, .2, .2)
expect(Emphasise(colour, .1, .01)).to.equal(Darken(colour, .1))
end)
end

0 comments on commit 6d9e366

Please sign in to comment.