From ed39db99a579342ad354b00f5639258f43528e6d Mon Sep 17 00:00:00 2001 From: Tectu Date: Tue, 10 Jul 2012 01:15:31 +0200 Subject: [PATCH] added lcdDrawEllipse() - contributed by Ben William --- glcd.c | 28 ++++++++++++++++++++++++++++ glcd.h | 1 + lcd.mk | 1 + 3 files changed, 30 insertions(+) diff --git a/glcd.c b/glcd.c index 8ab87597..683f8a3a 100644 --- a/glcd.c +++ b/glcd.c @@ -319,6 +319,34 @@ void lcdDrawCircle(uint16_t x, uint16_t y, uint16_t radius, uint8_t filled, uint } while(a <= b); } +void lcdDrawEllipse(uint16_t x, uint16_t y, uint16_t a, uint16_t b, uint16_t color) { + int dx = 0, dy = b; /* im I. Quadranten von links oben nach rechts unten */ + long a2 = a*a, b2 = b*b; + long err = b2-(2*b-1)*a2, e2; /* Fehler im 1. Schritt */ + + do { + lcdDrawPixel(x+dx, y+dy, color); /* I. Quadrant */ + lcdDrawPixel(x-dx, y+dy, color); /* II. Quadrant */ + lcdDrawPixel(x-dx, y-dy, color); /* III. Quadrant */ + lcdDrawPixel(x+dx, y-dy, color); /* IV. Quadrant */ + + e2 = 2*err; + if(e2 < (2*dx+1)*b2) { + dx++; + err += (2*dx+1)*b2; + } + if(e2 > -(2*dy-1)*a2) { + dy--; + err -= (2*dy-1)*a2; + } + } while(dy >= 0); + + while(dx++ < a) { /* fehlerhafter Abbruch bei flachen Ellipsen (b=1) */ + lcdDrawPixel(x+dx, y, color); /* -> Spitze der Ellipse vollenden */ + lcdDrawPixel(x-dx, y, color); + } +} + void lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, int16_t lines) { lld_lcdVerticalScroll(x0,y0,x1,y1,lines); } diff --git a/glcd.h b/glcd.h index 531be901..bb587253 100644 --- a/glcd.h +++ b/glcd.h @@ -67,6 +67,7 @@ void lcdDrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t co void lcdDrawRect(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t filled, uint16_t color); void lcdDrawRectString(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, const char* str, font_t font, uint16_t fontColor, uint16_t bkColor); void lcdDrawCircle(uint16_t x, uint16_t y, uint16_t radius, uint8_t filled, uint16_t color); +void lcdDrawEllipse(uint16_t x, uint16_t y, uint16_t a, uint16_t b, uint16_t color); /* Text Rendering Functions */ int lcdDrawChar(uint16_t cx, uint16_t cy, char c, font_t font, uint16_t color, uint16_t bkcolor, bool_t tpText); diff --git a/lcd.mk b/lcd.mk index 5ba7df1b..6bae4072 100644 --- a/lcd.mk +++ b/lcd.mk @@ -8,6 +8,7 @@ LCDSRC = $(LCDLIB)/glcd.c \ $(LCDLIB)/graph.c \ $(LCDLIB)/gui.c \ $(LCDLIB)/console.c \ + $(LCDLIB)/fastMath.c \ $(LCD_DRIVERS_SRC) LCDINC = $(LCDLIB) \