Struct Color

Source
#[repr(C)]
pub struct Color { pub r: f32, pub g: f32, pub b: f32, pub a: f32, }

Fields§

§r: f32§g: f32§b: f32§a: f32

Implementations§

Source§

impl Color

Source

pub const fn new(r: f32, g: f32, b: f32, a: f32) -> Color

Source

pub const fn gray(value: f32) -> Color

Source

pub const fn rgb(r: f32, g: f32, b: f32) -> Color

Source

pub fn rgb8(r: u8, g: u8, b: u8) -> Color

Examples found in repository?
examples/shapes.rs (line 6)
5fn update(_c: &mut EngineContext) {
6    clear_background(Color::rgb8(13, 2, 8));
7
8    let z = 0;
9    let size = 1.0;
10    let thickness = 0.1;
11
12    draw_circle(vec2(0.0, 0.0), size / 2.0, RED, z);
13    draw_circle_outline(vec2(0.0, 2.0), size / 2.0, thickness, RED, z);
14
15    draw_rect(vec2(2.0, 0.0), splat(size), GREEN, z);
16    draw_rect_outline(vec2(2.0, 2.0), splat(size), thickness, GREEN, z);
17}
More examples
Hide additional examples
examples/animated_shapes.rs (line 8)
5fn update(_c: &mut EngineContext) {
6    let time = get_time() as f32;
7
8    clear_background(Color::rgb8(13, 2, 8));
9
10    let colors = [RED, GREEN, BLUE, YELLOW, CYAN];
11
12    for (i, color) in colors.into_iter().enumerate() {
13        let s = (i + 1) as f32;
14        let t = s * time;
15
16        let z_index = i as i32;
17
18        draw_circle(
19            vec2(i as f32 * 2.0 + 2.0, t.sin() - 2.0),
20            s * 0.75,
21            color,
22            z_index,
23        );
24
25        let r = rescale(i, 0..colors.len(), 2..5);
26        draw_arc(
27            vec2(-s - 2.0, t.sin() - 2.0),
28            r,
29            PI - t.sin(),
30            PI - t.cos(),
31            color,
32            z_index,
33        );
34
35        draw_arc_outline(
36            vec2(-0.5, s - 0.5),
37            r,
38            s / 10.0,
39            PI / 4.0 - t.cos().powf(2.0),
40            t.sin().powf(2.0) + PI * 3.0 / 4.0,
41            // t.cos(),
42            color,
43            z_index,
44        );
45    }
46}
examples/screenshot_history.rs (line 86)
16    fn update(&mut self, c: &mut EngineContext) {
17        let screen_size = uvec2(screen_width() as u32, screen_height() as u32);
18
19        if !self.initialized {
20            self.initialized = true;
21
22            c.renderer.screenshot_params.record_screenshots = true;
23            c.renderer.screenshot_params.screenshot_interval_n = 10;
24            c.renderer.screenshot_params.history_length = 5;
25
26            for i in 0..c.renderer.screenshot_params.history_length {
27                self.handles.push(
28                    c.renderer
29                        .context
30                        .texture_creator
31                        .borrow_mut()
32                        .handle_from_size(
33                            &format!("screenshot-{i}"),
34                            screen_size,
35                            RED,
36                        ),
37                );
38            }
39        }
40
41        if is_key_pressed(KeyCode::F) {
42            let start = Instant::now();
43
44            save_screenshots_to_folder(
45                "screenshot-history",
46                &c.renderer.screenshot_history_buffer,
47            );
48
49            println!(
50                "Saved screenshots to folder 'screenshot-history', time: {}ms",
51                start.elapsed().as_millis()
52            );
53        }
54
55        for (screenshot, handle) in
56            c.renderer.screenshot_history_buffer.iter().zip(self.handles.iter())
57        {
58            c.renderer.context.texture_creator.borrow_mut().update_texture(
59                &imageops::flip_vertical(&screenshot.image),
60                *handle,
61            );
62        }
63
64        let ratio = screen_size.x as f32 / screen_size.y as f32;
65        let w = 2.0;
66
67        for (i, handle) in self.handles.iter().enumerate() {
68            draw_sprite(
69                *handle,
70                vec2(i as f32 * 2.0 + 2.0, 2.0),
71                WHITE,
72                100,
73                vec2(w, w / ratio),
74            );
75        }
76
77        draw_text_ex(
78            "Press F to save screenshots to disk",
79            Vec2::ZERO,
80            TextAlign::Center,
81            TextParams::default(),
82        );
83
84        let time = get_time() as f32;
85
86        clear_background(Color::rgb8(13, 2, 8));
87
88        let colors = [RED, GREEN, BLUE, YELLOW, CYAN];
89
90        for (i, color) in colors.into_iter().enumerate() {
91            let s = (i + 1) as f32;
92            let t = s * time;
93
94            let z_index = i as i32;
95
96            draw_circle(
97                vec2(i as f32 * 2.0 + 2.0, t.sin() - 2.0),
98                s * 0.75,
99                color,
100                z_index,
101            );
102
103            let r = rescale(i, 0..colors.len(), 2..5);
104            draw_arc(
105                vec2(-s - 2.0, t.sin() - 2.0),
106                r,
107                PI - t.sin(),
108                PI - t.cos(),
109                color,
110                z_index,
111            );
112
113            draw_arc_outline(
114                vec2(-0.5, s - 0.5),
115                r,
116                s / 10.0,
117                PI / 4.0 - t.cos().powf(2.0),
118                t.sin().powf(2.0) + PI * 3.0 / 4.0,
119                // t.cos(),
120                color,
121                z_index,
122            );
123        }
124    }
Source

