Skip to main content

Color

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 TRANSPARENT: Color

Source

pub const ALICE_BLUE: Color

Source

pub const ANTIQUE_WHITE: Color

Source

pub const AQUA: Color

Source

pub const AQUAMARINE: Color

Source

pub const AZURE: Color

Source

pub const BEIGE: Color

Source

pub const BISQUE: Color

Source

pub const BLACK: Color

Source

pub const BLANCHED_ALMOND: Color

Source

pub const BLUE: Color

Source

pub const BLUE_VIOLET: Color

Source

pub const BROWN: Color

Source

pub const BURLY_WOOD: Color

Source

pub const CADET_BLUE: Color

Source

pub const CHARTREUSE: Color

Source

pub const CHOCOLATE: Color

Source

pub const CORAL: Color

Source

pub const CORNFLOWER_BLUE: Color

Source

pub const CORNSILK: Color

Source

pub const CRIMSON: Color

Source

pub const CYAN: Color

Source

pub const DARK_BLUE: Color

Source

pub const DARK_CYAN: Color

Source

pub const DARK_GOLDEN_ROD: Color

Source

pub const DARK_GRAY: Color

Source

pub const DARK_GREEN: Color

Source

pub const DARK_GREY: Color

Source

pub const DARK_KHAKI: Color

Source

pub const DARK_MAGENTA: Color

Source

pub const DARK_OLIVE_GREEN: Color

Source

pub const DARK_ORANGE: Color

Source

pub const DARK_ORCHID: Color

Source

pub const DARK_RED: Color

Source

pub const DARK_SALMON: Color

Source

pub const DARK_SEA_GREEN: Color

Source

pub const DARK_SLATE_BLUE: Color

Source

pub const DARK_SLATE_GRAY: Color

Source

pub const DARK_SLATE_GREY: Color

Source

pub const DARK_TURQUOISE: Color

Source

pub const DARK_VIOLET: Color

Source

pub const DEEP_PINK: Color

Source

pub const DEEP_SKY_BLUE: Color

Source

pub const DIM_GRAY: Color

Source

pub const DIM_GREY: Color

Source

pub const DODGER_BLUE: Color

Source

pub const FIRE_BRICK: Color

Source

pub const FLORAL_WHITE: Color

Source

pub const FOREST_GREEN: Color

Source

pub const FUCHSIA: Color

Source

pub const GAINSBORO: Color

Source

pub const GHOST_WHITE: Color

Source

pub const GOLD: Color

Source

pub const GOLDEN_ROD: Color

Source

pub const GRAY: Color

Source

pub const GREEN: Color

Source

pub const GREEN_YELLOW: Color

Source

pub const GREY: Color

Source

pub const HONEY_DEW: Color

Source

pub const HOT_PINK: Color

Source

pub const INDIAN_RED: Color

Source

pub const INDIGO: Color

Source

pub const IVORY: Color

Source

pub const KHAKI: Color

Source

pub const LAVENDER: Color

Source

pub const LAVENDER_BLUSH: Color

Source

pub const LAWN_GREEN: Color

Source

pub const LEMON_CHIFFON: Color

Source

pub const LIGHT_BLUE: Color

Source

pub const LIGHT_CORAL: Color

Source

pub const LIGHT_CYAN: Color

Source

pub const LIGHT_GOLDEN_ROD_YELLOW: Color

Source

pub const LIGHT_GRAY: Color

Source

pub const LIGHT_GREEN: Color

Source

pub const LIGHT_GREY: Color

Source

pub const LIGHT_PINK: Color

Source

pub const LIGHT_SALMON: Color

Source

pub const LIGHT_SEA_GREEN: Color

Source

pub const LIGHT_SKY_BLUE: Color

Source

pub const LIGHT_SLATE_GRAY: Color

Source

pub const LIGHT_SLATE_GREY: Color

Source

pub const LIGHT_STEEL_BLUE: Color

Source

pub const LIGHT_YELLOW: Color

Source

pub const LIME: Color

Source

pub const LIME_GREEN: Color

Source

pub const LINEN: Color

Source

pub const MAGENTA: Color

Source

pub const MAROON: Color

Source

pub const MEDIUM_AQUA_MARINE: Color

Source

pub const MEDIUM_BLUE: Color

Source

pub const MEDIUM_ORCHID: Color

Source

pub const MEDIUM_PURPLE: Color

Source

pub const MEDIUM_SEA_GREEN: Color

Source

pub const MEDIUM_SLATE_BLUE: Color

Source

pub const MEDIUM_SPRING_GREEN: Color

Source

pub const MEDIUM_TURQUOISE: Color

Source

pub const MEDIUM_VIOLET_RED: Color

Source

pub const MIDNIGHT_BLUE: Color

Source

pub const MINT_CREAM: Color

Source

pub const MISTY_ROSE: Color

Source

pub const MOCCASIN: Color

Source

pub const NAVAJO_WHITE: Color

Source

pub const NAVY: Color

Source

