From 6d9e36694a73547dd2bbaea51aa643728320f64f Mon Sep 17 00:00:00 2001 From: Cam <21029087+ClockworkSquirrel@users.noreply.github.com> Date: Sun, 28 Mar 2021 19:14:40 +0100 Subject: [PATCH] Add threshold arg to Emphasise --- src/Emphasise.lua | 5 +++-- src/Emphasise.spec.lua | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Emphasise.lua b/src/Emphasise.lua index f56f295..694db16 100644 --- a/src/Emphasise.lua +++ b/src/Emphasise.lua @@ -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 diff --git a/src/Emphasise.spec.lua b/src/Emphasise.spec.lua index 74ea284..badc2bd 100644 --- a/src/Emphasise.spec.lua +++ b/src/Emphasise.spec.lua @@ -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