@@ -345,6 +345,122 @@ void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
345
345
}
346
346
}
347
347
348
+ /* *************************************************************************/
349
+ /* !
350
+ @brief Draw an ellipse outline
351
+ @param x0 Center-point x coordinate
352
+ @param y0 Center-point y coordinate
353
+ @param rw Horizontal radius of ellipse
354
+ @param rh Vertical radius of ellipse
355
+ @param color 16-bit 5-6-5 Color to draw with
356
+ */
357
+ /* *************************************************************************/
358
+ void Adafruit_GFX::drawEllipse (int16_t x0, int16_t y0, int16_t rw, int16_t rh,
359
+ uint16_t color) {
360
+ #if defined(ESP8266)
361
+ yield ();
362
+ #endif
363
+ // Bresenham's ellipse algorithm
364
+ int16_t x = 0 , y = rh;
365
+ int32_t rw2 = rw * rw, rh2 = rh * rh;
366
+ int32_t twoRw2 = 2 * rw2, twoRh2 = 2 * rh2;
367
+
368
+ int32_t decision = rh2 - (rw2 * rh) + (rw2 / 4 );
369
+
370
+ startWrite ();
371
+
372
+ // region 1
373
+ while ((twoRh2 * x) < (twoRw2 * y)) {
374
+ writePixel (x0 + x, y0 + y, color);
375
+ writePixel (x0 - x, y0 + y, color);
376
+ writePixel (x0 + x, y0 - y, color);
377
+ writePixel (x0 - x, y0 - y, color);
378
+ x++;
379
+ if (decision < 0 ) {
380
+ decision += rh2 + (twoRh2 * x);
381
+ } else {
382
+ decision += rh2 + (twoRh2 * x) - (twoRw2 * y);
383
+ y--;
384
+ }
385
+ }
386
+
387
+ // region 2
388
+ decision = ((rh2 * (2 * x + 1 ) * (2 * x + 1 )) >> 2 ) +
389
+ (rw2 * (y - 1 ) * (y - 1 )) - (rw2 * rh2);
390
+ while (y >= 0 ) {
391
+ writePixel (x0 + x, y0 + y, color);
392
+ writePixel (x0 - x, y0 + y, color);
393
+ writePixel (x0 + x, y0 - y, color);
394
+ writePixel (x0 - x, y0 - y, color);
395
+ y--;
396
+ if (decision > 0 ) {
397
+ decision += rw2 - (twoRw2 * y);
398
+ } else {
399
+ decision += rw2 + (twoRh2 * x) - (twoRw2 * y);
400
+ x++;
401
+ }
402
+ }
403
+
404
+ endWrite ();
405
+ }
406
+
407
+ /* *************************************************************************/
408
+ /* !
409
+ @brief Draw an ellipse with filled colour
410
+ @param x0 Center-point x coordinate
411
+ @param y0 Center-point y coordinate
412
+ @param rw Horizontal radius of ellipse
413
+ @param rh Vertical radius of ellipse
414
+ @param color 16-bit 5-6-5 Color to draw with
415
+ */
416
+ /* *************************************************************************/
417
+ void Adafruit_GFX::fillEllipse (int16_t x0, int16_t y0, int16_t rw, int16_t rh,
418
+ uint16_t color) {
419
+ #if defined(ESP8266)
420
+ yield ();
421
+ #endif
422
+ // Bresenham's ellipse algorithm
423
+ int16_t x = 0 , y = rh;
424
+ int32_t rw2 = rw * rw, rh2 = rh * rh;
425
+ int32_t twoRw2 = 2 * rw2, twoRh2 = 2 * rh2;
426
+
427
+ int32_t decision = rh2 - (rw2 * rh) + (rw2 / 4 );
428
+
429
+ startWrite ();
430
+
431
+ // region 1
432
+ while ((twoRh2 * x) < (twoRw2 * y)) {
433
+ drawFastHLine (x0 - x, y0 + y, 2 * x + 1 , color);
434
+ drawFastHLine (x0 - x, y0 - y, 2 * x + 1 , color);
435
+
436
+ x++;
437
+ if (decision < 0 ) {
438
+ decision += rh2 + (twoRh2 * x);
439
+ } else {
440
+ decision += rh2 + (twoRh2 * x) - (twoRw2 * y);
441
+ y--;
442
+ }
443
+ }
444
+
445
+ // region 2
446
+ decision = ((rh2 * (2 * x + 1 ) * (2 * x + 1 )) >> 2 ) +
447
+ (rw2 * (y - 1 ) * (y - 1 )) - (rw2 * rh2);
448
+ while (y >= 0 ) {
449
+ drawFastHLine (x0 - x, y0 + y, 2 * x + 1 , color);
450
+ drawFastHLine (x0 - x, y0 - y, 2 * x + 1 , color);
451
+
452
+ y--;
453
+ if (decision > 0 ) {
454
+ decision += rw2 - (twoRw2 * y);
455
+ } else {
456
+ decision += rw2 + (twoRh2 * x) - (twoRw2 * y);
457
+ x++;
458
+ }
459
+ }
460
+
461
+ endWrite ();
462
+ }
463
+
348
464
/* *************************************************************************/
349
465
/* !
350
466
@brief Draw a circle outline
0 commit comments