Programmers - which have a confession 520 Tips for you

Blink of an eye to declare section 520, the programmer how we declare it, then I will personally pen to paper to give you an exclusive confession secrets.

First, than the heart

The way I introduced before the blessing of Mother's Day https://blog.csdn.net/BEYONDMA/article/details/90137479, is to use python's print function to output 520 of a shape, the program can run on any version of python, the principle is briefly made LIST 520 can be composed of a shape, then print output, specific code as follows:

ncol=20
nrow=10
proposal=[0,1,2,3,4,5,9,17,1+1*ncol,8+1*ncol,10+1*ncol,16+1*ncol,18+1*ncol,1+2*ncol,11+2*ncol,15+2*ncol,19+2*ncol,1+3*ncol,12+3*ncol,15+3*ncol,19+3*ncol,2+4*ncol,12+4*ncol,15+4*ncol,19+4*ncol,3+5*ncol,11+5*ncol,15+5*ncol,19+5*ncol,4+6*ncol,10+6*ncol,15+6*ncol,19+6*ncol,3+7*ncol,9+7*ncol,15+7*ncol,19+7*ncol,2+8*ncol,8+8*ncol,16+8*ncol,18+8*ncol,1+9*ncol,8+9*ncol,9+9*ncol,10+9*ncol,11+9*ncol,12+9*ncol,17+9*ncol]
proposalStr =''
for i in range(1,ncol*nrow):
if i in proposal:
proposalStr=proposalStr+'*'
else:
proposalStr = proposalStr + ' '
if i%20==0:
proposalStr=proposalStr+'\r\n'
print(proposalStr)


 


Second, the production photo wall

We can also take advantage of image processing functions python, and to the family photo wall made little moisture, if you are using WINDOWS reader is referred to https://blog.csdn.net/BEYONDMA/article/details/88381705 built environment. Specific code as follows, similar to the principle outlined above, but also the shape of matrix 520, to the deployment of the photo, as follows:

from PIL import Image
import os
path="F:/照片/2019/201901/pic"
canvasImage=Image.new('RGBA',(2000,1000))
ncol=20
nrow=10
proposal=[0,1,2,3,4,5,9,17,1+1*ncol,8+1*ncol,10+1*ncol,16+1*ncol,18+1*ncol,1+2*ncol,11+2*ncol,15+2*ncol,19+2*ncol,1+3*ncol,12+3*ncol,15+3*ncol,19+3*ncol,2+4*ncol,12+4*ncol,15+4*ncol,19+4*ncol,3+5*ncol,11+5*ncol,15+5*ncol,19+5*ncol,4+6*ncol,10+6*ncol,15+6*ncol,19+6*ncol,3+7*ncol,9+7*ncol,15+7*ncol,19+7*ncol,2+8*ncol,8+8*ncol,16+8*ncol,18+8*ncol,1+9*ncol,8+9*ncol,9+9*ncol,10+9*ncol,11+9*ncol,12+9*ncol,17+9*ncol]
listPic=[]
for i in os.walk(path):
listPic.append(i)
k=0
for j in range(1, 200):
if j in proposal:
orgImage = Image.open(os.path.join(path,listPic[0][2][k]))
print(orgImage)
canvasRow = j % 20;
canvasCol = int((j - canvasRow) / 20);
print(canvasRow)
print(canvasCol)
print()
orgImage = orgImage.resize((100, 100), Image.ANTIALIAS)
canvasImage.paste(orgImage, (canvasRow * 100, canvasCol * 100))
k=k+1
canvasImage.save('F:/new.bmp')



 


Third, the dialogue making word cloud

You can also use wordcloud us before making a word cloud to express love, you can export text specific micro-channel dialogue between lovers by email, and then made into a word cloud, here as long as the word cloud background set me the following Screenshots can

 

code show as below:

from wordcloud import WordCloud
import cv2
import jieba
import matplotlib.pyplot as plt

with open('F:/520/520.txt', 'r') as f:
text = f.read()

cut_text = " ".join(jieba.cut(text))
print(cut_text)
color_mask = cv2.imread("F:/520/mask.jpg")

520cloud = WordCloud(
font_path=" C:\\Windows\\Fonts\\simkai.ttf",
background_color='white',
mask=color_mask,
max_words=100,
max_font_size=40
)

520wCloud = 520cloud.generate(cut_text)
520wCloud.to_file('F:/520/cloud.jpg')

plt.imshow(520wCloud, interpolation='bilinear')
plt.axis('off')
plt.show()

 


How about these few examples are not difficult, and his knock at the code, but also learned a lot of knowledge of python, and finally I wish the world lovers get married, it would not wish you IT people can find themselves in this day 520 happiness, success confession!

Guess you like

Origin www.cnblogs.com/hyhy904/p/10958449.html