Struct tetra::graphics::Color [−][src]
Expand description
An RGBA color.
The components are stored as f32
values in the range of 0.0
to 1.0
.
If your data is made up of bytes or hex values, this type provides
constructors that will carry out the conversion for you.
The std
arithmetic traits are implemented for this type, which allows you to
add/subtract/multiply/divide colors. These are implemented as saturating
operations (i.e. the values will always remain between 0.0
and 1.0
).
Serde
Serialization and deserialization of this type (via Serde)
can be enabled via the serde_support
feature.
Fields
r: f32
The red component of the color.
g: f32
The green component of the color.
b: f32
The blue component of the color.
a: f32
The alpha component of the color.
Implementations
Creates a new Color
, with the specified RGB values and the alpha set to 1.0.
Creates a new Color
, with the specified RGBA values.
Creates a new Color
, with the specified RGB integer (0-255) values and the alpha set to 255.
Creates a new Color
, with the specified RGBA (0-255) integer values.
Creates a new Color
using a hexidecimal color code, panicking if the input is
invalid.
Six and eight digit codes can be used - the former will be interpreted as RGB, and
the latter as RGBA. The #
prefix (commonly used on the web) will be stripped if present.
Creates a new Color
using a hexidecimal color code, returning an error if the
input is invalid.
Six and eight digit codes can be used - the former will be interpreted as RGB, and
the latter as RGBA. The #
prefix (commonly used on the web) will be stripped if present.
Errors
TetraError::InvalidColor
will be returned if the specified color is invalid.
Returns the color with the red component set to the specified value.
Returns the color with the green component set to the specified value.
Returns the color with the blue component set to the specified value.
Returns the color with the alpha component set to the specified value.
Returns the color with the RGB components multiplied by the alpha component.
This can be useful when working with premultiplied alpha blending, if you want to convert a non-premultiplied color into its premultiplied version.
Shortcut for Color::rgb(0.0, 0.0, 0.0)
.
Shortcut for Color::rgb(1.0, 1.0, 1.0)
.
Shortcut for Color::rgb(1.0, 0.0, 0.0)
.
Shortcut for Color::rgb(0.0, 1.0, 0.0)
.
Trait Implementations
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Can be accessed as a vec4
in your shader.
Auto Trait Implementations
impl RefUnwindSafe for Color
impl UnwindSafe for Color
Blanket Implementations
Mutably borrows from an owned value. Read more