diff --git a/src/main.rs b/src/main.rs index 2f8e437..00f0944 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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); diff --git a/src/st7735/gfx.rs b/src/st7735/gfx.rs index c458627..209ce4d 100644 --- a/src/st7735/gfx.rs +++ b/src/st7735/gfx.rs @@ -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); + } + } }