c64_painter.py 文件源码

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

项目:Pythonista-C64-Painter 作者: superrune 项目源码 文件源码
def draw_grid_image(self):
        (startPos, endPos) = self.get_current_region()

        yPixelScale = self.width/(endPos[0]-startPos[0]+1)/Settings.pixelSize #self.height/Settings.height
        xPixelScale = yPixelScale*2
        charSize = Settings.charSize
        charScale = yPixelScale*charSize
        xRangeStart = int(startPos[0]/charSize*charSize)

        pixelGrid = ui.Path.rect(0, 0, *self.frame[2:])
        characterGrid = ui.Path.rect(0, 0, *self.frame[2:])

        charDrawColor = (1,1,1,0.5) if self.darkGrid == False else (0,0,0,0.5)
        lineDrawColor = (0.5,0.5,0.5,0.5) if self.darkGrid == False else (0.25,0.25,0.25,0.5)

        with ui.ImageContext(*self.frame[2:]) as ctx:
            # Fills entire grid with empty color
            ui.set_color((0, 0, 0, 0))
            #pixelGrid.fill()
            pixelGrid.line_width = 1

            # Horizontal gridlines
            yEnd = 200 * yPixelScale
            for x in xrange(startPos[0]+1, endPos[0]+1):
                xPos = (x-startPos[0]) * xPixelScale
                if x%4 != 0:
                    pixelGrid.move_to(xPos,0)
                    pixelGrid.line_to(xPos,yEnd)
                else:
                    characterGrid.move_to(xPos,0)
                    characterGrid.line_to(xPos,yEnd)

            # Vertical gridlines
            xEnd = 160 * xPixelScale
            for y in xrange(startPos[1]+1, endPos[1]+1):
                yPos = (y-startPos[1]) * yPixelScale
                if y%8 != 0:
                    pixelGrid.move_to(0, yPos)
                    pixelGrid.line_to(xEnd, yPos)
                else:    
                    characterGrid.move_to(0, yPos)
                    characterGrid.line_to(xEnd, yPos)

            ui.set_color(lineDrawColor)
            pixelGrid.stroke()
            ui.set_color(charDrawColor)
            characterGrid.stroke()

            return ctx.get_image()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号