mirror of
https://gitlab.com/feliix42/embedded-plots.git
synced 2024-11-22 01:46:30 +00:00
Dummy plot implementation
This commit is contained in:
parent
e74a39d396
commit
242d8eb750
3 changed files with 64 additions and 2 deletions
|
@ -7,6 +7,10 @@ edition = "2018"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
embedded-graphics = "0.6.0"
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
embedded-graphics-simulator = "0.2.1"
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,24 @@
|
|||
fn main() {
|
||||
println!("Hello world!");
|
||||
use embedded_graphics::{
|
||||
pixelcolor::Rgb565,
|
||||
prelude::*,
|
||||
};
|
||||
use embedded_graphics_simulator::{SimulatorDisplay, Window, OutputSettingsBuilder};
|
||||
|
||||
use embedded_plots::Plot;
|
||||
|
||||
fn main() -> Result<(), core::convert::Infallible> {
|
||||
let mut display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(480, 272));
|
||||
|
||||
Plot::new(
|
||||
vec![
|
||||
Point::new(100, 100),
|
||||
Point::new(150, 100),
|
||||
Point::new(200, 200)],RgbColor::GREEN)
|
||||
.draw(&mut display)?;
|
||||
|
||||
let output_settings = OutputSettingsBuilder::new()
|
||||
.build();
|
||||
Window::new("Hello World", &output_settings).show_static(&display);
|
||||
|
||||
Ok(())
|
||||
}
|
37
src/lib.rs
37
src/lib.rs
|
@ -1,3 +1,40 @@
|
|||
use embedded_graphics::drawable::{Drawable};
|
||||
use embedded_graphics::DrawTarget;
|
||||
use embedded_graphics::geometry::Point;
|
||||
use embedded_graphics::pixelcolor::{PixelColor};
|
||||
use embedded_graphics::primitives::{Line, Primitive};
|
||||
use embedded_graphics::style::PrimitiveStyle;
|
||||
|
||||
|
||||
pub struct Plot<C>
|
||||
{
|
||||
data: Vec<Point>,
|
||||
color: C,
|
||||
}
|
||||
|
||||
impl<C> Plot<C>
|
||||
where C: PixelColor
|
||||
{
|
||||
pub fn new(data: Vec<Point>,color : C) -> Plot<C> {
|
||||
Plot {
|
||||
data,
|
||||
color,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> Drawable<C> for Plot<C>
|
||||
where C: PixelColor
|
||||
{
|
||||
fn draw<D: DrawTarget<C>>(self, display: &mut D) -> Result<(), <D as DrawTarget<C>>::Error> {
|
||||
let style = PrimitiveStyle::with_stroke(self.color,2);
|
||||
for i in 1..self.data.len() {
|
||||
Line::new(self.data[i-1],self.data[i]).into_styled(style).draw(display)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue