ThingPulse / esp8266-oled-ssd1306

Driver for the SSD1306 and SH1106 based 128x64, 128x32, 64x48 pixel OLED display running on ESP8266/ESP32
https://thingpulse.com
Other
2.03k stars 643 forks source link

Circles look weird #278

Closed NoobTracker closed 4 years ago

NoobTracker commented 4 years ago

Hello!

I have a problem with fillCircle(). It looks like the circles are a pixel higher then wide. I don't have problems with drawCircle(). My code:

#include <Wire.h>
#include "SH1106Wire.h" 

SH1106Wire display(0x3c, SDA, SCL);

void setup() {
  display.init();
  display.flipScreenVertically();
}
void loop(){
  display.clear();
  display.setColor(WHITE);
  display.drawCircle(60, 28, 4);
  display.drawCircle(70, 28, 3);
  display.fillCircle(60, 38, 4);
  display.fillCircle(70, 38, 3);
  display.display();
}

You can see the result in the attached image.

IMG_0049

marcelstoer commented 4 years ago

Maybe fillCircle() is plagues by the same issues @DaveSprague fixed in #197 for drawCircle().

NoobTracker commented 4 years ago

No, I had another problem. And I fixed it. I changed

void OLEDDisplay::fillCircle(int16_t x0, int16_t y0, int16_t radius) {
  int16_t x = 0, y = radius;
    int16_t dp = 1 - radius;
    do {
        if (dp < 0)
      dp = dp + (x++) * 2 + 3;
    else
      dp = dp + (x++) * 2 - (y--) * 2 + 5;

    drawHorizontalLine(x0 - x, y0 - y, 2*x);
    drawHorizontalLine(x0 - x, y0 + y, 2*x);
    drawHorizontalLine(x0 - y, y0 - x, 2*y);
    drawHorizontalLine(x0 - y, y0 + x, 2*y);

    } while (x < y);
  drawHorizontalLine(x0 - radius, y0, 2 * radius);

}

to

void OLEDDisplay::fillCircle(int16_t x0, int16_t y0, int16_t radius) {
  int16_t x = 0, y = radius;
    int16_t dp = 1 - radius;
    do {
        if (dp < 0)
      dp = dp + (x++) * 2 + 3;
    else
      dp = dp + (x++) * 2 - (y--) * 2 + 5;

    drawHorizontalLine(x0 - x, y0 - y, 2*x + 1);
    drawHorizontalLine(x0 - x, y0 + y, 2*x + 1);
    drawHorizontalLine(x0 - y, y0 - x, 2*y + 1);
    drawHorizontalLine(x0 - y, y0 + x, 2*y + 1);

    } while (x < y);
  drawHorizontalLine(x0 - radius, y0, (2 * radius) + 1);  
  drawVerticalLine(x0, y0 - radius, 2 * radius);
}

I'm not sure, but I think that the problem was caused by horizontalLine(). I guess this should be implemented in a future bugfix. Now it looks much better.

IMG_0050

NoobTracker commented 4 years ago

Hopefully this will be fixed in an update soon, because I want to use this lib in a game and don't want to tell the people "Please delete line x to y and insert this:". I would also like to see fillCircleQuads(). Otherwise it's a great lib.

marcelstoer commented 4 years ago

By far the quickest way to get issues resolved is through pull requests.

NoobTracker commented 4 years ago

I haven't figured out how these pull requests work. I'm new to GitHub and my english is not the best.

marcelstoer commented 4 years ago

Fear not - there's a first time for everything, we've all been there 😄 Finding your way around GitHub and knowing how to create PRs is a powerful tool in your developer toolbox. And very satisfactory, too!

Can I encourage you maybe start with this video https://youtu.be/For9VtrQx58 or our own guidelines?

NoobTracker commented 4 years ago

That's really interesting! Thank you!

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.