def get_ball_im(radius=40, fColor=Color(0.0, 0.0, 1.0), sThick=2, sColor=None):
'''
fColor: fill color
sColor: stroke color
sThick: stroke thickness
'''
sz = 2*(radius + sThick)
data = np.zeros((sz, sz, 4), dtype=np.uint8)
surface = cairo.ImageSurface.create_for_data(data,
cairo.FORMAT_ARGB32, sz, sz)
cr = cairo.Context(surface)
#Create a transparent source
cr.set_source_rgba(1.0, 1.0, 1.0, 0.0)
cr.paint()
#Create the border
cx, cy = radius + sThick, radius + sThick
cr.arc(cx, cy, radius, 0, 2*math.pi)
cr.set_line_width(sThick)
if sColor is not None:
cr.set_source_rgba(sColor.b, sColor.g, sColor.r, sColor.a)
else:
cr.set_source_rgba(0.0, 0.0, 0.0, 1.0)
cr.stroke()
#Fill in the desired color
cr.set_source_rgba(fColor.b, fColor.g, fColor.r, fColor.a)
cr.arc(cx, cy, radius, 0, 2*math.pi)
cr.fill()
#cr.destroy()
return cr, data
评论列表
文章目录