cairo_trial.py 文件源码

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

项目:pyphy-engine 作者: pulkitag 项目源码 文件源码
def paste_ball():
    bDef  = pm.BallDef()
    ball1 = pm.Ball.from_def(bDef, 'ball1', pm.Point(70,50))

    #Canvas Sz
    xCsz, yCsz = 640, 480
    #Create the base to paste it on
    data    = np.zeros((yCsz, xCsz, 4), dtype=np.uint8)
    surface = cairo.ImageSurface.create_for_data(data, 
                            cairo.FORMAT_ARGB32, xCsz, yCsz)
    cr      = cairo.Context(surface)
    cr.set_source_rgba(0.5, 0.5, 1.0, 1.0)
    cr.paint()

    #Create imSurface
    shp = ball1.data_.im.shape
    y, x  = ball1.pos_.y() - ball1.yOff_, ball1.pos_.x() - ball1.xOff_
    imDat    = np.zeros((yCsz, xCsz, 4), dtype=np.uint8)
    imDat[y:y+shp[0],x:x+shp[0],:] = ball1.data_.im[:] 
    surface = cairo.ImageSurface.create_for_data(imDat, 
                            cairo.FORMAT_ARGB32, xCsz, yCsz)
    cr.set_source_surface(surface)      
    #cr.set_source_rgb(1.0,0.0,0.0)     
    cr.rectangle(x, y, shp[0], shp[1])
    cr.fill()
    print y,x,shp[0],shp[1]
    return data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号