pub const OLD_LACE: Color

Source

pub const OLIVE: Color

Source

pub const OLIVE_DRAB: Color

Source

pub const ORANGE: Color

Source

pub const ORANGE_RED: Color

Source

pub const ORCHID: Color

Source

pub const PALE_GOLDEN_ROD: Color

Source

pub const PALE_GREEN: Color

Source

pub const PALE_TURQUOISE: Color

Source

pub const PALE_VIOLET_RED: Color

Source

pub const PAPAYA_WHIP: Color

Source

pub const PEACH_PUFF: Color

Source

pub const PERU: Color

Source

pub const PINK: Color

Source

pub const PLUM: Color

Source

pub const POWDER_BLUE: Color

Source

pub const PURPLE: Color

Source

pub const REBECCA_PURPLE: Color

Source

pub const RED: Color

Source

pub const ROSY_BROWN: Color

Source

pub const ROYAL_BLUE: Color

Source

pub const SADDLE_BROWN: Color

Source

pub const SALMON: Color

Source

pub const SANDY_BROWN: Color

Source

pub const SEA_GREEN: Color

Source

pub const SEA_SHELL: Color

Source

pub const SIENNA: Color

Source

pub const SILVER: Color

Source

pub const SKY_BLUE: Color

Source

pub const SLATE_BLUE: Color

Source

pub const SLATE_GRAY: Color

Source

pub const SLATE_GREY: Color

Source

pub const SNOW: Color

Source

pub const SPRING_GREEN: Color

Source

pub const STEEL_BLUE: Color

Source

pub const TAN: Color

Source

pub const TEAL: Color

Source

pub const THISTLE: Color

Source

pub const TOMATO: Color

Source

pub const TURQUOISE: Color

Source

pub const VIOLET: Color

Source

pub const WHEAT: Color

Source

pub const WHITE: Color

Source

pub const WHITE_SMOKE: Color

Source

pub const YELLOW: Color

Source

pub const YELLOW_GREEN: Color

Source

pub const AMBER_50: Color

Source

pub const AMBER_100: Color

Source

pub const AMBER_200: Color

Source

pub const AMBER_300: Color

Source

pub const AMBER_400: Color

Source

pub const AMBER_500: Color

Source

pub const AMBER_600: Color

Source

pub const AMBER_700: Color

Source

pub const AMBER_800: Color

Source

pub const AMBER_900: Color

Source

pub const AMBER_950: Color

Source

pub const BLUE_50: Color

Source

pub const BLUE_100: Color

Source

pub const BLUE_200: Color

Source

pub const BLUE_300: Color

Source

pub const BLUE_400: Color

Source

pub const BLUE_500: Color

Source

pub const BLUE_600: Color

Source

pub const BLUE_700: Color

Source

pub const BLUE_800: Color

Source

pub const BLUE_900: Color

Source

pub const BLUE_950: Color

Source

pub const CYAN_50: Color

Source

pub const CYAN_100: Color

Source

pub const CYAN_200: Color

Source

pub const CYAN_300: Color

Source

pub const CYAN_400: Color

Source

pub const CYAN_500: Color

Source

pub const CYAN_600: Color

Source

pub const CYAN_700: Color

Source

pub const CYAN_800: Color

Source

pub const CYAN_900: Color

Source

pub const CYAN_950: Color

Source

pub const EMERALD_50: Color

Source

pub const EMERALD_100: Color

Source

pub const EMERALD_200: Color

Source

pub const EMERALD_300: Color

Source

pub const EMERALD_400: Color

Source

pub const EMERALD_500: Color

Source

pub const EMERALD_600: Color

Source

pub const EMERALD_700: Color

Source

pub const EMERALD_800: Color

Source

pub const EMERALD_900: Color

Source

pub const EMERALD_950: Color

Source

pub const FUCHSIA_50: Color

Source

pub const FUCHSIA_100: Color

Source

pub const FUCHSIA_200: Color

Source

pub const FUCHSIA_300: Color

Source

pub const FUCHSIA_400: Color

Source

pub const FUCHSIA_500: Color

Source

pub const FUCHSIA_600: Color

Source

pub const FUCHSIA_700: Color

Source

pub const FUCHSIA_800: Color

Source

pub const FUCHSIA_900: Color

Source

pub const FUCHSIA_950: Color

Source

pub const GRAY_50: Color

Source

pub const GRAY_100: Color

Source

pub const GRAY_200: Color

Source

pub const GRAY_300: Color

Source

pub const GRAY_400: Color

Source

pub const GRAY_500: Color

Source

pub const GRAY_600: Color

Source

pub const GRAY_700: Color

Source

pub const GRAY_800: Color

Source

pub const GRAY_900: Color

Source

pub const GRAY_950: Color

Source

pub const GREEN_50: Color

Source

pub const GREEN_100: Color

Source

pub const GREEN_200: Color

Source

pub const GREEN_300: Color

Source

pub const GREEN_400: Color

Source

pub const GREEN_500: Color

Source

