|
@@ -345,6 +345,122 @@ void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**************************************************************************/
|
|
|
|
|
+/*!
|
|
|
|
|
+ @brief Draw an ellipse outline
|
|
|
|
|
+ @param x0 Center-point x coordinate
|
|
|
|
|
+ @param y0 Center-point y coordinate
|
|
|
|
|
+ @param rw Horizontal radius of ellipse
|
|
|
|
|
+ @param rh Vertical radius of ellipse
|
|
|
|
|
+ @param color 16-bit 5-6-5 Color to draw with
|
|
|
|
|
+*/
|
|
|
|
|
+/**************************************************************************/
|
|
|
|
|
+void Adafruit_GFX::drawEllipse(int16_t x0, int16_t y0, int16_t rw, int16_t rh,
|
|
|
|
|
+ uint16_t color) {
|
|
|
|
|
+#if defined(ESP8266)
|
|
|
|
|
+ yield();
|
|
|
|
|
+#endif
|
|
|
|
|
+ // Bresenham's ellipse algorithm
|
|
|
|
|
+ int16_t x = 0, y = rh;
|
|
|
|
|
+ int32_t rw2 = rw * rw, rh2 = rh * rh;
|
|
|
|
|
+ int32_t twoRw2 = 2 * rw2, twoRh2 = 2 * rh2;
|
|
|
|
|
+
|
|
|
|
|
+ int32_t decision = rh2 - (rw2 * rh) + (rw2 / 4);
|
|
|
|
|
+
|
|
|
|
|
+ startWrite();
|
|
|
|
|
+
|
|
|
|
|
+ // region 1
|
|
|
|
|
+ while ((twoRh2 * x) < (twoRw2 * y)) {
|
|
|
|
|
+ writePixel(x0 + x, y0 + y, color);
|
|
|
|
|
+ writePixel(x0 - x, y0 + y, color);
|
|
|
|
|
+ writePixel(x0 + x, y0 - y, color);
|
|
|
|
|
+ writePixel(x0 - x, y0 - y, color);
|
|
|
|
|
+ x++;
|
|
|
|
|
+ if (decision < 0) {
|
|
|
|
|
+ decision += rh2 + (twoRh2 * x);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ decision += rh2 + (twoRh2 * x) - (twoRw2 * y);
|
|
|
|
|
+ y--;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // region 2
|
|
|
|
|
+ decision = ((rh2 * (2 * x + 1) * (2 * x + 1)) >> 2) +
|
|
|
|
|
+ (rw2 * (y - 1) * (y - 1)) - (rw2 * rh2);
|
|
|
|
|
+ while (y >= 0) {
|
|
|
|
|
+ writePixel(x0 + x, y0 + y, color);
|
|
|
|
|
+ writePixel(x0 - x, y0 + y, color);
|
|
|
|
|
+ writePixel(x0 + x, y0 - y, color);
|
|
|
|
|
+ writePixel(x0 - x, y0 - y, color);
|
|
|
|
|
+ y--;
|
|
|
|
|
+ if (decision > 0) {
|
|
|
|
|
+ decision += rw2 - (twoRw2 * y);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ decision += rw2 + (twoRh2 * x) - (twoRw2 * y);
|
|
|
|
|
+ x++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ endWrite();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**************************************************************************/
|
|
|
|
|
+/*!
|
|
|
|
|
+ @brief Draw an ellipse with filled colour
|
|
|
|
|
+ @param x0 Center-point x coordinate
|
|
|
|
|
+ @param y0 Center-point y coordinate
|
|
|
|
|
+ @param rw Horizontal radius of ellipse
|
|
|
|
|
+ @param rh Vertical radius of ellipse
|
|
|
|
|
+ @param color 16-bit 5-6-5 Color to draw with
|
|
|
|
|
+*/
|
|
|
|
|
+/**************************************************************************/
|
|
|
|
|
+void Adafruit_GFX::fillEllipse(int16_t x0, int16_t y0, int16_t rw, int16_t rh,
|
|
|
|
|
+ uint16_t color) {
|
|
|
|
|
+#if defined(ESP8266)
|
|
|
|
|
+ yield();
|
|
|
|
|
+#endif
|
|
|
|
|
+ // Bresenham's ellipse algorithm
|
|
|
|
|
+ int16_t x = 0, y = rh;
|
|
|
|
|
+ int32_t rw2 = rw * rw, rh2 = rh * rh;
|
|
|
|
|
+ int32_t twoRw2 = 2 * rw2, twoRh2 = 2 * rh2;
|
|
|
|
|
+
|
|
|
|
|
+ int32_t decision = rh2 - (rw2 * rh) + (rw2 / 4);
|
|
|
|
|
+
|
|
|
|
|
+ startWrite();
|
|
|
|
|
+
|
|
|
|
|
+ // region 1
|
|
|
|
|
+ while ((twoRh2 * x) < (twoRw2 * y)) {
|
|
|
|
|
+ drawFastHLine(x0 - x, y0 + y, 2 * x + 1, color);
|
|
|
|
|
+ drawFastHLine(x0 - x, y0 - y, 2 * x + 1, color);
|
|
|
|
|
+
|
|
|
|
|
+ x++;
|
|
|
|
|
+ if (decision < 0) {
|
|
|
|
|
+ decision += rh2 + (twoRh2 * x);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ decision += rh2 + (twoRh2 * x) - (twoRw2 * y);
|
|
|
|
|
+ y--;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // region 2
|
|
|
|
|
+ decision = ((rh2 * (2 * x + 1) * (2 * x + 1)) >> 2) +
|
|
|
|
|
+ (rw2 * (y - 1) * (y - 1)) - (rw2 * rh2);
|
|
|
|
|
+ while (y >= 0) {
|
|
|
|
|
+ drawFastHLine(x0 - x, y0 + y, 2 * x + 1, color);
|
|
|
|
|
+ drawFastHLine(x0 - x, y0 - y, 2 * x + 1, color);
|
|
|
|
|
+
|
|
|
|
|
+ y--;
|
|
|
|
|
+ if (decision > 0) {
|
|
|
|
|
+ decision += rw2 - (twoRw2 * y);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ decision += rw2 + (twoRh2 * x) - (twoRw2 * y);
|
|
|
|
|
+ x++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ endWrite();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/**************************************************************************/
|
|
/**************************************************************************/
|
|
|
/*!
|
|
/*!
|
|
|
@brief Draw a circle outline
|
|
@brief Draw a circle outline
|