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

[pygame] Re: rendering anti-alias in argument color with transparency



On Aug 26, 6:34 am, René Dudfield <ren...@xxxxxxxxx> wrote:
[snip]
> > I'd like to know if anti-aliased objects, in particular the edges of
> > lines and fonts, can be rendered using transparency instead of
> > directly blended colors.  Specifically, can the function calls draw 4-
> > tuples of ( r, g, b ) specified in the arguments, plus + ( a,  ), the
> > proportion of intensity determined by the drawing algorithm?
>
> > The trick can of course be accomplished with 'numpy', the numerics
> > package, but it is a heavyweight solution, in particular complicated
> > and distracting, where programmer time is scarce; and slower, where
> > run-time environment CPU time is scarce.
>
> Hey,
>
> have you tried out the gfxdraw package?  That's got some antialiased drawing
> functions.

Hi, thanks for the fast reply.

Yes, the 'bezier_motion' screenshot used the bezier method in
gfxdraw.  I wouldn't mind seeing a filled pie, though.  I used an
approximation to accomplish it.

http://home.comcast.net/~castironpi-misc/draggable_pie.1311632054.png

Regarding the anti-aliasing, I ran this code:

>>> import pygame
>>> pygame.init( )
(6, 0)
>>> scr= pygame.display.set_mode(( 640,480 ) )
>>> surf= pygame.Surface((400,400)).convert_alpha( )
>>> import pygame.gfxdraw
>>> pygame.draw.aaline(surf,(0,255,0),(50,100),(150,350))
<rect(50, 100, 102, 252)>
>>> pygame.gfxdraw.aacircle(surf,200,250,50,(0,0,255))
>>> surf.get_at((52,103)) # on the line
(0, 102, 0, 0)
>>> surf.get_at((194,200)) # on the circle
(0, 0, 162, 103)
>>> surf.get_at((109,247)) # on the line
(0, 254, 0, 0)

# part 2, continued
>>> surf.fill((0,0,0,0))
<rect(0, 0, 400, 400)>
>>> pygame.draw.aaline(surf,(0,255,0,255),(50,100),(150,350))
<rect(50, 100, 102, 252)>
>>> pygame.gfxdraw.aacircle(surf,200,250,50,(0,0,255,255))
>>> surf.get_at((52,103))
(0, 102, 0, 102)
>>> surf.get_at((194,200))
(0, 0, 162, 103)
>>> surf.get_at((109,247))
(0, 254, 0, 254)

As you can see, I tried both length-3 and length-4 tuples for the
color argument.  In these examples, the results I want would be:

>>> surf.get_at((52,103))
(0, 255, 0, 102)
>>> surf.get_at((194,200))
(0, 0, 255, 103) # or (0, 0, 255, 162), unclear
>>> surf.get_at((109,247))
(0, 255, 0, 254)

Does this help to clarify?