pub const GREEN_600: Color

Source

pub const GREEN_700: Color

Source

pub const GREEN_800: Color

Source

pub const GREEN_900: Color

Source

pub const GREEN_950: Color

Source

pub const INDIGO_50: Color

Source

pub const INDIGO_100: Color

Source

pub const INDIGO_200: Color

Source

pub const INDIGO_300: Color

Source

pub const INDIGO_400: Color

Source

pub const INDIGO_500: Color

Source

pub const INDIGO_600: Color

Source

pub const INDIGO_700: Color

Source

pub const INDIGO_800: Color

Source

pub const INDIGO_900: Color

Source

pub const INDIGO_950: Color

Source

pub const LIME_50: Color

Source

pub const LIME_100: Color

Source

pub const LIME_200: Color

Source

pub const LIME_300: Color

Source

pub const LIME_400: Color

Source

pub const LIME_500: Color

Source

pub const LIME_600: Color

Source

pub const LIME_700: Color

Source

pub const LIME_800: Color

Source

pub const LIME_900: Color

Source

pub const LIME_950: Color

Source

pub const NEUTRAL_50: Color

Source

pub const NEUTRAL_100: Color

Source

pub const NEUTRAL_200: Color

Source

pub const NEUTRAL_300: Color

Source

pub const NEUTRAL_400: Color

Source

pub const NEUTRAL_500: Color

Source

pub const NEUTRAL_600: Color

Source

pub const NEUTRAL_700: Color

Source

pub const NEUTRAL_800: Color

Source

pub const NEUTRAL_900: Color

Source

pub const NEUTRAL_950: Color

Source

pub const ORANGE_50: Color

Source

pub const ORANGE_100: Color

Source

pub const ORANGE_200: Color

Source

pub const ORANGE_300: Color

Source

pub const ORANGE_400: Color

Source

pub const ORANGE_500: Color

Source

pub const ORANGE_600: Color

Source

pub const ORANGE_700: Color

Source

pub const ORANGE_800: Color

Source

pub const ORANGE_900: Color

Source

pub const ORANGE_950: Color

Source

pub const PINK_50: Color

Source

pub const PINK_100: Color

Source

pub const PINK_200: Color

Source

pub const PINK_300: Color

Source

pub const PINK_400: Color

Source

pub const PINK_500: Color

Source

pub const PINK_600: Color

Source

pub const PINK_700: Color

Source

pub const PINK_800: Color

Source

pub const PINK_900: Color

Source

pub const PINK_950: Color

Source

pub const PURPLE_50: Color

Source

pub const PURPLE_100: Color

Source

pub const PURPLE_200: Color

Source

pub const PURPLE_300: Color

Source

pub const PURPLE_400: Color

Source

pub const PURPLE_500: Color

Source

pub const PURPLE_600: Color

Source

pub const PURPLE_700: Color

Source

pub const PURPLE_800: Color

Source

pub const PURPLE_900: Color

Source

pub const PURPLE_950: Color

Source

pub const RED_50: Color

Source

pub const RED_100: Color

Source

pub const RED_200: Color

Source

pub const RED_300: Color

Source

pub const RED_400: Color

Source

pub const RED_500: Color

Source

pub const RED_600: Color

Source

pub const RED_700: Color

Source

pub const RED_800: Color

Source

pub const RED_900: Color

Source

pub const RED_950: Color

Source

pub const ROSE_50: Color

Source

pub const ROSE_100: Color

Source

pub const ROSE_200: Color

Source

pub const ROSE_300: Color

Source

pub const ROSE_400: Color

Source

pub const ROSE_500: Color

Source

pub const ROSE_600: Color

Source

pub const ROSE_700: Color

Source

pub const ROSE_800: Color

Source

pub const ROSE_900: Color

Source

pub const ROSE_950: Color

Source

pub const SKY_50: Color

Source

pub const SKY_100: Color

Source

pub const SKY_200: Color

Source

pub const SKY_300: Color

Source

pub const SKY_400: Color

Source

pub const SKY_500: Color

Source

pub const SKY_600: Color

Source

pub const SKY_700: Color

Source

pub const SKY_800: Color

Source

pub const SKY_900: Color

Source

pub const SKY_950: Color

Source

pub const SLATE_50: Color

Source

pub const SLATE_100: Color

Source

pub const SLATE_200: Color

Source

pub const SLATE_300: Color

Source

pub const SLATE_400: Color

Source

pub const SLATE_500: Color

Source

pub const SLATE_600: Color

Source

pub const SLATE_700: Color

Source

pub const SLATE_800: Color

Source

pub const SLATE_900: Color

Source

pub const SLATE_950: Color

Source

pub const STONE_50: Color

Source

pub const STONE_100: Color

Source

pub const STONE_200: Color

Source

pub const STONE_300: Color

Source

pub const STONE_400: Color

Source

pub const STONE_500: Color

Source

pub const STONE_600: Color

Source

pub const STONE_700: Color

Source

pub const STONE_800: Color

