Skip to content

ellipse and circle implementation #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ noFill KEYWORD2
stroke KEYWORD2
noStroke KEYWORD2

ellipse KEYWORD2
circle KEYWORD2
line KEYWORD2
point KEYWORD2
quad KEYWORD2
Expand Down
45 changes: 45 additions & 0 deletions src/ArduinoGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,51 @@ void ArduinoGraphics::noStroke()
_stroke = false;
}

void ArduinoGraphics::ellipse(int x, int y, int width, int height)
{
if (!_stroke && !_fill) {
return;
}

float theta;
int r1 = width / 2;
int r2 = height / 2;
for (int angle = 0; angle < 360; angle += 1) {
theta = angle * 3.14 / 180;
int xi = r1 * cos(theta);
int yi = r2 * sin(theta);
if (_stroke) {
// stroke
set(x + xi, y - yi, _strokeR, _strokeG, _strokeB);
} else if (_fill) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are treating fill as an alternative stroke. The fill should fill the inside of the ellipse, so it needs to be done in addition to the stroke.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry still not fixed. I notice another bug with fill.
I am trying to solve it.

// fill
set(x + xi, y - yi, _fillR, _fillG, _fillB);
}
}
}

void ArduinoGraphics::circle(int x, int y, int radius)
{
//ellipse(x, y, 2 * radius, 2 * radius);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you decide not to functionalize the shared code? I see from this comment that you started out to do that at one point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for reducing the number of function calling.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave that choice up to you and whoever does the final review on this, but I would request that you remove the commented out code, since it doesn't serve any purpose.

if (!_stroke && !_fill) {
return;
}

float theta;
for (int angle = 0; angle < 360; angle += 1) {
theta = angle * 3.14 / 180;
int xi = radius * cos(theta);
int yi = radius * sin(theta);
if (_stroke) {
// stroke
set(x + xi, y - yi, _strokeR, _strokeG, _strokeB);
} else if (_fill) {
// fill
set(x + xi, y - yi, _fillR, _fillG, _fillB);
}
}
}

void ArduinoGraphics::line(int x1, int y1, int x2, int y2)
{
if (!_stroke) {
Expand Down
3 changes: 2 additions & 1 deletion src/ArduinoGraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class ArduinoGraphics : public Print {
void noStroke();

//virtual void arc(int x, int y, int width, int height, int start, int stop);
//virtual void ellipse(int x, int y, int width, int height);
virtual void ellipse(int x, int y, int width, int height);
virtual void circle(int x, int y, int radius);
virtual void line(int x1, int y1, int x2, int y2);
virtual void point(int x, int y);
//virtual void quad(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
Expand Down