-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The 'openhue set light' command now allows setting the color (#18)
Examples: ```shell # Set color (in RGB) of a single light openhue set light 15f51223-1e83-4e48-9158-0c20dbd5734e --on --rgb #3399FF # Set color (in CIE space) of a single light openhue set light 15f51223-1e83-4e48-9158-0c20dbd5734e --on -x 0.675 -y 0.322 # Set color (by name) of a single light openhue set light 15f51223-1e83-4e48-9158-0c20dbd5734e --on --color powder_blue ```
- Loading branch information
Showing
10 changed files
with
488 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package testing | ||
|
||
import "math" | ||
|
||
// AlmostEqual32 returns true if a and b are equal within a relative error of e. | ||
// See http://floating-point-gui.de/errors/comparison/ for the details of the applied method. | ||
func AlmostEqual32(a, b, e float32) bool { | ||
|
||
MinNormal32 := math.Float32frombits(0x00800000) | ||
|
||
if a == b { | ||
return true | ||
} | ||
absA := Abs32(a) | ||
absB := Abs32(b) | ||
diff := Abs32(a - b) | ||
if a == 0 || b == 0 || absA+absB < MinNormal32 { | ||
return diff < e*MinNormal32 | ||
} | ||
return diff/Min32(absA+absB, math.MaxFloat32) < e | ||
} | ||
|
||
// Abs32 works like math.Abs, but for float32. | ||
func Abs32(x float32) float32 { | ||
switch { | ||
case x < 0: | ||
return -x | ||
case x == 0: | ||
return 0 // return correctly abs(-0) | ||
} | ||
return x | ||
} | ||
|
||
// Min32 works like math.Min, but for float32. | ||
func Min32(x, y float32) float32 { | ||
if x < y { | ||
return x | ||
} | ||
return y | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package color | ||
|
||
type RGB struct { | ||
Red int | ||
Green int | ||
Blue int | ||
} | ||
|
||
type XY struct { | ||
X float32 | ||
Y float32 | ||
Brightness float32 | ||
} | ||
|
||
var UndefinedColor = XY{ | ||
X: -1.0, | ||
Y: -1.0, | ||
Brightness: -1.0, | ||
} | ||
|
||
// RGBHex Hexadecimal representation of an RGB color. Must start with '#' | ||
type RGBHex string | ||
|
||
// toXY converts a RGBHex value to its XY representation in CIE color space | ||
func (c *RGBHex) toXY() *XY { | ||
hex, err := NewRGBFomHex(string(*c)) | ||
if err != nil { | ||
return nil | ||
} | ||
return hex.ToXY() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package color |
Oops, something went wrong.