Source

pub const STONE_900: Color

Source

pub const STONE_950: Color

Source

pub const TEAL_50: Color

Source

pub const TEAL_100: Color

Source

pub const TEAL_200: Color

Source

pub const TEAL_300: Color

Source

pub const TEAL_400: Color

Source

pub const TEAL_500: Color

Source

pub const TEAL_600: Color

Source

pub const TEAL_700: Color

Source

pub const TEAL_800: Color

Source

pub const TEAL_900: Color

Source

pub const TEAL_950: Color

Source

pub const VIOLET_50: Color

Source

pub const VIOLET_100: Color

Source

pub const VIOLET_200: Color

Source

pub const VIOLET_300: Color

Source

pub const VIOLET_400: Color

Source

pub const VIOLET_500: Color

Source

pub const VIOLET_600: Color

Source

pub const VIOLET_700: Color

Source

pub const VIOLET_800: Color

Source

pub const VIOLET_900: Color

Source

pub const VIOLET_950: Color

Source

pub const YELLOW_50: Color

Source

pub const YELLOW_100: Color

Source

pub const YELLOW_200: Color

Source

pub const YELLOW_300: Color

Source

pub const YELLOW_400: Color

Source

pub const YELLOW_500: Color

Source

pub const YELLOW_600: Color

Source

pub const YELLOW_700: Color

Source

pub const YELLOW_800: Color

Source

pub const YELLOW_900: Color

Source

pub const YELLOW_950: Color

Source

pub const ZINC_50: Color

Source

pub const ZINC_100: Color

Source

pub const ZINC_200: Color

Source

pub const ZINC_300: Color

Source

pub const ZINC_400: Color

Source

pub const ZINC_500: Color

Source

pub const ZINC_600: Color

Source

pub const ZINC_700: Color

Source

pub const ZINC_800: Color

Source

pub const ZINC_900: Color

Source

pub const ZINC_950: Color

Source

pub const ALL: [Color; 242]

Source§

impl Color

Source

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

Source

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

Source

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

Source

pub fn from_gpu(v: [f32; 4]) -> Color

Source

pub fn to_u8(&self) -> (u8, u8, u8)

Source

pub fn from_string(s: impl AsRef<str>) -> Option<Color>

Source

pub const fn to_rgba_u8(&self) -> (u8, u8, u8, u8)

Source

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

Source

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

Source

pub const fn for_gpu(&self) -> [f32; 4]

Source

pub const fn to_vec4(&self) -> Vec4

Source

pub fn from_vec4(v: Vec4) -> Color

Source

pub fn splat(v: f32) -> Color

Source

pub fn grey(v: f32) -> Color

Source

pub const fn with_alpha(self, a: f32) -> Color

