-
Notifications
You must be signed in to change notification settings - Fork 22
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test sketch:
#include <ArduinoGraphics.h>
const byte canvasWidth = 11;
const byte canvasHeight = 11;
class ASCIIDrawClass : public ArduinoGraphics {
public:
ASCIIDrawClass() : ArduinoGraphics(canvasWidth, canvasHeight) {}
virtual void set(int x, int y, uint8_t r, uint8_t g, uint8_t b) {
// the r parameter is (mis)used to set the character to draw with
_canvasBuffer[x][y] = r;
(void)g;
(void)b;
}
// display the drawing
void endDraw() {
ArduinoGraphics::endDraw();
for (byte row = 0; row < canvasHeight; row++) {
for (byte column = 0; column < canvasWidth; column++) {
// handle unset parts of buffer
if (_canvasBuffer[column][row] == 0) {
_canvasBuffer[column][row] = ' ';
}
Serial.print(_canvasBuffer[column][row]);
}
Serial.println();
}
}
private:
char _canvasBuffer[canvasWidth][canvasHeight] = {0};
};
ASCIIDrawClass ASCIIDraw;
void setup() {
Serial.begin(9600);
while (!Serial);
ASCIIDraw.beginDraw();
ASCIIDraw.background('X', 0, 0);
ASCIIDraw.clear();
ASCIIDraw.stroke('*', 0, 0);
ASCIIDraw.fill('O', 0, 0);
ASCIIDraw.ellipse(5, 5, 10, 10);
ASCIIDraw.endDraw();
}
void loop() {}
gives this output:
XXXXXXXXXXX
XXX*****XXX
XX*XXXXX*XX
X*XXXXXXX*X
X*XXXXXXX*X
X*XXXXXXX**
X*XXXXXXX*X
X*XXXXXXX*X
XX*XXXXX*XX
XXX*****XXX
XXXXXXXXXXX
Three problems:
- There is an extra "pixel" set at position (10, 5).
- Ignoring the extra "pixel", the ellipse is 9x9, not 10x10.
- No fill.
|
||
void ArduinoGraphics::circle(int x, int y, int radius) | ||
{ | ||
//ellipse(x, y, 2 * radius, 2 * radius); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/ArduinoGraphics.cpp
Outdated
if (_stroke) { | ||
// stroke | ||
set(x + xi, y - yi, _strokeR, _strokeG, _strokeB); | ||
} else if (_fill) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
There was a problem hiding this comment.
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.
@per1234 |
@OmarAli3 I would expect something that looks approximately like this:
I might not have the shape of the circle quite right, but your code seems to do that well enough already. What I expect is a circle that:
|
After working on the problem :
So now I have two choices:
@per1234 , Do You suggest something? |
As far as I know, this library is currently only used by the Arduino_MKRRGB library (though I'm sure it will be used for many other applications soon). The Arduino MKR RGB shield is a 12x7 LED matrix, so it is actually less of a "real graphic display" in some ways than the Serial Monitor.
Because of the use with the MKR RGB Shield, I do think it's important to avoid this extra pixel. That will be very noticeable when it's an extra LED lit up. I have confirmed the issue also occurs with using the Arduino_MKRRGB library and the Arduino MKR RGB shield. |
|
Fixed by #30 |
No description provided.