forked from Lngramos/three
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmath_color.go
More file actions
47 lines (40 loc) · 1.21 KB
/
math_color.go
File metadata and controls
47 lines (40 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package three
import (
"fmt"
"github.com/gopherjs/gopherjs/js"
)
// Color - represents a color.
type Color struct {
*js.Object
}
// NewColor returns a new three.Color for the given string.
// It accepts different string color formats:
// three.NewColor("rgb(255, 0, 0)")
// three.NewColor("rgb(100%, 0%, 0%)")
// three.NewColor("skyblue") // X11 color names (without CamelCase), see three.js source
// three.NewColor("hsl(0, 100%, 50%)")
// See https://threejs.org/docs/#api/en/math/Color for additional details.
func NewColor(color string) *Color {
return &Color{
Object: three.Get("Color").New(color),
}
}
// NewColorRGB returns a new three.Color for the given RGB values in 0..255 range.
func NewColorRGB(r, g, b uint8) *Color {
rgb := fmt.Sprintf("rgb(%d, %d, %d)", r, g, b)
return NewColor(rgb)
}
// NewColorRGBFloat returns a new three.Color for the given RGB values in 0.0..0.1 range.
func NewColorRGBFloat(r, g, b float64) *Color {
return &Color{
Object: three.Get("Color").New(r, g, b),
}
}
// NewColorHex returns a new three.Color for the given hex integer value.
// Example:
// three.NewColorHex(0xff0000)
func NewColorHex(i int64) *Color {
return &Color{
Object: three.Get("Color").New(i),
}
}