Examples found in repository?
examples/space_game.rs (line 216)
209    fn emit_movement_particles(&self) {
210        let batch = ParticleOneshot::builder()
211            .shape(&Circle::new(
212                Vec2::ZERO,
213                Vec2::splat(LINE_THICKNESS * 1.5),
214                FG,
215            ))
216            .end_color(RED.with_alpha(0.0))
217            .speed(self.speed * 0.8)
218            .direction(-self.rotation)
219            .direction_randomness(0.2)
220            .speed_randomness(self.speed * 0.5)
221            .lifetime(0.8)
222            .lifetime_randomness(0.4)
223            .quantity((self.speed * 5.0).max(1.0) as usize)
224            .position_randomness(Vec2::splat(PLAYER_SIZE * 0.3))
225            .build();
226        get_particles().spawn_oneshot(
227            &batch,
228            self.pos + vec2(0.0, -PLAYER_SIZE * 0.3).rotated_around_origin(-self.rotation),
229        );
230    }
231
232    fn update_input(&mut self) {
233        if action_held(UP) {
234            self.speed += PLAYER_ACCEL;
235            self.emit_movement_particles();
236
237            if once_per_n_seconds(0.1) {
238                play_sound_ex(get_sounds().engine).volume(0.1).start();
239            }
240        }
241
242        if action_held(DOWN) {
243            self.speed -= PLAYER_ACCEL;
244        }
245
246        if action_held(RIGHT) {
247            self.angvel -= PLAYER_TURN_SPEED;
248        }
249
250        if action_held(LEFT) {
251            self.angvel += PLAYER_TURN_SPEED;
252        }
253
254        if action_pressed(SHOOT) {
255            play_sound(get_sounds().shoot);
256            let tip = self.pos + vec2(0.0, PLAYER_SIZE).rotated_around_origin(-self.rotation);
257            self.bullets
258                .push(Bullet::new(tip, self.rotation, self.vel()));
259        }
260    }
261
262    fn update_velocities(&mut self) {
263        self.pos += self.vel();
264        self.rotation += self.angvel;
265
266        self.speed *= PLAYER_LIN_DECEL;
267        self.angvel *= PLAYER_ANG_DECEL;
268
269        if self.speed.abs() < 0.1 {
270            self.speed = 0.0;
271        }
272
273        if self.angvel.abs() < 0.1 {
274            self.angvel = 0.0;
275        }
276    }
277
278    fn draw(&self) {
279        for bullet in &self.bullets {
280            bullet.draw();
281        }
282
283        let c = self.pos;
284        let tip = c + vec2(0.0, PLAYER_SIZE);
285        let elbow = c + vec2(0.0, -PLAYER_SIZE * 0.5);
286        let left_wing = c + vec2(-PLAYER_SIZE, -PLAYER_SIZE);
287        let right_wing = c + vec2(PLAYER_SIZE, -PLAYER_SIZE);
288
289        let now = time();
290        let time = (now - self.last_hit) * 10.0;
291        let blink_on = time as i32 % 2 == 0;
292        let currently_invincible = now - self.last_hit < PLAYER_INVINCIBILITY_DURATION;
293        let color = if currently_invincible && blink_on {
294            FG.with_alpha(0.3)
295        } else {
296            FG
297        };
298
299        if currently_invincible && blink_on {
300            vignette_screen(RED, 0.5);
301        }
302
303        draw_circle_path_world(
304            &[tip, left_wing, elbow, right_wing, tip]
305                .map(|p| p.rotated_around_point(c, -self.rotation)),
306            LINE_THICKNESS,
307            color,
308        );
309
310        self.draw_healthbar();
311    }
312
313    fn draw_healthbar(&self) {
314        let width = PLAYER_HEALTHBAR_WIDTH / MAX_PLAYER_HEALTH as f32;
315        let height = PLAYER_HEALTHBAR_HEIGHT;
316
317        for i in 0..self.health {
318            let offset = (width + PLAYER_HEALTHBAR_PADDING) * i as f32 + PLAYER_HEALTHBAR_PADDING;
319            draw_rect(
320                vec2(offset, window_height() - height - PLAYER_HEALTHBAR_PADDING),
321                vec2(width, height),
322                FG,
323            );
324        }
325    }
326}
327
328struct Asteroid {
329    health: usize,
330    max_health: usize,
331    last_hit: f32,
332    points: Vec<Vec2>,
333    pos: Vec2,
334    velocity: Vec2,
335    rotation: f32,
336    angvel: f32,
337    radius: f32,
338}
339
340impl Asteroid {
341    fn new() -> Self {
342        let radius = rand_range(MIN_ASTEROID_RADIUS..MAX_ASTEROID_RADIUS);
343        let health = (radius / MIN_ASTEROID_RADIUS) as usize * 2;
344        let last_hit = f32::MIN;
345        let pos = rand_vec2() * BASE_WINDOW_SIZE / 2.0;
346        let velocity = rand_vec2() * MAX_ASTEROID_SPEED;
347        let rotation = rand_f32() * TAU;
348        let angvel = rand_f32() * MAX_ASTEROID_ANGVEL;
349
350        let num_points = (radius * MAX_ASTEROID_POINTS) as usize;
351        let max_offset = radius * MAX_ASTEROID_POINT_OFFSET / 2.0;
352
353        let mut points = Vec::with_capacity(num_points + 1);
354
355        for i in 0..num_points {
356            let angle = (TAU / num_points as f32) * i as f32;
357            let offset = rand_range(-max_offset..max_offset) + radius;
358            let pos = Vec2::new(0.0, offset).rotated_around_origin(angle);
359            points.push(pos);
360        }
361
362        points.push(points[0]);
363
364        Self {
365            health,
366            last_hit,
367            points,
368            pos,
369            velocity,
370            rotation,
371            angvel,
372            radius,
373            max_health: health,
374        }
375    }
376
377    fn update(&mut self) {
378        self.pos += self.velocity;
379        self.rotation += self.angvel;
380        self.pos = wrap_position(self.pos, self.radius);
381    }
382
383    fn draw(&self) {
384        let points = &self
385            .points
386            .iter()
387            .map(|p| p.rotated_around_origin(self.rotation) + self.pos)
388            .collect::<Vec<_>>();
389
390        let blinking = time() - self.last_hit < ASTEROID_BLINK_DURATION;
391        let fill = if blinking { FG } else { BG };
392
393        draw_custom_shape_world(points, fill);
394        draw_circle_path_world(points, LINE_THICKNESS, FG);
395    }
396}
397
398struct Sounds {
399    shoot: SoundRef,
400    asteroid_hit: SoundRef,
401    asteroid_death: SoundRef,
402    player_hit: SoundRef,
403    game_over: SoundRef,
404    engine: SoundRef,
405}
406
407impl Sounds {
408    fn new() -> Result<Self, SoundLoadError> {
409        Ok(Self {
410            shoot: include_sound!("../assets/sounds/Gun.wav")?,
411            asteroid_hit: include_sound!("../assets/sounds/Click.wav")?,
412            asteroid_death: include_sound!("../assets/sounds/Explosion.wav")?,
413            player_hit: include_sound!("../assets/sounds/Hurt.wav")?,
414            game_over: include_sound!("../assets/sounds/Powerdown.wav")?,
415            engine: include_sound!("../assets/sounds/Crunch.wav")?,
416        })
417    }
418}
419
420#[main("Space game")]
421fn main() -> anyhow::Result<()> {
422    storage_store_state(ParticleSystem::new());
423    storage_store_state(Sounds::new()?);
424
425    bind! {
426        UP => KeyCode::ArrowUp;
427        UP => KeyCode::KeyW;
428        DOWN => KeyCode::ArrowDown;
429        DOWN => KeyCode::KeyS;
430        LEFT => KeyCode::ArrowLeft;
431        LEFT => KeyCode::KeyA;
432        RIGHT => KeyCode::ArrowRight;
433        RIGHT => KeyCode::KeyD;
434        SHOOT => KeyCode::Space;
435    }
436
437    let mut state = State::new();
438
439    loop {
440        clear_screen(BG);
441        let scale = window_size() / BASE_WINDOW_SIZE * BASE_SCALE;
442        let scale = scale.x.min(scale.y);
443        get_camera_2d_mut().set_scale(scale);
444
445        state.update();
446
447        get_particles().update();
448        get_particles().draw_world();
449        state.draw();
450
451        if should_quit() {
452            break;
453        }
454
455        next_frame().await;
456    }
457
458    Ok(())
459}
460
461fn get_particles() -> &'static mut ParticleSystem {
462    storage_get_state_mut()
463}
464
465fn get_sounds() -> &'static Sounds {
466    storage_get_state()
467}
468
469fn spawn_hit_particles(pos: Vec2, impact_dir: Vec2) {
470    play_sound(get_sounds().asteroid_hit);
471    let batch = ParticleOneshot::builder()
472        .shape(&Circle::new(
473            Vec2::ZERO,
474            Vec2::splat(LINE_THICKNESS * 1.5),
475            FG.with_alpha(0.5),
476        ))
477        .end_color(FG.with_alpha(0.0))
478        .speed(3.0)
479        .direction(impact_dir.to_angle() + FRAC_PI_2)
480        .direction_randomness(1.5)
481        .speed_randomness(2.0)
482        .lifetime(0.4)
483        .lifetime_randomness(0.2)
484        .quantity(8)
485        .build();
486    get_particles().spawn_oneshot(&batch, pos);
487}
488
489fn spawn_death_particles(pos: Vec2, radius: f32) {
490    play_sound(get_sounds().asteroid_death);
491    let batch = ParticleOneshot::builder()
492        .shape(&Circle::new(
493            Vec2::ZERO,
494            Vec2::splat(LINE_THICKNESS * 2.0),
495            FG.with_alpha(0.7),
496        ))
497        .end_color(FG.with_alpha(0.0))
498        .speed(radius * 0.1)
499        .direction(0.0)
500        .direction_randomness(std::f32::consts::TAU)
501        .speed_randomness(radius * 0.2)
502        .lifetime(0.8)
503        .lifetime_randomness(0.4)
504        .quantity((radius * 1.5) as usize)
505        .position_randomness(Vec2::splat(radius * 0.5))
506        .build();
507    get_particles().spawn_oneshot(&batch, pos);
508}
Source

