| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- // Copyright 2016 The G3N Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style
- // license that can be found in the LICENSE file.
- package math32
- import ()
- type Color4 struct {
- R float32
- G float32
- B float32
- A float32
- }
- var Black4 = Color4{0, 0, 0, 1}
- var White4 = Color4{1, 1, 1, 1}
- var Red4 = Color4{1, 0, 0, 1}
- var Green4 = Color4{0, 1, 0, 1}
- var Blue4 = Color4{0, 0, 1, 1}
- var Gray4 = Color4{0.5, 0.5, 0.5, 1}
- func NewColor4(r, g, b, a float32) *Color4 {
- return &Color4{R: r, G: g, B: b, A: a}
- }
- // Set sets this color individual R,G,B,A components
- func (c *Color4) Set(r, g, b, a float32) *Color4 {
- c.R = r
- c.G = g
- c.B = b
- c.A = b
- return c
- }
- // SetHex sets the color RGB components from the
- // specified integer interpreted as a color hex number
- // Alpha component is not modified
- func (c *Color4) SetHex(value uint) *Color4 {
- c.R = float32((value >> 16 & 255)) / 255
- c.G = float32((value >> 8 & 255)) / 255
- c.B = float32((value & 255)) / 255
- return c
- }
- // SetName sets the color RGB components from the
- // specified HTML color name
- // Alpha component is not modified
- func (c *Color4) SetName(name string) *Color4 {
- return c.SetHex(colorKeywords[name])
- }
- func (c *Color4) Add(other *Color4) *Color4 {
- c.R += other.R
- c.G += other.G
- c.B += other.B
- c.A += other.A
- return c
- }
- func (c *Color4) MultiplyScalar(v float32) *Color4 {
- c.R *= v
- c.G *= v
- c.B *= v
- return c
- }
- // FromColor sets this Color4 fields from Color and an alpha
- func (c *Color4) FromColor(other *Color, alpha float32) {
- c.R = other.R
- c.G = other.G
- c.B = other.B
- c.A = alpha
- }
- // ToColor returns a Color with this Color4 RGB components
- func (c *Color4) ToColor() Color {
- return Color{c.R, c.G, c.B}
- }
|