2023-01-07 18:17:43 +08:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
extern crate alloc;
|
2023-01-17 13:28:31 +08:00
|
|
|
extern crate user_lib;
|
2023-01-07 18:17:43 +08:00
|
|
|
|
2023-01-17 13:28:31 +08:00
|
|
|
use user_lib::{Display, VIRTGPU_XRES, VIRTGPU_YRES};
|
2023-01-07 23:36:05 +08:00
|
|
|
|
2023-01-07 18:17:43 +08:00
|
|
|
use embedded_graphics::pixelcolor::Rgb888;
|
2023-01-11 09:02:54 -08:00
|
|
|
use embedded_graphics::prelude::{DrawTarget, Drawable, Point, RgbColor, Size};
|
2023-01-17 13:28:31 +08:00
|
|
|
use embedded_graphics::primitives::{Circle, Primitive, PrimitiveStyle, Rectangle,Triangle};
|
2023-01-07 18:17:43 +08:00
|
|
|
|
2023-01-17 13:28:31 +08:00
|
|
|
const INIT_X: i32 = 80;
|
2023-01-07 18:17:43 +08:00
|
|
|
const INIT_Y: i32 = 400;
|
2023-01-17 13:28:31 +08:00
|
|
|
const RECT_SIZE: u32 = 150;
|
2023-01-07 18:17:43 +08:00
|
|
|
|
|
|
|
pub struct DrawingBoard {
|
|
|
|
disp: Display,
|
|
|
|
latest_pos: Point,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DrawingBoard {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {
|
2023-01-11 09:02:54 -08:00
|
|
|
disp: Display::new(Size::new(VIRTGPU_XRES, VIRTGPU_YRES)),
|
2023-01-07 18:17:43 +08:00
|
|
|
latest_pos: Point::new(INIT_X, INIT_Y),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn paint(&mut self) {
|
|
|
|
Rectangle::with_center(self.latest_pos, Size::new(RECT_SIZE, RECT_SIZE))
|
2023-01-17 13:28:31 +08:00
|
|
|
.into_styled(PrimitiveStyle::with_stroke(Rgb888::RED, 10))
|
|
|
|
.draw(&mut self.disp)
|
|
|
|
.ok();
|
|
|
|
Circle::new(self.latest_pos + Point::new(-70, -300), 150)
|
|
|
|
.into_styled(PrimitiveStyle::with_fill(Rgb888::BLUE))
|
|
|
|
.draw(&mut self.disp)
|
|
|
|
.ok();
|
|
|
|
Triangle::new(self.latest_pos + Point::new(0, 150), self.latest_pos + Point::new(80, 200), self.latest_pos + Point::new(-120, 300))
|
|
|
|
.into_styled(PrimitiveStyle::with_stroke(Rgb888::GREEN, 10))
|
2023-01-07 18:17:43 +08:00
|
|
|
.draw(&mut self.disp)
|
|
|
|
.ok();
|
|
|
|
}
|
|
|
|
fn unpaint(&mut self) {
|
|
|
|
Rectangle::with_center(self.latest_pos, Size::new(RECT_SIZE, RECT_SIZE))
|
2023-01-17 13:28:31 +08:00
|
|
|
.into_styled(PrimitiveStyle::with_stroke(Rgb888::BLACK, 10))
|
2023-01-07 18:17:43 +08:00
|
|
|
.draw(&mut self.disp)
|
|
|
|
.ok();
|
|
|
|
}
|
|
|
|
pub fn move_rect(&mut self, dx: i32, dy: i32) {
|
|
|
|
self.unpaint();
|
|
|
|
self.latest_pos.x += dx;
|
|
|
|
self.latest_pos.y += dy;
|
|
|
|
self.paint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn main() -> i32 {
|
2023-01-07 19:14:20 +08:00
|
|
|
let mut board = DrawingBoard::new();
|
2023-01-10 16:29:36 +08:00
|
|
|
let _ = board.disp.clear(Rgb888::BLACK).unwrap();
|
2023-01-17 13:28:31 +08:00
|
|
|
for i in 0..5 {
|
|
|
|
board.latest_pos.x += (RECT_SIZE as i32 + 20);
|
|
|
|
//board.latest_pos.y += i;
|
2023-01-07 19:14:20 +08:00
|
|
|
board.paint();
|
2023-01-07 18:17:43 +08:00
|
|
|
}
|
|
|
|
0
|
|
|
|
}
|