c64_painter.py 文件源码

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

项目:Pythonista-C64-Painter 作者: superrune 项目源码 文件源码
def character_colorcheck(self):
        (startPos, endPos) = self.get_current_region()
        charSize = Settings.charSize
        clashCount = 0
        pixelScale =  self.width/(endPos[0]-startPos[0]+1)/Settings.pixelSize #self.height/Settings.height
        #s = self.width/self.row if self.row > self.column else self.height/self.column
        with ui.ImageContext(self.width, self.height) as ctx:
            ui.set_color('red')
            # Grid line per character
            for y in xrange(int(startPos[1]/charSize)*charSize, endPos[1]+1, charSize):
                for x in xrange(int(startPos[0]/charSize*charSize), endPos[0]+1,4):
                    # Check this character for color clash
                    charColors ={(self.background_color[0], self.background_color[1], self.background_color[2])}
                    startIndex = xy_to_index(x,y)
                    for pixelRow in range(0, 8):
                        for pixelCol in range(0, 4):
                            pixelIndex = startIndex + pixelRow*Settings.actualWidth + pixelCol
                            charColors.add((self.pixels[pixelIndex].color[0], self.pixels[pixelIndex].color[1], self.pixels[pixelIndex].color[2]))
                    if len(charColors) > 4:
                        clashCount = clashCount + 1
                        pixel_path = ui.Path.rect((x-startPos[0])*pixelScale*2, (y-startPos[1])*pixelScale, pixelScale*charSize, pixelScale*charSize)
                        pixel_path.line_width = 2
                        pixel_path.stroke()
                        self.color_check.image = ctx.get_image()
        if clashCount == 0:
            self.color_check.image = self.create_new_image() # Clear clash image
        self.superview['debugtext'].text = str(clashCount) + " characters have color clashes."
        return clashCount

    #@ui.in_background
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号