/* ---------------------------------------------------------- fastxline zeichnet eine Linie in X-Achse mit den X Punkten x1 und x2 auf der Y-Achse y1 x1, x2 : Start-, Endpunkt der Linie y1 : Y-Koordinate der Linie color : 16 - Bit RGB565 Farbwert der gezeichnet werden soll ---------------------------------------------------------- */ void fastxline(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t color) { uint8_t x; if (x2< x1) { x= x1; x1= x2; x= x2= x; } for (x= x1; x< (x2+1); x++) { putpixel(x,y1, color); } } /* ------------------------------------------------------------- line Zeichnet eine Linie von den Koordinaten x0,y0 zu x1,y1 mit der angegebenen Farbe x0,y0 : Koordinate linke obere Ecke x1,y1 : Koordinate rechte untere Ecke color : 16 - Bit RGB565 Farbwert der gezeichnet werden soll Linienalgorithmus nach Bresenham (www.wikipedia.org) ------------------------------------------------------------- */ void line(int x0, int y0, int x1, int y1, uint16_t color) { // Linienalgorithmus nach Bresenham (www.wikipedia.org) int dx = abs(x1-x0), sx = x0 dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */ if (e2 < dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */ } } /* ------------------------------------------------------------- ellipse Zeichnet eine Ellipse mit Mittelpunt an der Koordinate xm,ym mit den Hoehen- Breitenverhaeltnis a:b mit der angegebenen Farbe xm,ym : Koordinate des Mittelpunktes der Ellipse a,b : Hoehen- Breitenverhaeltnis color : 16 - Bit RGB565 Farbwert der gezeichnet werden soll Ellipsenalgorithmus nach Bresenham (www.wikipedia.org) ------------------------------------------------------------- */ void ellipse(int xm, int ym, int a, int b, uint16_t color ) { // Algorithmus nach Bresenham (www.wikipedia.org) 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 { putpixel(xm+dx, ym+dy,color); // I. Quadrant putpixel(xm-dx, ym+dy,color); // II. Quadrant putpixel(xm-dx, ym-dy,color); // III. Quadrant putpixel(xm+dx, ym-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) { putpixel(xm+dx, ym,color); // -> Spitze der Ellipse vollenden putpixel(xm-dx, ym,color); } } /* ------------------------------------------------------------- circle Zeichnet einen Kreis mit Mittelpunt an der Koordinate xm,ym und dem Radius r mit der angegebenen Farbe x ,y : Koordinate des Mittelpunktes der Ellipse r : Radius des Kreises color : 16 - Bit RGB565 Farbwert der gezeichnet werden soll ------------------------------------------------------------- */ void circle(int x, int y, int r, uint16_t color ) { ellipse(x,y,r,r,color); } /* ------------------------------------------------------------- fillellipse Zeichnet eine ausgefuellte Ellipse mit Mittelpunt an der Koordinate xm,ym mit den Hoehen- Breitenverhaeltnis a:b mit der angegebenen Farbe xm,ym : Koordinate des Mittelpunktes der Ellipse a,b : Hoehen- Breitenverhaeltnis color : 16 - Bit RGB565 Farbwert der gezeichnet werden soll Ellipsenalgorithmus nach Bresenham (www.wikipedia.org) ------------------------------------------------------------- */ void fillellipse(int xm, int ym, int a, int b, uint16_t color ) { // Algorithmus nach Bresenham (www.wikipedia.org) 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 { fastxline(xm+dx, ym+dy,xm-dx, color); // I. und II. Quadrant fastxline(xm-dx, ym-dy,xm+dx, color); // III. und 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) { putpixel(xm+dx, ym,color); // -> Spitze der Ellipse vollenden putpixel(xm-dx, ym,color); } } /* ------------------------------------------------------------- fillcircle Zeichnet einen ausgefuellten Kreis mit Mittelpunt an der Koordinate xm,ym und dem Radius r mit der angegebenen Farbe x,y : Koordinate des Mittelpunktes der Ellipse r : Radius des Kreises color : 16 - Bit RGB565 Farbwert der gezeichnet werden soll ------------------------------------------------------------- */ void fillcircle(int x, int y, int r, uint16_t color ) { fillellipse(x,y,r,r,color); }