 # Glossy buttons

Dear folks,

I wrote an ad-hoc script to generate buttons that have the ‘glossy’ effect. The implementation is fairly straightforward and did work – the buttons themselves are rectangles with rounded corners so I call a polygon patch. The light is simulated using a white, transparent ellipse. But there is one problem though, the ellipse would mask anything that’s above the buttons as well.

Any people interested to take a look and suggest a solution?

Haibao

···

from pylab import *

from matplotlib.patches import *

fig = figure(1,(8,8))

def plot_cap(center, t, r):
x, y = center
return zip(x+rcos(t), y+rsin(t))

def round_rect(ax, xy, width, height, shrink=.33, label=None, **kwargs):

``````shrink *= height
x,y=xy
pts = []
# plot the four rounded cap one by one
pts += plot_cap((x+width-shrink, y+height-shrink), array([radians(j) for j in range(0,90)]), shrink)
pts += [[x+width-shrink, y+height], [x+shrink, y+height]]

pts += plot_cap((x+shrink, y+height-shrink), array([radians(j) for j in range(90,180)]), shrink)
pts += [[x, y+height-shrink], [x, y+shrink]]
pts += plot_cap((x+shrink, y+shrink), array([radians(j) for j in range(180,270)]), shrink)

pts += [[x+shrink, y], [x+width-shrink, y]]
pts += plot_cap((x+width-shrink, y+shrink), array([radians(j) for j in range(270,360)]), shrink)
pts += [[x+width, y+shrink], [x+width, y+height-shrink]]

# add a white transparency ellipse filter
# CAUTION -- things immediately above the button will be masked too!!!

if label: root.text(x+width/2.,y+height/2.,label,size=10,horizontalalignment="center",verticalalignment="center",color="w")
``````

round_rect(root,(.45,.4),.1,.04,label=“Button”,lw=0,fc=‘k’)