Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Draw Circle and Ellipse #21

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
boo13 opened this issue Oct 8, 2019 · 1 comment · Fixed by #24
Closed

Draw Circle and Ellipse #21

boo13 opened this issue Oct 8, 2019 · 1 comment · Fixed by #24
Labels
enhancement New feature or request

Comments

@boo13
Copy link
Contributor

boo13 commented Oct 8, 2019

Please consider adding the ability to draw a circle and/or ellipse.

An existing Adafruit example -- Adafruit_CircuitPython_SSD1306 -- implements a draw_circle function that works for my case in the meantime.

# Helper function to draw a circle from a given position with a given radius
# This is an implementation of the midpoint circle algorithm,
# see https://en.wikipedia.org/wiki/Midpoint_circle_algorithm#C_example for details
def draw_circle(xpos0, ypos0, rad, col=1):
    x = rad - 1
    y = 0
    dx = 1
    dy = 1
    err = dx - (rad << 1)
    while x >= y:
        oled.pixel(xpos0 + x, ypos0 + y, col)
        oled.pixel(xpos0 + y, ypos0 + x, col)
        oled.pixel(xpos0 - y, ypos0 + x, col)
        oled.pixel(xpos0 - x, ypos0 + y, col)
        oled.pixel(xpos0 - x, ypos0 - y, col)
        oled.pixel(xpos0 - y, ypos0 - x, col)
        oled.pixel(xpos0 + y, ypos0 - x, col)
        oled.pixel(xpos0 + x, ypos0 - y, col)
        if err <= 0:
            y += 1
            err += dy
            dy += 2
        if err > 0:
            x -= 1
            dx += 2
            err += dx - (rad << 1)
@ladyada
Copy link
Member

ladyada commented Oct 8, 2019

hiya, a pull request would be welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants