其他分享
首页 > 其他分享> > mpy lcd 绘制圆

mpy lcd 绘制圆

作者:互联网

1.实心

def drawCirc_fill(tft,x,y,r,pen):
    ox =r
    oy =0
    err = -r
    while ox>=oy:
        last_oy = oy
        err +=oy
        oy+=1
        err+=oy
        tft.hline(x-ox,y+last_oy,ox*2+1,pen) ##3
        if last_oy != 0:
            tft.hline(x-ox,y-last_oy,ox*2+1,pen)##2
        if err>=0 and ox!=last_oy:
            tft.hline(x-last_oy,y+ox,last_oy*2+1,pen)##4
            if ox!=0:
                tft.hline(x-last_oy,y-ox,last_oy*2+1,pen)##1
            err -=ox
            ox -=1
            err -=ox

2.非实心

#draw1_8 = 1
#draw2_8 = 2
#draw3_8 = 4
#draw4_8 = 8
#draw5_8 = 16
#draw6_8 = 32
#draw7_8 = 64
#draw8_8 = 128
def drawCirc(tft,x,y,r,color,shape_type=0):
    x_i =0
    y_i = r
    p = 1-r
    shape_bin = bin(shape_type)
    while x_i<y_i:
        x_i +=1
        if p<0:
            p += 2*x_i+1
        else:
            y_i -=1
            p +=2*(x_i-y_i)+1
            
        if shape_type&0x1:
            tft.pixel(x+y_i,y-x_i,color)
        if (shape_type>>1)&0x1:
            tft.pixel(x+x_i,y-y_i,color)
            
        if (shape_type>>2)&0x1:       
            tft.pixel(x-x_i,y-y_i,color)
        if (shape_type>>3)&0x1:
            tft.pixel(x-y_i,y-x_i,color)

        if (shape_type>>4)&0x1:       
            tft.pixel(x-y_i,y+x_i,color)       
        if (shape_type>>5)&0x1:   
            tft.pixel(x-x_i,y+y_i,color)
            
        if (shape_type>>6)&0x1:       
            tft.pixel(x+x_i,y+y_i,color)     
        if (shape_type>>7)&0x1:   
            tft.pixel(x+y_i,y+x_i,color) 

标签:last,type,shape,lcd,oy,ox,tft,绘制,mpy
来源: https://blog.csdn.net/xinshuwei/article/details/123109673