pub const fn with_red(self, r: f32) -> Color

Source

pub const fn with_green(self, g: f32) -> Color

Source

pub const fn with_blue(self, b: f32) -> Color

Source

pub const fn with_alpha8(self, a: u8) -> Color

Source

pub const fn with_red8(self, r: u8) -> Color

Source

pub const fn with_green8(self, g: u8) -> Color

Source

pub const fn with_blue8(self, b: u8) -> Color

Source

pub fn inverted(self) -> Color

Source

pub const fn hex(hex: u32) -> Color

Source

pub const fn hex_alpha(hex: u32) -> Color

Source

pub const fn to_hex(&self) -> u32

Source

pub fn to_hex_string(&self) -> String

Source

pub fn from_hsla(hue: f32, saturation: f32, lightness: f32, alpha: f32) -> Color

Source

pub fn from_hsl(hue: f32, saturation: f32, lightness: f32) -> Color

Source

pub fn to_oklch(&self) -> (f32, f32, f32)

Source

pub fn from_oklch_with_alpha( lightness: f32, chroma: f32, hue: f32, alpha: f32, ) -> Color

Source

pub fn from_oklch(lightness: f32, chroma: f32, hue: f32) -> Color

Examples found in repository?
examples/physics.rs (lines 38-42)
37fn speed_color(speed: f32) -> Color {
38    Color::from_oklch(
39        0.8,
40        0.1 + (speed / 100.0).clamp(0.0, 0.1),
41        142.94 - (speed / 5.0).clamp(0.0, 142.94 - 26.17),
42    )
43}
More examples
Hide additional examples
examples/3d_render_textures.rs (line 14)
9    pub fn random() -> Self {
10        Self {
11            circle: Circle {
12                center: Vec2::new(rand::<f32>() * 1000.0, rand::<f32>() * 1000.0),
13                radius: Vec2::splat(rand::<f32>() * 30.0),
14                color: Color::from_oklch(0.7493, 0.1184, rand::<f32>() * 360.0),
15            },
16            velocity: Vec2::ZERO,
17        }
18    }
examples/screenshot.rs (line 64)
57async fn draw_pattern() {
58    let mut hue = 0.0;
59    let mut offset = vec2(0.0, 0.0);
60
61    loop {
62        hue += 20.0 * delta_time();
63        hue %= 360.0;
64        let color = Color::from_oklch(0.727, 0.1219, hue);
65        let alt_color = color.darken_oklch(0.05);
66
67        offset -= vec2(0.5, 0.25) * delta_time();
68
69        draw_sdf(
70            Sdf::rect_tl(vec2(0.0, 0.0), window_size())
71                .with_fill(color, alt_color, FRAC_PI_2, 5.0, SdfFill::Truchet)
72                .with_fill_offset(offset),
73        );
74
75        let r = min_window_dimension() / 5.0;
76
77        draw_circle(window_center(), r, Color::BLACK);
78        push_scissor(Area::new(vec2(window_center().x, 0.0), window_size()).to_rect());
79        draw_circle(window_center(), r, Color::WHITE);
80        pop_scissor();
81
82        next_frame().await;
83    }
84}
Source

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

