[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] unround circle!



Pete Shinners wrote on 2003-07-14:

> Beni Cherniavsky wrote:
> > I just downloaded the CVS snapshot__ and the WHATSNEW says "cleaned
> > fill circle draw" (on Jun 11, so this is clearly relates to your
> > message) but I still see the same behavior and diff of `src/draw.c`
> > vs. 1.5.5 doesn't show any difference at all in the `circle` function.
> > What do I miss?  Is the CVS snapshot not up-to-date perhaps?
> >
> > __ http://pygame.org/ftp/pygame-cvs.tar.gz
>
> this should be all taken care of in the latest release. pygame-1.5.6
> has the same updated circle draw as the cvs snapshot.
>
> i just doublechecked with the old 'circle magnified' code you had
> posted earlier. i added a feature to draw a rectangle around the area
> to be effected. the old rectangle has some problems to be sure. the
> new one seems much better.
>
> comparison
> http://pygame.org/ftp/contrib/circles.png
>
> code change diff
> http://cvs.seul.org/cgi-bin/cvsweb-1.80.cgi/games/pygame/src/draw.c.diff?r1=text&tr1=1.30&r2=text&tr2=1.31&f=h
>
Sorry, I didn't check carefully.  Indeed, it's better - it fits into a
scquare now.  However, the square is always of even size and therefore
is not centered on the center requested.  I can't get an odd size
since it doesn't respect float arguments (says they are deprecated and
silently rounds them).  Yet, a circle of radius 0 is drawed as a
precisely 1 pixel.  And a circle of radius 1 is still a 4x2 block.
Here is my new code, with your rectangle idea but also drawing the
center:

import pygame
from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((640, 480))

try:
    s = pygame.Surface((32, 24))
    size = 0
    def redraw():
        s.fill([255]*3)
        CENTER = 16, 12
        rect = Rect((CENTER, (0, 0))).inflate(size*2, size*2)
        pygame.draw.rect(s, (0, 255, 0), rect, 1)
        pygame.draw.circle(s, (0, 0, 255), CENTER, size)
        s.set_at(CENTER, (255, 0, 0))
        screen.blit(pygame.transform.scale(s, screen.get_size()),
                    (0, 0))
        pygame.display.update()
    redraw()
    for ev in iter(pygame.event.wait, None):
        if ev.type == QUIT:
            break
        elif ev.type == KEYDOWN and ev.unicode == '+':
            size += 1
        elif ev.type == KEYDOWN and ev.unicode == '-':
            if size > 0:
                size -= 1
        else:
            continue
        redraw()
finally:
    pygame.quit()




-- 
Beni Cherniavsky <cben@tx.technion.ac.il>

If I don't hack on it, who will?  And if I don't GPL it, what am I?
And if it itches, why not now?  [With apologies to Hilel ;]