primitives.py 文件源码

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

项目:pyphy-engine 作者: pulkitag 项目源码 文件源码
def imprint(self, cr, xSz, ySz):
        #Get the position on the cnavas.
        ySt, xSt  = self.pos_.y_asint() - self.imSt_.y_asint(), self.pos_.x_asint() - self.imSt_.x_asint()
        yEn, xEn  = ySt + self.ySz_, xSt + self.xSz_
        #Get the data that can be pasted
        y1, x1 = np.abs(min(0, ySt)), np.abs(min(0, xSt))   
        y2     = self.ySz_ - np.abs(min(0, ySz - yEn)) 
        x2     = self.xSz_ - np.abs(min(0, xSz - xEn))
        #Correct for positions on canvas
        ySt, xSt = max(0, ySt), max(0, xSt)
        yEn, xEn = min(ySz, yEn), min(xSz, xEn)

        srcIm = np.zeros((ySz, xSz, 4), dtype=np.uint8)
        srcIm[ySt:yEn, xSt:xEn,:] = self.data_.im[y1:y2, x1:x2] 
        surface = cairo.ImageSurface.create_for_data(srcIm, 
                                cairo.FORMAT_ARGB32, xSz,ySz)
        cr.set_source_surface(surface)      
        cr.rectangle(xSt, ySt, x2 - x1, y2 - y1)
        cr.fill()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号