Added drawing circles

This commit is contained in:
Sebastian 2018-09-09 03:01:14 +02:00
parent f367eefb1e
commit 23883c9bce
2 changed files with 39 additions and 0 deletions

View File

@ -129,6 +129,7 @@ fn run(mut scs: scs::Instance, mut p: hcl::platform::Instance) {
st7735io.fill_rect(80, 4, 76, 60, st7735::COLOR_BLUE);
st7735io.fill_rect(80, 64, 76, 60, st7735::COLOR_YELLOW);
st7735io.draw_circle(80, 64, 20, st7735::COLOR_MAGENTA);
st7735io.draw_line(4, 4, 80, 64, st7735::COLOR_GREEN);
systick::delay_ms(2000);

View File

@ -85,4 +85,42 @@ pub trait GFX : PrimitveGFX {
}
}
fn draw_circle(&mut self, x0 : u8, y0 : u8, r : u8, color : u16) {
let mut f : i16 = 1 - (r as i16);
let mut ddF_x : i16 = 1;
let mut ddF_y : i16 = -2 * (r as i16);
let mut x : i16 = 0;
let mut y : i16 = r as i16;
self.draw_pixel(x0, y0 + r, color);
self.draw_pixel(x0, y0 - r, color);
self.draw_pixel(x0 + r, y0, color);
self.draw_pixel(x0 - r, y0, color);
let x0 = x0 as i16;
let y0 = y0 as i16;
let r = r as i16;
while x < y {
if f >= 0 {
y -= 1;
ddF_y += 2;
f += ddF_y;
}
x += 1;
ddF_x += 2;
f += ddF_x;
self.draw_pixel((x0 + x) as u8, (y0 + y) as u8, color);
self.draw_pixel((x0 - x) as u8, (y0 + y) as u8, color);
self.draw_pixel((x0 + x) as u8, (y0 - y) as u8, color);
self.draw_pixel((x0 - x) as u8, (y0 - y) as u8, color);
self.draw_pixel((x0 + y) as u8, (y0 + x) as u8, color);
self.draw_pixel((x0 - y) as u8, (y0 + x) as u8, color);
self.draw_pixel((x0 + y) as u8, (y0 - x) as u8, color);
self.draw_pixel((x0 - y) as u8, (y0 - x) as u8, color);
}
}
}