Skip to content
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

pygame.draw.circle with a thickness had a weird moiré pattern. #389

Merged
merged 1 commit into from Feb 17, 2018

Conversation

Projects
None yet
2 participants
@illume
Copy link
Member

illume commented Feb 9, 2018

For #388
circles with width draw nicely now.

Here is a test script to see the patterns. You can set thickness to 2 as well for another good test.
circle.py

Before:
screen shot 2018-02-10 at 00 53 30

After:
screen shot 2018-02-10 at 00 34 24

#circle.py
import pygame

def draw_outlined_circle2(surf, color, origin, radius, thickness):
    width = radius * 2 + thickness * 2
    background = (0, 0, 0, 0)
    circle = pygame.Surface((width, width)).convert_alpha()
    rect = circle.get_rect()
    circle.fill(background)
    pygame.draw.circle(circle, color, rect.center, radius)
    pygame.draw.circle(circle, background, rect.center, radius - thickness)
    surf.blit(circle, (origin[0] - (rect.w / 2), origin[1] - (rect.w / 2)))

def draw_outlined_circle0(surf, color, origin, radius, thickness):
    pygame.draw.circle(surf, color, origin, radius)
    pygame.draw.circle(surf, (0, 0, 0, 255), origin, radius - thickness)

surf = pygame.Surface((2000,2000))
radius = 508
thickness = 50
draw_with_pygame = True


pygame.init()
screen = pygame.display.set_mode((1024, 768))
pygame.display.set_caption('space - toggle draw with pygame(red), escape - quit')
pygame.display.flip()

pygame.draw.circle(surf, pygame.Color("red"), (500, 500), radius, thickness)

screen.blit(surf, (0,0))
pygame.display.flip()
going = True

while going:
    events = pygame.event.get()
    for e in events:
        if (e.type == pygame.QUIT or
           (e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE)):
            going = False
        if e.type == pygame.KEYDOWN and e.key == pygame.K_SPACE:
            draw_with_pygame = not draw_with_pygame
            if draw_with_pygame:
                pygame.draw.circle(surf, pygame.Color("red"), (500, 500), radius, thickness)
            else:
                draw_outlined_circle2(surf, pygame.Color("white"), (750, 750), radius, thickness)
            screen.blit(surf, (0,0))
            color_name = 'red' if draw_with_pygame else 'white'
            msg = 'space - toggle draw with pygame(%s):%s, escape - quit' % (color_name, draw_with_pygame)
            pygame.display.set_caption(msg)
            pygame.display.flip()

@illume illume force-pushed the moiré-pattern branch 2 times, most recently from cf4c3e7 to 2f2c850 Feb 9, 2018

src/draw.c Outdated
draw_ellipse(surf, posx, posy, radius-loop, radius-loop, color);
/* To avoid moiré pattern. Don't do an extra one on the outter ellipse.

This comment has been minimized.

@mrjbq7

mrjbq7 Feb 15, 2018

s/outter/outer

src/draw.c Outdated
draw_ellipse(surf, posx, posy, radius-loop, radius-loop, color);
/* To avoid moiré pattern. Don't do an extra one on the outter ellipse.
We draw another elipse offset by a pixel, over drawing the missed

This comment has been minimized.

@mrjbq7

mrjbq7 Feb 15, 2018

s/elipse/ellipse

@illume illume force-pushed the moiré-pattern branch from 2f2c850 to cef7cde Feb 15, 2018

@illume

This comment has been minimized.

Copy link
Member Author

illume commented Feb 15, 2018

Oops. Thanks @mrjbq7

@illume illume merged commit 120daa4 into master Feb 17, 2018

2 of 4 checks passed

continuous-integration/appveyor/branch AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build failed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@illume illume deleted the moiré-pattern branch Feb 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.