Article \ | tide

Source: Python Technology “ID: pythonall”

Today is Mother’s Day, xiao Jiang is here to wish all mothers a happy Holiday. As a daughter, I will not only buy gifts to send surprises, but also send special wishes with Python!

Mother’s Day is a Day to thank mothers. Mother was also a girl, afraid of the dark afraid of bugs, will shed tears, clumsy afraid of needles, but she gentle ME, gentle years.

Take this to wish all mothers happy Mother’s Day!

Make mother’s Day word cloud picture – blessing way 1

There is only one mother in this world, inclusive of my 10 million capricious!

Today I used Python to make a word cloud map to send blessings to my mother. The code is as follows:

import numpy
import multidict
import matplotlib.pyplot as plt
from scipy.misc import imread
from wordcloud import WordCloud, ImageColorGenerator

def transform_format(val):
    ""Arguments: val {[array]} -- RGB color group Returns: [array] -- Arguments: val {[array]}""
    if val[0] > 245 and val[1] > 245 and val[2] > 245:
        val[0] = val[1] = val[2] = 255
        return val
    else:
        returnVal def gen_happY_birthday_cloud (file, name): words = multidict.multidict () # You must first initialize two maximum weights of words.add('Happy Mother's Day'.10)
    words.add(name, 12) # Insert new words freelyfor i in range(1000):
        words.add('mother', numpy.random.randint(1.5))
        words.add('You have worked hard.', numpy.random.randint(1.5))
        words.add(name, numpy.random.randint(1.5Bimg = imread(file)for color in range(len(bimg)):
        bimg[color] = list(map(transform_format, bimg[color]))

    wordcloud = WordCloud(
        background_color='white',
        mask=bimg,
        font_path='simhei.ttf').generate_from_overriding (words) # generate word cloudbimgcolors = ImageColorGenerator(bimg) # render word cloudplt.axis ("off")
    plt.imshow(wordcloud.recolor(color_func=bimgColors))
    plt.savefig(name + '.png')
    plt.show()

gen_happy_birthday_cloud("mother.jpg"."Happy Mother's Day")
Copy the code

The idea is: import a picture and then input the holiday message after the picture rendering, and finally generate the corresponding word cloud according to the shape of the picture.

The running results are as follows:

Another shape picture generated word cloud:

Falling roses of love – Blessings 2

Next to make a beautiful falling heart to mothers to send blessings!

import time
from random import randint

for i in range(1.35): # print headersprint(' ')

heartStars = [2.4.8.10.14.20.26.28.40.44.52.60.64.76] # * heartBreakLines = [13.27.41.55.69.77FlowerBreakLines = [flowerBreakLines = [7.15.23.31.39.46Def addSpaces(a): # add blank Spaces = a while count >0:
        print(' ', end=' ')
        count -= 1Def newLineWithSleep():0.3)
    print('\n', end=' ')


play = 0
while play == 0:
    Left_Spaces = randint(8.80)
    addSpaces(Left_Spaces)

    for i in range(0.78): # The shape of the heartif i in heartBreakLines:
            newLineWithSleep()
            addSpaces(Left_Spaces)
        elif i in heartStars:
            print(The '*', end=' ')
        elif i in (32.36) :print('M', end=' ')
        elif i == 34:
            print('O', end=' ')
        else:
            print(' ', end=' ')

    newLineWithSleep()
    addSpaces(randint(8.80))
    print("H a p p y M o t h e r ' s D a y !", end=' ')
    newLineWithSleep()
    newLineWithSleep()

    Left_Spaces = randint(8.80)
    addSpaces(Left_Spaces)
    for i in range(0.47): # Bring flowers to your motherif i in flowerBreakLines:
            newLineWithSleep()
            addSpaces(Left_Spaces)
        elif i in (2.8.12.18) :print('{', end=' ')
        elif i in (3.9.13.19) :print('_', end=' ')
        elif i in (4.10.14.20) :print('} ', end=' ')
        elif i in (27.35.43) :print('|', end=' ')
        elif i in (34.44) :print('~', end=' ')
        elif i == 11:
            print('o', end=' ')
        else:
            print(' ', end=' ')

    print('\n', end=' ')
Copy the code

The implementation effect is as follows:

conclusion

Today is Mother’s Day, I hope you can spend a good time with your parents, or send a blessing and gift to your mother. I hope you found today’s article helpful.

Write in the last

Dear mother, in fact, I love you more than you love me for a long time, you began to love me at the age of 20, and I began to love you when I was born, you can only love me for decades, and I love you for a lifetime!

Years never defeated beauty, I wish all mothers happy Mother’s Day!

PS: Reply “Python” within the public number to enter the Python novice learning exchange group, together with the 100-day plan!

Old rules, brothers still remember, the lower right corner of the “watching” click, if you feel the content of the article is good, remember to share moments to let more people know!

[Code access ****]

Identify the qr code at the end of the text, reply: 210509