It’s the Chinese Valentine’s Day. It’s the Chinese Valentine’s Day. Let programmers love people feel the romance of IT people!

​                                                      

​       

​​

Today is Chinese Valentine’s Day!

Have you prepared a surprise for your beloved?

                     

The body of the

Xiaobian is very poor, take the hand of only free gifts.

No object to learn to express procedures, there are objects to take the Tanabata!!

One, word cloud production

First we can use the WordCould package to make word clouds. The WordCloud package is simple to install. PIP is ready to install.

Install: PIP install Wordclould if you need the environment directly private chat xiaobian free access.

Then to make the word cloud, you need a background image, which is optional. Because today is Tanabata so directly used a simple.

Ps: You can also use the background of an object, boyfriend/girlfriend.

​​

The code is as follows:

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

# Here are the words you say

with open('F:/qixi/qixi.txt', 'r') as f: text = f.read() cut_text = " ".join(jieba.cut(text)) print(cut_text)

# Just use the image we saved as

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()

Effect:

! [](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/954961eeed13457a876cd9d5735375f7~tplv-k3u1fbpfcp-zoom-1.image)! [](data:image/gif; Base64, R0lGODlhAQABAPABAP / / / wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw = = "click and drag to move")

Second,

Turtle Basic parameters

The power of Python lies in its many powerful libraries. Turtle is a module for interactive drawing. It is also the secret to improving the enjoyment of Python for beginners!

As a less art-rich fellow, it may be difficult to draw a picture, but using Python’s Turtle library, you can do it in just a few lines of code. The previous article also has a lot of small braid drawing source oh! Welcome to previous articles!

1. Spongebob Squarepants 2. Pikachu 3 Confession code collection.

Turtle is a library that comes with Python and can be called directly.

​​

Then we need to understand turtle’s basic statements to lay the foundation for drawing.

Now, let’s try using the commands in the above table to see how turtle moves.

​​

After running, the effect is as follows:

You can see that the brush is moving as we want it to. Now let’s try our own simple imitation to draw

drawing

But to save work, we can create some functions so that we don’t have to write a lot of basic code many times.

​​

For example, the above code builds a function to draw a heart and tests the effect separately.

Successfully draw a heart and fill it with color.

The rest of us can use the straight line and curve to draw the head, arms and body, etc.

​​

Of course, in addition to the heart, you can also add some text. If you want to customize the text, directly change the parameter text 520.

​​

The final result is shown in the following figure 👇

At the end

Ahem, the article ends here, wish you all have a beautiful Tanabata today!!

Because still in the epidemic period if you are certain to meet, remember to show each other a green code ~~~~~

Hahaha this meme brush douyin see!!

Need complete project: private message 06 will do.