Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Adafruit_GFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ POSSIBILITY OF SUCH DAMAGE.

#include "Adafruit_GFX.h"
#include "glcdfont.c"
#include <math.h>
#define PI 3.1415926
#ifdef __AVR__
#include <avr/pgmspace.h>
#elif defined(ESP8266) || defined(ESP32)
Expand Down Expand Up @@ -368,6 +370,47 @@ void Adafruit_GFX::fillRoundRect(int16_t x, int16_t y, int16_t w,
endWrite();
}

// Draw a Pentagram
void Adafruit_GFX::drawPentagram(int16_t x0, int16_t y0,
int16_t r0, uint16_t color) {
int xa, ya;
int xb, yb;
int xc, yc;
int xd, yd;
int xe, ye;
xa = x0;
ya = y0 - r0;
xb = x0 - r0 * sin(PI / 180 * 72);
yb = y0 + r0 * -(cos(PI / 180 * 72));
xc = x0 - r0 * -(sin(PI / 180 * 36));
yc = y0 - r0 * -(cos(PI / 180 * 36));
xd = x0 + r0 * -(sin(PI / 180 * 36));
yd = y0 - r0 * -(cos(PI / 180 * 36));
xe = x0 + r0 * sin(PI / 180 * 72);
ye = y0 + r0 * -(cos(PI / 180 * 72));
drawLine(xa, ya, xc, yc, color);
drawLine(xa, ya, xd, yd, color);
drawLine(xb, yb, xc, yc, color);
drawLine(xb, yb, xe, ye, color);
drawLine(xd, yd, xe, ye, color);
}

// Draw a ellipse outline
void Adafruit_GFX::drawEllipse(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t a, uint16_t color) {
int16_t max_x = ((x1 > x2 ? x1 : x2) + a > 128 ? (x1 > x2 ? x1 : x2) + a : 128);
int16_t max_y = ((y1 > y2 ? y1 : y2) + a > 64 ? (y1 > y2 ? y1 : y2) + a : 64);
for (int16_t x = ((x1 > x2 ? x2 : x1) - a > 0 ? (x1 > x2 ? x2 : x1) - a : 0 ); x <= max_x; x++) {
for (int16_t y = ((y1 > y2 ? y2 : y1) - a > 0 ? (y1 > y2 ? y2 : y1) - a : 0); y <= max_y; y++) {
int32_t distance = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)) + sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));
if (distance-a == a) {
writePixel(x, y, color);
}
}
}
endWrite();
}


// Draw a triangle
void Adafruit_GFX::drawTriangle(int16_t x0, int16_t y0,
int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color) {
Expand Down Expand Up @@ -1346,3 +1389,4 @@ void GFXcanvas16::fillScreen(uint16_t color) {
}
}


4 changes: 3 additions & 1 deletion Adafruit_GFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class Adafruit_GFX : public Print {
// Optional and probably not necessary to change
drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);

// These exist only with Adafruit_GFX (no subclass overrides)
void
drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
Expand All @@ -56,6 +55,8 @@ class Adafruit_GFX : public Print {
fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
int16_t delta, uint16_t color),
drawPentagram(int16_t x0, int16_t y0, int16_t r0, uint16_t color),
drawEllipse(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t a, uint16_t color),
drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
int16_t x2, int16_t y2, uint16_t color),
fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
Expand Down Expand Up @@ -209,3 +210,4 @@ class GFXcanvas16 : public Adafruit_GFX {
};

#endif // _ADAFRUIT_GFX_H