Skip to content

Commit 70c352c

Browse files
Ellipse Function Added. Need to test.
1 parent 7c0ecdd commit 70c352c

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

keywords.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Font KEYWORD1
1010
Image KEYWORD1
1111

1212
##########################################
13-
# Methods and Functions
14-
##########################################
13+
# Methods and Functions
14+
##########################################
1515

1616
begin KEYWORD2
1717
end KEYWORD2
@@ -33,6 +33,7 @@ line KEYWORD2
3333
point KEYWORD2
3434
quad KEYWORD2
3535
rect KEYWORD2
36+
ellipse KEYWORD2
3637

3738
text KEYWORD2
3839
textFont KEYWORD2

src/ArduinoGraphics.cpp

+34-2
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,38 @@ void ArduinoGraphics::rect(int x, int y, int width, int height)
184184
}
185185
}
186186

187+
void ArduinoGraphics::ellipse(int x, int y, int width, int height)
188+
{
189+
if (!_stroke && !_fill) {
190+
return;
191+
}
192+
193+
int x1 = x;
194+
int y1 = y;
195+
int r1 = (width/2);
196+
int r2 = (height/2);
197+
int x2 = x1 + r1 - 1;
198+
199+
for(x = x1; x <= x2; x++) {
200+
y2 = y1 + sqrt((1 - ((x * x)/(r1 * r1)))) * r2;
201+
for(y = y1; y <= y2; y++) {
202+
if ((y == y2) && _stroke) {
203+
// stroke
204+
set(x, y, _strokeR, _strokeG, _strokeB); // current point
205+
set(x - (((x - x1) * 2)), y, _strokeR, _strokeG, _strokeB); // second reflection
206+
set(x, y - (((y - y1) * 2)), _strokeR, _strokeG, _strokeB); // third reflection
207+
set(x - (((x - x1) * 2)), y - (((y - y1) * 2)), _strokeR, _strokeG, _strokeB); // fourth reflection
208+
} else if (_fill) {
209+
// fill
210+
set(x, y, _fillR, _fillG, _fillB); // current point
211+
set(x - (((x - x1) * 2)), y, _fillR, _fillG, _fillB); // second reflection
212+
set(x, y - (((y - y1) * 2)), _fillR, _fillG, _fillB); // third reflection
213+
set(x - (((x - x1) * 2)), y - (((y - y1) * 2)), _fillR, _fillG, _fillB); // fourth reflection
214+
}
215+
}
216+
}
217+
}
218+
187219
void ArduinoGraphics::text(const char* str, int x, int y)
188220
{
189221
if (!_font || !_stroke) {
@@ -365,7 +397,7 @@ void ArduinoGraphics::beginText(int x, int y, uint8_t r, uint8_t g, uint8_t b)
365397

366398
_textR = r;
367399
_textG = g;
368-
_textB = b;
400+
_textB = b;
369401
}
370402

371403
void ArduinoGraphics::beginText(int x, int y, uint32_t color)
@@ -482,7 +514,7 @@ void ArduinoGraphics::lineHigh(int x1, int y1, int x2, int y2)
482514
xi = -1;
483515
dx = -dx;
484516
}
485-
517+
486518
int D = 2 * dx - dy;
487519
int x = x1;
488520

src/ArduinoGraphics.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ class ArduinoGraphics : public Print {
5858
void noStroke();
5959

6060
//virtual void arc(int x, int y, int width, int height, int start, int stop);
61-
//virtual void ellipse(int x, int y, int width, int height);
6261
virtual void line(int x1, int y1, int x2, int y2);
6362
virtual void point(int x, int y);
6463
//virtual void quad(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
6564
//virtual void triangle(int x1, int y1, int x2, int y2, int x3, int y3);
6665
virtual void rect(int x, int y, int width, int height);
66+
virtual void ellipse(int x, int y, int width, int height);
6767

6868
virtual void text(const char* str, int x = 0, int y = 0);
6969
virtual void text(const String& str, int x = 0, int y = 0) { text(str.c_str(), x, y); }

0 commit comments

Comments
 (0)