|90行Python代码,让张小龙的微信地球转起来( 二 )


def getPic(a):
# imgBack= Image.open('地球3.jpg')
imgBack= Image.open('世界地球日地图_8K_2.jpg')
imgCloud= Image.open('世界地球云地图_8K.jpg')
width= imgBack.size[0]

imgBack= imgBack.convert('RGBA')
arrayBack= np.array(imgBack)
arrayCloud= np.array(imgCloud)
circleSize= 508
img2= Image.new('RGBA', (circleSize,circleSize))
img= Image.new('RGBA', (circleSize,circleSize), 'black')
w= img.size[0]
h= img.size[1]
pxList=
pyList=
for i in range(w):
for j in range(h):
r= math.sqrt((i-w/2)**2+(j-h/2)**2)
if r<circleSize/2:
pxList.append(i)
pyList.append(j)
nplon, nplat= calcSphereXY2XYZ(pxList, pyList, h/2, a)
nplon2, nplat2= calcSphereXY2XYZ(pxList, pyList, h/2, a/2)
# nplon, nplat= rotSphere(nplon, nplat, )
npx, npy= calcShpereLatLong2XY(nplon, nplat, width-1, height)
npx2, npy2= calcShpereLatLong2XY(nplon2, nplat2, width-1, height)
color= arrayBack[npy, npx]
color2= arrayCloud[npy2, npx2]
for i in range(len(pxList)):
x= pxList[i]
y= pyList[i]
cc=color[i]
# print(cc)
cc= tuple(cc)
img.putpixel((x,y), cc)
【|90行Python代码,让张小龙的微信地球转起来】c2= color2[i]
c0= int(c2[0]*1.6)
if c0>255:
c0=255
c_alpha= int(c2[0]*0.9)
c2= (c0,c0,c0,c_alpha)
img2.putpixel((x,y), c2)
r,g,b,a= img2.split
img.paste(img2, (0,0), mask=a)
return img
if __name__=='__main__':
frames=
str1= '微信地球_mask.png'
img1= Image.new('RGB', (750,1334))
img2= Image.open(str1)
for i in range(0, 720, 12):
a= -i*math.pi/ 180
img= getPic(a)
img1.paste(img,(122,424))
r,g,b,alpha=img2.split
img1.paste(img2, (0,0), mask=alpha)
str1= 'temp%03d.png'%i
print(str1)
img1.save(str1)
im = imageio.imread(str1)
frames.append(im)
# img.show
imageio.mimsave('earth.gif', frames, 'GIF', duration=0.20)
|90行Python代码,让张小龙的微信地球转起来
本文插图


推荐阅读