| @@ -2,7 +2,8 @@ | |||
| #' @description Produces a linear blend of the color with white or black. | |||
| #' @param color_hex A character string representing a hex color | |||
| #' @param strength The "strength" of the blend with white or black, | |||
| #' 0 low to 1 high. | |||
| #' where 0 is entirely the original color and 1 is entirely white | |||
| #' (`lighten_color()`) or black (`darken_color()`). | |||
| #' @name lighten_darken_color | |||
| NULL | |||
| @@ -14,7 +14,8 @@ darken_color(color_hex, strength = 0.8) | |||
| \item{color_hex}{A character string representing a hex color} | |||
| \item{strength}{The "strength" of the blend with white or black, | |||
| 0 low to 1 high.} | |||
| where 0 is entirely the original color and 1 is entirely white | |||
| (\code{lighten_color()}) or black (\code{darken_color()}).} | |||
| } | |||
| \description{ | |||
| Produces a linear blend of the color with white or black. | |||
| @@ -41,3 +41,26 @@ describe("full_length_hex()", { | |||
| expect_error(full_length_hex("#00000Z")) | |||
| }) | |||
| }) | |||
| describe("lighten_color() and darken_color()", { | |||
| it("errors if strength not in [0, 1]", { | |||
| expect_error(lighten_color("#123", 9)) | |||
| expect_error(darken_color("#123", 9)) | |||
| }) | |||
| it("returns original color if strength = 0", { | |||
| expect_equal(lighten_color("#808080", 0), "#808080") | |||
| expect_equal(darken_color("#808080", 0), "#808080") | |||
| }) | |||
| it("returns entire blend color if strength = 0", { | |||
| expect_equal(lighten_color("#808080", 1), "#FFFFFF") | |||
| expect_equal(darken_color("#808080", 1), "#000000") | |||
| }) | |||
| it("returns midpoint if strength = 0.5", { | |||
| expect_equal(lighten_color("#000000", 0.5), "#7F7F7F") | |||
| expect_equal(darken_color("#FFFFFF", 0.5), "#7F7F7F") | |||
| }) | |||
| }) | |||