Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 0 additions & 74 deletions examples/chaining.rs

This file was deleted.

145 changes: 51 additions & 94 deletions examples/primitives-stroke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,109 +12,66 @@ use embedded_graphics_simulator::{OutputSettings, SimulatorDisplay, Window};

const PADDING: i32 = 16;

fn main() -> Result<(), core::convert::Infallible> {
let mut display: SimulatorDisplay<BinaryColor> = SimulatorDisplay::new(Size::new(512, 256));
/// Draws all embedded-graphics primitives.
fn draw_primitives<D>(target: &mut D, style: PrimitiveStyle<BinaryColor>) -> Result<(), D::Error>
where
D: DrawTarget<Color = BinaryColor>,
{
Triangle::new(Point::new(0, 64), Point::new(64, 0), Point::new(64, 64))
.into_styled(style)
.draw(target)?;

let thin_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 1);
let medium_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 3);
let thick_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 10);
Rectangle::new(Point::new(0, 0), Size::new(64, 64))
.translate(Point::new(64 + PADDING, 0))
.into_styled(style)
.draw(target)?;

let triangle = Triangle::new(Point::new(0, 64), Point::new(64, 0), Point::new(64, 64));
let rectangle =
Rectangle::new(Point::new(0, 0), Size::new(64, 64)).translate(Point::new(64 + PADDING, 0));
let line = Line::new(Point::new(0, 0), Point::new(64, 64))
.translate(Point::new((64 + PADDING) * 2, 0));
let circle = Circle::new(Point::new(0, 0), 64).translate(Point::new((64 + PADDING) * 3, 0));
let rounded_rectangle = RoundedRectangle::new(
Line::new(Point::new(0, 0), Point::new(64, 64))
.translate(Point::new((64 + PADDING) * 2, 0))
.into_styled(style)
.draw(target)?;

Circle::new(Point::new(0, 0), 64)
.translate(Point::new((64 + PADDING) * 3, 0))
.into_styled(style)
.draw(target)?;

RoundedRectangle::new(
Rectangle::new(Point::new(0, 0), Size::new(64, 64)),
CornerRadii::new(Size::new(16, 16)),
)
.translate(Point::new((64 + PADDING) * 4, 0));
.translate(Point::new((64 + PADDING) * 4, 0))
.into_styled(style)
.draw(target)?;

let ellipse = Ellipse::new(Point::new(0, 0), Size::new(96, 64))
.translate(Point::new((64 + PADDING) * 5, 0));
Ellipse::new(Point::new(0, 0), Size::new(96, 64))
.translate(Point::new((64 + PADDING) * 5, 0))
.into_styled(style)
.draw(target)
}

fn main() -> Result<(), core::convert::Infallible> {
let mut display = SimulatorDisplay::<BinaryColor>::new(Size::new(512, 256));

let thin_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 1);
let medium_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 3);
let thick_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 10);

circle
.into_styled(thin_stroke)
.into_pixels()
.chain(rectangle.into_styled(thin_stroke).into_pixels())
.chain(line.into_styled(thin_stroke).into_pixels())
.chain(triangle.into_styled(thin_stroke).into_pixels())
.chain(ellipse.into_styled(thin_stroke).into_pixels())
.chain(rounded_rectangle.into_styled(thin_stroke).into_pixels())
.draw(&mut display)?;
// Draw the primitives using a thin stroke.
//
// Instead of directly drawing to the display a `TranslatedDrawTarget` is created by
// using `display.translated(position)`. This translates all drawing operations in `draw_shapes`
// by 10 pixels in the x and y direction.
let mut position = Point::new(10, 10);
draw_primitives(&mut display.translated(position), thin_stroke)?;

let offset = Point::new(0, 64 + PADDING);
circle
.translate(offset)
.into_styled(medium_stroke)
.into_pixels()
.chain(
rectangle
.translate(offset)
.into_styled(medium_stroke)
.into_pixels(),
)
.chain(
line.translate(offset)
.into_styled(medium_stroke)
.into_pixels(),
)
.chain(
triangle
.translate(offset)
.into_styled(medium_stroke)
.into_pixels(),
)
.chain(
ellipse
.translate(offset)
.into_styled(medium_stroke)
.into_pixels(),
)
.chain(
rounded_rectangle
.translate(offset)
.into_styled(medium_stroke)
.into_pixels(),
)
.draw(&mut display)?;
// Draw the primitives using a medium stroke.
position.y += 64 + PADDING;
draw_primitives(&mut display.translated(position), medium_stroke)?;

let offset = Point::new(0, (64 + PADDING) * 2);
circle
.translate(offset)
.into_styled(thick_stroke)
.into_pixels()
.chain(
rectangle
.translate(offset)
.into_styled(thick_stroke)
.into_pixels(),
)
.chain(
line.translate(offset)
.into_styled(thick_stroke)
.into_pixels(),
)
.chain(
triangle
.translate(offset)
.into_styled(thick_stroke)
.into_pixels(),
)
.chain(
ellipse
.translate(offset)
.into_styled(thick_stroke)
.into_pixels(),
)
.chain(
rounded_rectangle
.translate(offset)
.into_styled(thick_stroke)
.into_pixels(),
)
.draw(&mut display)?;
// Draw the primitives using a thick stroke.
position.y += 64 + PADDING;
draw_primitives(&mut display.translated(position), thick_stroke)?;

Window::new("Strokes", &OutputSettings::default()).show_static(&display);

Expand Down