From 81096ef454a9aacacf3853f7dfe96b8b9228f200 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 14 Apr 2020 06:38:06 +0200 Subject: Implement `From` for `canvas::Fill` --- examples/solar_system/src/main.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'examples/solar_system/src') diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 963f047b..d2c6e38f 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -128,7 +128,7 @@ impl State { impl canvas::Drawable for State { fn draw(&self, frame: &mut canvas::Frame) { - use canvas::{Fill, Path, Stroke}; + use canvas::{Path, Stroke}; use std::f32::consts::PI; let center = frame.center(); @@ -146,9 +146,9 @@ impl canvas::Drawable for State { let sun = Path::new(|path| path.circle(center, Self::SUN_RADIUS)); let orbit = Path::new(|path| path.circle(center, Self::ORBIT_RADIUS)); - frame.fill(&space, Fill::Color(Color::BLACK)); - frame.fill(&stars, Fill::Color(Color::WHITE)); - frame.fill(&sun, Fill::Color(Color::from_rgb8(0xF9, 0xD7, 0x1C))); + frame.fill(&space, Color::BLACK); + frame.fill(&stars, Color::WHITE); + frame.fill(&sun, Color::from_rgb8(0xF9, 0xD7, 0x1C)); frame.stroke( &orbit, Stroke { @@ -184,7 +184,7 @@ impl canvas::Drawable for State { ) }); - frame.fill(&earth, Fill::Color(Color::from_rgb8(0x6B, 0x93, 0xD6))); + frame.fill(&earth, Color::from_rgb8(0x6B, 0x93, 0xD6)); frame.with_save(|frame| { frame.rotate( @@ -197,15 +197,15 @@ impl canvas::Drawable for State { path.circle(Point::ORIGIN, Self::MOON_RADIUS) }); - frame.fill(&moon, Fill::Color(Color::WHITE)); + frame.fill(&moon, Color::WHITE); }); frame.fill( &shadow, - Fill::Color(Color { + Color { a: 0.7, ..Color::BLACK - }), + }, ); }); } -- cgit From c545af35773307d16eca7ec03ed4794f26491da2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 14 Apr 2020 06:49:15 +0200 Subject: Implement `canvas::Path::rectangle` helper method --- examples/solar_system/src/main.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'examples/solar_system/src') diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index d2c6e38f..067f8ff2 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -133,9 +133,7 @@ impl canvas::Drawable for State { let center = frame.center(); - let space = Path::new(|path| { - path.rectangle(Point::new(0.0, 0.0), frame.size()) - }); + let space = Path::rectangle(Point::new(0.0, 0.0), frame.size()); let stars = Path::new(|path| { for (p, size) in &self.stars { @@ -174,15 +172,10 @@ impl canvas::Drawable for State { path.circle(Point::ORIGIN, Self::EARTH_RADIUS) }); - let shadow = Path::new(|path| { - path.rectangle( - Point::new(0.0, -Self::EARTH_RADIUS), - Size::new( - Self::EARTH_RADIUS * 4.0, - Self::EARTH_RADIUS * 2.0, - ), - ) - }); + let shadow = Path::rectangle( + Point::new(0.0, -Self::EARTH_RADIUS), + Size::new(Self::EARTH_RADIUS * 4.0, Self::EARTH_RADIUS * 2.0), + ); frame.fill(&earth, Color::from_rgb8(0x6B, 0x93, 0xD6)); -- cgit From 46cd0891d25c2dd48e182747d8c1f9579b066490 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 14 Apr 2020 06:54:12 +0200 Subject: Implement `canvas::Path::circle` helper method --- examples/solar_system/src/main.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'examples/solar_system/src') diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 067f8ff2..bcd1dc71 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -141,8 +141,8 @@ impl canvas::Drawable for State { } }); - let sun = Path::new(|path| path.circle(center, Self::SUN_RADIUS)); - let orbit = Path::new(|path| path.circle(center, Self::ORBIT_RADIUS)); + let sun = Path::circle(center, Self::SUN_RADIUS); + let orbit = Path::circle(center, Self::ORBIT_RADIUS); frame.fill(&space, Color::BLACK); frame.fill(&stars, Color::WHITE); @@ -168,10 +168,7 @@ impl canvas::Drawable for State { ); frame.translate(Vector::new(Self::ORBIT_RADIUS, 0.0)); - let earth = Path::new(|path| { - path.circle(Point::ORIGIN, Self::EARTH_RADIUS) - }); - + let earth = Path::circle(Point::ORIGIN, Self::EARTH_RADIUS); let shadow = Path::rectangle( Point::new(0.0, -Self::EARTH_RADIUS), Size::new(Self::EARTH_RADIUS * 4.0, Self::EARTH_RADIUS * 2.0), @@ -186,10 +183,7 @@ impl canvas::Drawable for State { ); frame.translate(Vector::new(0.0, Self::MOON_DISTANCE)); - let moon = Path::new(|path| { - path.circle(Point::ORIGIN, Self::MOON_RADIUS) - }); - + let moon = Path::circle(Point::ORIGIN, Self::MOON_RADIUS); frame.fill(&moon, Color::WHITE); }); -- cgit