pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
AAfilledRoundedRect

AAfilledRoundedRect - 1

josmiley (josmiley)

Tags:

Description

a func to draw antialiased rounded filled rectangles

from pygame import *

def AAfilledRoundedRect(surface,rect,color,radius=0.4):

"""
AAfilledRoundedRect(surface,rect,color,radius=0.4)

surface : destination
rect : rectangle
color : rgb or rgba
radius : 0 <= radius <= 1
"""

rect = Rect(rect)
color = Color(*color)
alpha = color.a
color.a = 0
pos = rect.topleft
rect.topleft = 0,0
rectangle = Surface(rect.size,SRCALPHA)

circle = Surface([min(rect.size)*3]*2,SRCALPHA)
draw.ellipse(circle,(0,0,0),circle.get_rect(),0)
circle = transform.smoothscale(circle,[int(min(rect.size)*radius)]*2)

radius = rectangle.blit(circle,(0,0))
radius.bottomright = rect.bottomright
rectangle.blit(circle,radius)
radius.topright = rect.topright
rectangle.blit(circle,radius)
radius.bottomleft = rect.bottomleft
rectangle.blit(circle,radius)

rectangle.fill((0,0,0),rect.inflate(-radius.w,0))
rectangle.fill((0,0,0),rect.inflate(0,-radius.h))

rectangle.fill(color,special_flags=BLEND_RGBA_MAX)
rectangle.fill((255,255,255,alpha),special_flags=BLEND_RGBA_MIN)

return surface.blit(rectangle,pos)

if __name__ == "__main__":
scr = display.set_mode((300,300))
scr.fill(-1)
AAfilledRoundedRect(scr,(50,50,200,50),(200,20,20),0.5)
display.flip()
while event.wait().type != QUIT: pass



Links

Home Page: http://joel-murielle.perso.sfr.fr/AAfilledRoundedRect.py

Screenshot


click to view original size

Releases

AAfilledRoundedRect - 1 - May 30, 2012

Pygame.org account Comments

If you wish to leave a comment with your pygame.org account, please sign in first.

No user comments have been submitted.
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Apr 21, 2014


Apr 19, 2014

Apr 16, 2014

Apr 13, 2014

Apr 9, 2014

Mar 18, 2014


Mar 15, 2014


Mar 14, 2014

Mar 13, 2014

... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)