Skip to content

Commit

Permalink
fix: match color.RGBA() behavior from the standard library (#30)
Browse files Browse the repository at this point in the history
* Update whisker in flake

The template requires whisker 2.5.1 but in nix we were stuck with 2.3.0

* Make alpha 255 by default

I think this was the intended behavior, we want the colors to be fully
opaque.

* Match the expected behavior of color.RGBA() and update tests

In the standard library color.RGBA() expects returned values to be in
the interval [0, 0xffff]. With this patch we match the behavior of
image.color.RGBA.RGBA().

Tests were updated accordingly and a test was added to make sure we
match the implementation of the standard library.
  • Loading branch information
billy4479 authored Jan 2, 2025
1 parent effad68 commit e292d33
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 175 deletions.
70 changes: 7 additions & 63 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 26 additions & 26 deletions frappe.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (frappe) Name() string { return "frappe" }
func (frappe) Rosewater() Color {
return Color{
Hex: "#f2d5cf",
RGB: [3]uint32{242, 213, 207},
RGB: [3]uint8{242, 213, 207},
HSL: [3]float32{10, 0.57, 0.88},
}
}
Expand All @@ -22,7 +22,7 @@ func (frappe) Rosewater() Color {
func (frappe) Flamingo() Color {
return Color{
Hex: "#eebebe",
RGB: [3]uint32{238, 190, 190},
RGB: [3]uint8{238, 190, 190},
HSL: [3]float32{0, 0.59, 0.84},
}
}
Expand All @@ -31,7 +31,7 @@ func (frappe) Flamingo() Color {
func (frappe) Pink() Color {
return Color{
Hex: "#f4b8e4",
RGB: [3]uint32{244, 184, 228},
RGB: [3]uint8{244, 184, 228},
HSL: [3]float32{316, 0.73, 0.84},
}
}
Expand All @@ -40,7 +40,7 @@ func (frappe) Pink() Color {
func (frappe) Mauve() Color {
return Color{
Hex: "#ca9ee6",
RGB: [3]uint32{202, 158, 230},
RGB: [3]uint8{202, 158, 230},
HSL: [3]float32{277, 0.59, 0.76},
}
}
Expand All @@ -49,7 +49,7 @@ func (frappe) Mauve() Color {
func (frappe) Red() Color {
return Color{
Hex: "#e78284",
RGB: [3]uint32{231, 130, 132},
RGB: [3]uint8{231, 130, 132},
HSL: [3]float32{359, 0.68, 0.71},
}
}
Expand All @@ -58,7 +58,7 @@ func (frappe) Red() Color {
func (frappe) Maroon() Color {
return Color{
Hex: "#ea999c",
RGB: [3]uint32{234, 153, 156},
RGB: [3]uint8{234, 153, 156},
HSL: [3]float32{358, 0.66, 0.76},
}
}
Expand All @@ -67,7 +67,7 @@ func (frappe) Maroon() Color {
func (frappe) Peach() Color {
return Color{
Hex: "#ef9f76",
RGB: [3]uint32{239, 159, 118},
RGB: [3]uint8{239, 159, 118},
HSL: [3]float32{20, 0.79, 0.7},
}
}
Expand All @@ -76,7 +76,7 @@ func (frappe) Peach() Color {
func (frappe) Yellow() Color {
return Color{
Hex: "#e5c890",
RGB: [3]uint32{229, 200, 144},
RGB: [3]uint8{229, 200, 144},
HSL: [3]float32{40, 0.62, 0.73},
}
}
Expand All @@ -85,7 +85,7 @@ func (frappe) Yellow() Color {
func (frappe) Green() Color {
return Color{
Hex: "#a6d189",
RGB: [3]uint32{166, 209, 137},
RGB: [3]uint8{166, 209, 137},
HSL: [3]float32{96, 0.44, 0.68},
}
}
Expand All @@ -94,7 +94,7 @@ func (frappe) Green() Color {
func (frappe) Teal() Color {
return Color{
Hex: "#81c8be",
RGB: [3]uint32{129, 200, 190},
RGB: [3]uint8{129, 200, 190},
HSL: [3]float32{172, 0.39, 0.65},
}
}
Expand All @@ -103,7 +103,7 @@ func (frappe) Teal() Color {
func (frappe) Sky() Color {
return Color{
Hex: "#99d1db",
RGB: [3]uint32{153, 209, 219},
RGB: [3]uint8{153, 209, 219},
HSL: [3]float32{189, 0.48, 0.73},
}
}
Expand All @@ -112,7 +112,7 @@ func (frappe) Sky() Color {
func (frappe) Sapphire() Color {
return Color{
Hex: "#85c1dc",
RGB: [3]uint32{133, 193, 220},
RGB: [3]uint8{133, 193, 220},
HSL: [3]float32{199, 0.55, 0.69},
}
}
Expand All @@ -121,7 +121,7 @@ func (frappe) Sapphire() Color {
func (frappe) Blue() Color {
return Color{
Hex: "#8caaee",
RGB: [3]uint32{140, 170, 238},
RGB: [3]uint8{140, 170, 238},
HSL: [3]float32{222, 0.74, 0.74},
}
}
Expand All @@ -130,7 +130,7 @@ func (frappe) Blue() Color {
func (frappe) Lavender() Color {
return Color{
Hex: "#babbf1",
RGB: [3]uint32{186, 187, 241},
RGB: [3]uint8{186, 187, 241},
HSL: [3]float32{239, 0.66, 0.84},
}
}
Expand All @@ -139,7 +139,7 @@ func (frappe) Lavender() Color {
func (frappe) Text() Color {
return Color{
Hex: "#c6d0f5",
RGB: [3]uint32{198, 208, 245},
RGB: [3]uint8{198, 208, 245},
HSL: [3]float32{227, 0.7, 0.87},
}
}
Expand All @@ -148,7 +148,7 @@ func (frappe) Text() Color {
func (frappe) Subtext1() Color {
return Color{
Hex: "#b5bfe2",
RGB: [3]uint32{181, 191, 226},
RGB: [3]uint8{181, 191, 226},
HSL: [3]float32{227, 0.44, 0.8},
}
}
Expand All @@ -157,7 +157,7 @@ func (frappe) Subtext1() Color {
func (frappe) Subtext0() Color {
return Color{
Hex: "#a5adce",
RGB: [3]uint32{165, 173, 206},
RGB: [3]uint8{165, 173, 206},
HSL: [3]float32{228, 0.29, 0.73},
}
}
Expand All @@ -166,7 +166,7 @@ func (frappe) Subtext0() Color {
func (frappe) Overlay2() Color {
return Color{
Hex: "#949cbb",
RGB: [3]uint32{148, 156, 187},
RGB: [3]uint8{148, 156, 187},
HSL: [3]float32{228, 0.22, 0.66},
}
}
Expand All @@ -175,7 +175,7 @@ func (frappe) Overlay2() Color {
func (frappe) Overlay1() Color {
return Color{
Hex: "#838ba7",
RGB: [3]uint32{131, 139, 167},
RGB: [3]uint8{131, 139, 167},
HSL: [3]float32{227, 0.17, 0.58},
}
}
Expand All @@ -184,7 +184,7 @@ func (frappe) Overlay1() Color {
func (frappe) Overlay0() Color {
return Color{
Hex: "#737994",
RGB: [3]uint32{115, 121, 148},
RGB: [3]uint8{115, 121, 148},
HSL: [3]float32{229, 0.13, 0.52},
}
}
Expand All @@ -193,7 +193,7 @@ func (frappe) Overlay0() Color {
func (frappe) Surface2() Color {
return Color{
Hex: "#626880",
RGB: [3]uint32{98, 104, 128},
RGB: [3]uint8{98, 104, 128},
HSL: [3]float32{228, 0.13, 0.44},
}
}
Expand All @@ -202,7 +202,7 @@ func (frappe) Surface2() Color {
func (frappe) Surface1() Color {
return Color{
Hex: "#51576d",
RGB: [3]uint32{81, 87, 109},
RGB: [3]uint8{81, 87, 109},
HSL: [3]float32{227, 0.15, 0.37},
}
}
Expand All @@ -211,7 +211,7 @@ func (frappe) Surface1() Color {
func (frappe) Surface0() Color {
return Color{
Hex: "#414559",
RGB: [3]uint32{65, 69, 89},
RGB: [3]uint8{65, 69, 89},
HSL: [3]float32{230, 0.16, 0.3},
}
}
Expand All @@ -220,7 +220,7 @@ func (frappe) Surface0() Color {
func (frappe) Base() Color {
return Color{
Hex: "#303446",
RGB: [3]uint32{48, 52, 70},
RGB: [3]uint8{48, 52, 70},
HSL: [3]float32{229, 0.19, 0.23},
}
}
Expand All @@ -229,7 +229,7 @@ func (frappe) Base() Color {
func (frappe) Mantle() Color {
return Color{
Hex: "#292c3c",
RGB: [3]uint32{41, 44, 60},
RGB: [3]uint8{41, 44, 60},
HSL: [3]float32{231, 0.19, 0.2},
}
}
Expand All @@ -238,7 +238,7 @@ func (frappe) Mantle() Color {
func (frappe) Crust() Color {
return Color{
Hex: "#232634",
RGB: [3]uint32{35, 38, 52},
RGB: [3]uint8{35, 38, 52},
HSL: [3]float32{229, 0.2, 0.17},
}
}
2 changes: 1 addition & 1 deletion go.tera
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func ({{flavor.identifier}}) Name() string { return "{{flavor.identifier}}" }
func ({{flavor.identifier}}) {{color.identifier | title}}() Color {
return Color{
Hex: "#{{color.hex}}",
RGB: [3]uint32{ {{color.rgb.r}}, {{color.rgb.g}}, {{color.rgb.b}}},
RGB: [3]uint8{ {{color.rgb.r}}, {{color.rgb.g}}, {{color.rgb.b}}},
HSL: [3]float32{ {{color.hsl.h | round(precision=2)}}, {{color.hsl.s | round(precision=2)}}, {{color.hsl.l | round(precision=2)}}},
}
}
Expand Down
Loading

0 comments on commit e292d33

Please sign in to comment.