【代码语法高亮】插件测试

def map(start,now,end,colorBar=None,colorComplete=(0,0,0,255),description=('Unknown','A',20),startMessage=('','A',20),nowMessage=('','A',20),endMessage=('','A',20),showPercentage=(True,1,'A',20)):
    img = Image.open('./templates/assets/map.png')
    barWidth = 400
    barHeight = 30
    
    if colorBar:
        for x in range(50,51+barWidth):
            for y in range(50,51+barHeight):
                currentPixel = img.getpixel((x,y))
                if (currentPixel[2] >=180):
                    img.putpixel((x,y),colorBar)


    #percentage 百分比
    #pixel 应绘制的像素值
    delta = now - start
    duration = end - start
    percentage = delta / duration
    
    if percentage>1:
        percentage=1
    
    pixelDelta = int(percentage * 396)
    
    pixelFrom = 50
    pixelTo = 51 + pixelDelta
    
    #绘制进度条
    if colorBar:
        for x in range(50,pixelTo):
            for y in range(50,51+barHeight):
                currentPixel = img.getpixel((x,y))
                if (currentPixel == colorBar):
                    img.putpixel((x,y),colorComplete)
    else:
        for x in range(50,pixelTo):
            for y in range(50,51+barHeight):
                currentPixel = img.getpixel((x,y))
                if (currentPixel[2] >=180):    
                    img.putpixel((x,y),colorComplete)
    
    #添加文字
    writeText(img,description[0],(250,20),align='center',font=description[1],size=description[2])
    writeText(img,startMessage[0],(50,90),align='left',font=startMessage[1],size=startMessage[2])
    writeText(img,nowMessage[0],(250,90),align='center',font=nowMessage[1],size=nowMessage[2])
    writeText(img,endMessage[0],(450,90),align='right',font=endMessage[1],size=endMessage[2])
    if showPercentage[0]:
        percentageMessage = str(round(percentage*100,2)) + '%'
    writeText(img,percentageMessage,(250,55),align='center',font=showPercentage[2],size=showPercentage[3])

    return img