primitives.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:pyphy-engine 作者: pulkitag 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号