Source

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

Source

pub fn saturate(self, factor: f32) -> Color

Source

pub fn desaturate(self, factor: f32) -> Color

Source

pub fn hue_rotate(self, degrees: f32) -> Color

Source

pub fn lighten_oklch(self, factor: f32) -> Color

Source

pub fn darken_oklch(self, factor: f32) -> Color

Examples found in repository?
examples/screenshot.rs (line 65)
57async fn draw_pattern() {
58    let mut hue = 0.0;
59    let mut offset = vec2(0.0, 0.0);
60
61    loop {
62        hue += 20.0 * delta_time();
63        hue %= 360.0;
64        let color = Color::from_oklch(0.727, 0.1219, hue);
65        let alt_color = color.darken_oklch(0.05);
66
67        offset -= vec2(0.5, 0.25) * delta_time();
68
69        draw_sdf(
70            Sdf::rect_tl(vec2(0.0, 0.0), window_size())
71                .with_fill(color, alt_color, FRAC_PI_2, 5.0, SdfFill::Truchet)
72                .with_fill_offset(offset),
73        );
74
75        let r = min_window_dimension() / 5.0;
76
77        draw_circle(window_center(), r, Color::BLACK);
78        push_scissor(Area::new(vec2(window_center().x, 0.0), window_size()).to_rect());
79        draw_circle(window_center(), r, Color::WHITE);
80        pop_scissor();
81
82        next_frame().await;
83    }
84}
Source

pub fn hue_rotate_oklch(self, degrees: f32) -> Color

Source

pub fn to_color_u8(self) -> ColorU8

Source

pub fn blend_two(a: Color, b: Color, fac: f32) -> Color

Source

pub fn blend_two_halfway(a: Color, b: Color) -> Color

Source

pub fn blend(self, other: Color, fac: f32) -> Color

Source

pub fn blend_halfway(self, other: Color) -> Color

Source

pub fn to_linear(self) -> Color

Source

pub fn from_usize(n: usize) -> Color

Source

pub fn from_usize_no_alpha(n: usize) -> Color

Trait Implementations§

Source§

impl Add for Color

Source§

type Output = Color

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign for Color

Source§

fn add_assign(&mut self, rhs: Color)

Performs the += operation. Read more
Source§

impl Animatable for Color

Source§

fn interpolate(a: Color, b: Color, progress: f32) -> Color

Source§

impl Archive for Color
where f32: Archive,

Source§

const COPY_OPTIMIZATION: CopyOptimization<Color>

An optimization flag that allows the bytes of this type to be copied directly to a writer instead of calling serialize. Read more
Source§

type Archived = ArchivedColor

The archived representation of this type. Read more
Source§

type Resolver = ColorResolver

The resolver for this type. It must contain all the additional information from serializing needed to make the archived type from the normal type.
Source§

fn resolve( &self, resolver: <Color as Archive>::Resolver, out: Place<<Color as Archive>::Archived>, )

Creates the archived version of this value at the given position and writes it to the given output. Read more
Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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<__D> Deserialize<Color, __D> for <Color as Archive>::Archived
where __D: Fallible + ?Sized, f32: Archive, <f32 as Archive>::Archived: Deserialize<f32, __D>,

Source§

fn deserialize( &self, deserializer: &mut __D, ) -> Result<Color, <__D as Fallible>::Error>

Deserializes using the given deserializer
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 (const: unstable) · 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 PartialLerp for Color

Source§

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

Source§

impl PartialOrd for Color

Source§

fn partial_cmp(&self, other: &Color) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<__S> Serialize<__S> for Color
where __S: Fallible + ?Sized, f32: Serialize<__S>,

