偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

實(shí)戰(zhàn)!用 Python 給母親送祝福!

開發(fā) 后端
今天是母親節(jié),小阿醬在這里祝天下所有的母親節(jié)日快樂,作為女兒的我除了買禮物送驚喜外還要用 Python 送上特殊的祝福!

[[398232]]

本文轉(zhuǎn)載自微信公眾號「 Python技術(shù)」,作者派森醬。轉(zhuǎn)載本文請聯(lián)系 Python技術(shù)公眾號。

今天是母親節(jié),小阿醬在這里祝天下所有的母親節(jié)日快樂,作為女兒的我除了買禮物送驚喜外還要用 Python 送上特殊的祝福!

母親節(jié)(Mother’s Day),是一個感謝母親的節(jié)日。媽媽曾經(jīng)也是一個女孩子,怕黑怕蟲子,也會掉眼淚,笨手笨腳怕扎針,但她溫柔了我,溫柔了歲月。

借此祝全天下媽媽母親節(jié)快樂!

制作母親節(jié)詞云圖-祝福方式1

這個世界只有一個母親,包容我的一千萬任性!

今天我用 Python 制作一個詞云圖給媽媽送祝福,制作代碼如下:

  1. import numpy 
  2. import multidict 
  3. import matplotlib.pyplot as plt 
  4. from scipy.misc import imread 
  5. from wordcloud import WordCloud, ImageColorGenerator 
  6.  
  7. def transform_format(val): 
  8.     ""
  9.     用于去除雜色 
  10.     Arguments: 
  11.         val {[array]} -- RGB顏色組 
  12.     Returns
  13.         [array] -- 去除雜色后的值 
  14.     ""
  15.     if val[0] > 245 and val[1] > 245 and val[2] > 245: 
  16.         val[0] = val[1] = val[2] = 255 
  17.         return val 
  18.     else
  19.         return val 
  20.  
  21.  
  22. def gen_happy_birthday_cloud(file, name): 
  23.     words = multidict.MultiDict() 
  24.     # 必須先初始化兩個最大權(quán)重的 
  25.     words.add('母親節(jié)快樂', 10) 
  26.     words.add(name, 12) 
  27.  
  28.     # 隨意插入新的詞語 
  29.     for i in range(1000): 
  30.         words.add('媽媽', numpy.random.randint(1, 5)) 
  31.         words.add('您辛苦了', numpy.random.randint(1, 5)) 
  32.         words.add(name, numpy.random.randint(1, 5)) 
  33.  
  34.     # 設(shè)定圖片 
  35.     bimg = imread(file) 
  36.     for color in range(len(bimg)): 
  37.         bimg[color] = list(map(transform_format, bimg[color])) 
  38.  
  39.     wordcloud = WordCloud( 
  40.         background_color='white'
  41.         mask=bimg, 
  42.         font_path='simhei.ttf' 
  43.     ).generate_from_frequencies(words) 
  44.  
  45.     # 生成詞云 
  46.     bimgColors = ImageColorGenerator(bimg) 
  47.  
  48.     # 渲染詞云 
  49.     plt.axis("off"
  50.     plt.imshow(wordcloud.recolor(color_func=bimgColors)) 
  51.     plt.savefig(name + '.png'
  52.     plt.show() 
  53.  
  54. gen_happy_birthday_cloud("mother.jpg""母親節(jié)快樂"

思路為: 導(dǎo)入一張圖片后再輸入節(jié)日祝福語后進(jìn)行圖片渲染,最后再根據(jù)圖片形狀生成相應(yīng)詞云圖。

運(yùn)行結(jié)果如下:

另一個形狀圖片生成的詞云圖:圖片

飄落愛心玫瑰-祝福方式2

接下來還要制作一個唯美飄落桃心給媽媽們送祝福!

  1. import time 
  2. from random import randint 
  3.  
  4. for i in range(1, 35):  # 打印抬頭 
  5.     print(''
  6.  
  7. heartStars = [2, 4, 8, 10, 14, 20, 26, 28, 40, 44, 52, 60, 64, 76]  # *的位置 
  8. heartBreakLines = [13, 27, 41, 55, 69, 77]  # 空格的位置 
  9. flowerBreakLines = [7, 15, 23, 31, 39, 46]  # 玫瑰的空列位置 
  10.  
  11. def addSpaces(a):  # 添加空列 
  12.     count = a 
  13.     while count > 0: 
  14.         print(' 'end=''
  15.         count -= 1 
  16.  
  17.  
  18. def newLineWithSleep():  # 添加空行 
  19.     time.sleep(0.3) 
  20.     print('\n'end=''
  21.  
  22.  
  23. play = 0 
  24. while play == 0: 
  25.     Left_Spaces = randint(8, 80) 
  26.     addSpaces(Left_Spaces) 
  27.  
  28.     for i in range(0, 78):  # 比心的形狀 
  29.         if i in heartBreakLines: 
  30.             newLineWithSleep() 
  31.             addSpaces(Left_Spaces) 
  32.         elif i in heartStars: 
  33.             print('*'end=''
  34.         elif i in (32, 36): 
  35.             print('M'end=''
  36.         elif i == 34: 
  37.             print('O'end=''
  38.         else
  39.             print(' 'end=''
  40.  
  41.     newLineWithSleep() 
  42.     addSpaces(randint(8, 80)) 
  43.     print("H a p p y  M o t h e r ' s   D a y !"end='') 
  44.     newLineWithSleep() 
  45.     newLineWithSleep() 
  46.  
  47.     Left_Spaces = randint(8, 80) 
  48.     addSpaces(Left_Spaces) 
  49.     for i in range(0, 47):  # 向母親獻(xiàn)花 
  50.         if i in flowerBreakLines: 
  51.             newLineWithSleep() 
  52.             addSpaces(Left_Spaces) 
  53.         elif i in (2, 8, 12, 18): 
  54.             print('{'end=''
  55.         elif i in (3, 9, 13, 19): 
  56.             print('_'end=''
  57.         elif i in (4, 10, 14, 20): 
  58.             print('}'end=''
  59.         elif i in (27, 35, 43): 
  60.             print('|'end=''
  61.         elif i in (34, 44): 
  62.             print('~'end=''
  63.         elif i == 11: 
  64.             print('o'end=''
  65.         else
  66.             print(' 'end=''
  67.  
  68.     print('\n'end=''

實(shí)現(xiàn)效果如下:

總結(jié)

今天是母親節(jié),借此希望大家能夠好好陪陪父母,或者給母親送上一份祝福和好禮。也希望今天的文章對大家有幫助。

寫在最后

親愛的媽媽,其實(shí)我愛你要比你愛我久一點(diǎn),你從 20 歲就開始愛我,而我一出生就開始愛你,你只能愛我?guī)资辏覑勰阋惠呑?

歲月從不敗美人,祝全天下媽媽母親節(jié)快樂!

責(zé)任編輯:武曉燕 來源: Python技術(shù)
相關(guān)推薦

2012-11-23 15:28:08

華碩網(wǎng)絡(luò)產(chǎn)品

2022-01-22 19:58:15

微信微信支付紅包封面

2017-05-12 16:05:44

2017-05-12 16:05:44

2025-10-31 08:07:57

2012-02-01 17:11:14

傲游短信擴(kuò)展插件

2018-02-24 21:44:05

互聯(lián)網(wǎng)大數(shù)據(jù)春節(jié)

2024-08-09 10:15:34

2024-01-15 07:47:09

井字棋游戲編程練習(xí)Python

2021-12-24 14:17:11

SVG平安夜祝福動畫

2022-06-20 05:50:41

抖音春節(jié)活動視頻發(fā)紅包

2022-04-12 09:21:50

AIPython自動駕駛

2011-05-10 13:37:53

程序員

2018-12-25 09:27:55

Python圣誕帽程序員

2021-05-19 11:02:44

PythonTurtle參數(shù)

2020-02-22 08:02:07

春節(jié)疫情防控口罩

2012-02-17 13:39:03

CornerstoneAndroid平板

2011-09-27 11:09:13

2012-04-03 14:01:54

蘋果
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號