Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of RA8875 by
Diff: SPI_TFT.cpp
- Revision:
- 18:52cbeede86f0
- Parent:
- 16:2efcbb2814fa
--- a/SPI_TFT.cpp Mon Mar 25 10:11:00 2013 +0000
+++ b/SPI_TFT.cpp Tue Oct 22 20:17:29 2013 +0000
@@ -24,6 +24,7 @@
// 03.02.13 add a switch to switch off DMA use for LPC11U24
// 04.03.13 add support for new Kinetis board
// 25.03.13 fix Bug in bitmap for Kinetis board
+// 18.10.13 Better Circle function from Michael Ammann
#include "SPI_TFT.h"
#include "mbed.h"
@@ -450,120 +451,37 @@
_cs = 1;
}
-// draw circle
void SPI_TFT::circle(int x0, int y0, int r, int color)
+{
+ int x = -r, y = 0, err = 2-2*r, e2;
+ do {
+ pixel(x0-x, y0+y,color);
+ pixel(x0+x, y0+y,color);
+ pixel(x0+x, y0-y,color);
+ pixel(x0-x, y0-y,color);
+ e2 = err;
+ if (e2 <= y) {
+ err += ++y*2+1;
+ if (-x == y && e2 <= x) e2 = 0;
+ }
+ if (e2 > x) err += ++x*2+1;
+ } while (x <= 0);
+
+}
+
+void SPI_TFT::fillcircle(int x0, int y0, int r, int color)
{
-
- int draw_x0, draw_y0;
- int draw_x1, draw_y1;
- int draw_x2, draw_y2;
- int draw_x3, draw_y3;
- int draw_x4, draw_y4;
- int draw_x5, draw_y5;
- int draw_x6, draw_y6;
- int draw_x7, draw_y7;
- int xx, yy;
- int di;
- //WindowMax();
- if (r == 0) { /* no radius */
- return;
- }
-
- draw_x0 = draw_x1 = x0;
- draw_y0 = draw_y1 = y0 + r;
- if (draw_y0 < height()) {
- pixel(draw_x0, draw_y0, color); /* 90 degree */
- }
-
- draw_x2 = draw_x3 = x0;
- draw_y2 = draw_y3 = y0 - r;
- if (draw_y2 >= 0) {
- pixel(draw_x2, draw_y2, color); /* 270 degree */
- }
-
- draw_x4 = draw_x6 = x0 + r;
- draw_y4 = draw_y6 = y0;
- if (draw_x4 < width()) {
- pixel(draw_x4, draw_y4, color); /* 0 degree */
- }
-
- draw_x5 = draw_x7 = x0 - r;
- draw_y5 = draw_y7 = y0;
- if (draw_x5>=0) {
- pixel(draw_x5, draw_y5, color); /* 180 degree */
- }
-
- if (r == 1) {
- return;
- }
-
- di = 3 - 2*r;
- xx = 0;
- yy = r;
- while (xx < yy) {
-
- if (di < 0) {
- di += 4*xx + 6;
- } else {
- di += 4*(xx - yy) + 10;
- yy--;
- draw_y0--;
- draw_y1--;
- draw_y2++;
- draw_y3++;
- draw_x4--;
- draw_x5++;
- draw_x6--;
- draw_x7++;
+ int x = -r, y = 0, err = 2-2*r, e2;
+ do {
+ vline(x0-x, y0-y, y0+y, color);
+ vline(x0+x, y0-y, y0+y, color);
+ e2 = err;
+ if (e2 <= y) {
+ err += ++y*2+1;
+ if (-x == y && e2 <= x) e2 = 0;
}
- xx++;
- draw_x0++;
- draw_x1--;
- draw_x2++;
- draw_x3--;
- draw_y4++;
- draw_y5++;
- draw_y6--;
- draw_y7--;
-
- if ( (draw_x0 <= width()) && (draw_y0>=0) ) {
- pixel(draw_x0, draw_y0, color);
- }
-
- if ( (draw_x1 >= 0) && (draw_y1 >= 0) ) {
- pixel(draw_x1, draw_y1, color);
- }
-
- if ( (draw_x2 <= width()) && (draw_y2 <= height()) ) {
- pixel(draw_x2, draw_y2, color);
- }
-
- if ( (draw_x3 >=0 ) && (draw_y3 <= height()) ) {
- pixel(draw_x3, draw_y3, color);
- }
-
- if ( (draw_x4 <= width()) && (draw_y4 >= 0) ) {
- pixel(draw_x4, draw_y4, color);
- }
-
- if ( (draw_x5 >= 0) && (draw_y5 >= 0) ) {
- pixel(draw_x5, draw_y5, color);
- }
- if ( (draw_x6 <=width()) && (draw_y6 <= height()) ) {
- pixel(draw_x6, draw_y6, color);
- }
- if ( (draw_x7 >= 0) && (draw_y7 <= height()) ) {
- pixel(draw_x7, draw_y7, color);
- }
- }
- return;
-}
-
-void SPI_TFT::fillcircle(int x, int y, int r, int color)
-{
- int i;
- for (i = 0; i <= r; i++)
- circle(x,y,i,color);
+ if (e2 > x) err += ++x*2+1;
+ } while (x <= 0);
}