Source§

fn serialize( &self, serializer: &mut __S, ) -> Result<<Color as Archive>::Resolver, <__S as Fallible>::Error>

Writes the dependencies for the object and returns a resolver that can create the archived type.
Source§

impl Sub for Color

Source§

type Output = Color

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Color) -> <Color as Sub>::Output

Performs the - operation. Read more
Source§

impl SubAssign for Color

Source§

fn sub_assign(&mut self, rhs: Color)

Performs the -= operation. Read more
Source§

impl Copy 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 UnsafeUnpin for Color

§

impl UnwindSafe for Color

Blanket Implementations§

Source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Real + Zero + Arithmetics + Clone, Swp: WhitePoint<T>, Dwp: WhitePoint<T>, D: AdaptFrom<S, Swp, Dwp, T>,

Source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<T>,

Convert the source color to the destination color using the specified method.
Source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default.
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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> ArchiveUnsized for T
where T: Archive,

Source§

type Archived = <T as Archive>::Archived

The archived counterpart of this type. Unlike Archive, it may be unsized. Read more
Source§

fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata

Creates the archived version of the metadata for this value.
Source§

impl<T, C> ArraysFrom<C> for T
where C: IntoArrays<T>,

Source§

fn arrays_from(colors: C) -> T

Cast a collection of colors into a collection of arrays.
Source§

impl<T, C> ArraysInto<C> for T
where C: FromArrays<T>,

Source§

fn arrays_into(self) -> C

Cast this collection of arrays into a collection of colors.
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for U
where T: FromCam16Unclamped<WpParam, U>,

Source§

type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
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, C> ComponentsFrom<C> for T
where C: IntoComponents<T>,

Source§

fn components_from(colors: C) -> T

Cast a collection of colors into a collection of color components.
Source§

impl<T> Content for T
where T: Copy,

Source§

type Owned = T

A type that holds a sized version of the content.
Source§

unsafe fn read<F, E>(size: usize, f: F) -> Result<T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

Prepares an output buffer, then turns this buffer into an Owned. User-provided closure F must only write to and not read from &mut Self.
Source§

fn get_elements_size() -> usize

Returns the size of each element.
Source§

fn to_void_ptr(&self) -> *const ()

Produces a pointer to the data.
Source§

fn ref_from_ptr<'a>(ptr: *mut (), size: usize) -> Option<*mut T>

Builds a pointer to this type from a raw pointer.
Source§

fn is_size_suitable(size: usize) -> bool

Returns true if the size is suitable to store a type like this.
Source§

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

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

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

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromAngle<T> for T

Source§

fn from_angle(angle: T) -> T

Performs a conversion from angle.
Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> FromStimulus<U> for T
where U: IntoStimulus<T>,

Source§

fn from_stimulus(other: U) -> T

Converts other into Self, while performing the appropriate scaling, rounding and clamping.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> IntoAngle<U> for T
where U: FromAngle<T>,

Source§

fn into_angle(self) -> U

Performs a conversion into T.
Source§

impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for U
where T: Cam16FromUnclamped<WpParam, U>,

Source§

type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<T, U> IntoColor<U> for T
where U: FromColor<T>,

Source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
Source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

Source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
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> IntoStimulus<T> for T

Source§

fn into_stimulus(self) -> T

Converts self into T, while performing the appropriate scaling, rounding and clamping.
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> PartialClamp for T
where T: PartialOrd,

Source§

fn clamp(self, min: Self, max: Self) -> Self

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<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SerializeUnsized<S> for T
where T: Serialize<S>, S: Fallible + Writer + ?Sized,

Source§

fn serialize_unsized( &self, serializer: &mut S, ) -> Result<usize, <S as Fallible>::Error>

Writes the object and returns the position of the archived type.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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, C> TryComponentsInto<C> for T
where C: TryFromComponents<T>,

Source§

type Error = <C as TryFromComponents<T>>::Error

The error for when try_into_colors fails to cast.
Source§

fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>

Try to cast this collection of color components into a collection of colors. Read more
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, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

Source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
Source§

impl<C, U> UintsFrom<C> for U
where C: IntoUints<U>,

Source§

fn uints_from(colors: C) -> U

Cast a collection of colors into a collection of unsigned integers.
Source§

impl<C, U> UintsInto<C> for U
where C: FromUints<U>,

Source§

fn uints_into(self) -> C

Cast this collection of unsigned integers into a collection of colors.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T, Right> ClosedAdd<Right> for T
where T: Add<Right, Output = T> + AddAssign<Right>,

Source§

impl<T, Right> ClosedAddAssign<Right> for T
where T: ClosedAdd<Right> + AddAssign<Right>,

Source§

impl<T, Right> ClosedSub<Right> for T
where T: Sub<Right, Output = T> + SubAssign<Right>,

Source§

impl<T, Right> ClosedSubAssign<Right> for T
where T: ClosedSub<Right> + SubAssign<Right>,

Source§

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

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

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