pub fn rgba8(r: u8, g: u8, b: u8, a: u8) -> Color

Source

pub fn egui(self) -> Color32

Examples found in repository?
examples/egui.rs (line 10)
5fn update(_c: &mut EngineContext) {
6    egui::Window::new("Simple egui window")
7        .anchor(egui::Align2::CENTER_CENTER, egui::vec2(0.0, 0.0))
8        .show(egui(), |ui| {
9            if ui.button("hello").hovered() {
10                ui.colored_label(RED.egui(), "from egui");
11            } else {
12                ui.label("from egui");
13            }
14        });
15}
Source

pub fn to_vec4(&self) -> Vec4

Source

pub fn gamma_space_tint(self, tint: Color) -> Color

Source

pub fn linear_space_tint(self, tint: Color) -> Color

Source

pub fn to_linear(self) -> Color

Source

pub fn to_srgb(self) -> Color

Source

pub fn to_array(self) -> [u8; 4]

Source

pub fn to_array_f32(self) -> [f32; 4]

Source

pub fn alpha(&self, value: f32) -> Color

Source

pub fn mix(&self, other: Color, value: f32) -> Color

Source

pub fn to_image_rgba(self) -> Rgba<u8>

Source

pub fn darken(&self, amount: f32) -> Color

Source

pub fn lighten(&self, amount: f32) -> Color

Source

pub fn boost(&self, amount: f32) -> Color

Trait Implementations§

Source§

impl Add for Color

Source§

type Output = Color

The resulting type after applying the + operator.
Source§

fn add(self, val: Color) -> <Color as Add>::Output

Performs the + operation. Read more
Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Color

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Color

Source§

fn default() -> Color

Returns the “default value” for a type. Read more
Source§

impl From<Color> for Color32

Source§

fn from(value: Color) -> Color32

Converts to this type from the input type.
Source§

impl From<Color> for Rgba<u8>

Source§

fn from(value: Color) -> Rgba<u8>

Converts to this type from the input type.
Source§

impl From<Rgba<u8>> for Color

Source§

fn from(value: Rgba<u8>) -> Color

Converts to this type from the input type.
Source§

impl MathExtensions for Color

Source§

fn lerp(self, other: Color, t: f32) -> Color

Source§

impl Mul<f32> for Color

Source§

type Output = Color

The resulting type after applying the * operator.
Source§

fn mul(self, val: f32) -> <Color as Mul<f32>>::Output

Performs the * operation. Read more
Source§

impl Mul for Color

Source§

type Output = Color

The resulting type after applying the * operator.
Source§

fn mul(self, val: Color) -> <Color as Mul>::Output

Performs the * operation. Read more
Source§

impl PartialEq for Color

Source§

fn eq(&self, other: &Color) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl WgpuColorExtensions for Color

Source§

fn to_wgpu(&self) -> Color

Source§

impl Zeroable for Color

Source§

fn zeroed() -> Self

Source§

impl Copy for Color

Source§

impl Pod for Color

Source§

impl StructuralPartialEq for Color

Auto Trait Implementations§

§

impl Freeze for Color

§

impl RefUnwindSafe for Color

§

impl Send for Color

§

impl Sync for Color

§

impl Unpin for Color

§

impl UnwindSafe for Color

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Any for T
where T: Any,

Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> CloneAny for T
where T: Any + Clone,

Source§

impl<T> Component for T
where T: Send + Sync + 'static,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> NoUninit for T
where T: Pod,

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,