日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Python:繪制520-程序員的浪漫

系統 2139 0

(1) 用*繪制數字“520”

            
              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)
            
          

Python:繪制520-程序員的浪漫_第1張圖片

?

(2)用女朋友照片繪制數字“520”

            
              from PIL import Image
import os

path="D:/照片/duxiaoxue" #duxiaoxue為存放照片的文件名字,50張左右
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): #這里選擇的是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('D:/duxiaoxue.bmp')
            
          

Python:繪制520-程序員的浪漫_第2張圖片 ?

然后在D盤內找到名字為“duxiaoxue”的bmp文件,打開是如下結果:

Python:繪制520-程序員的浪漫_第3張圖片 ?

Python:繪制520-程序員的浪漫_第4張圖片 ?

?


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 大港区| 南华县| 临高县| 刚察县| 岳阳县| 谢通门县| 温泉县| 尖扎县| 远安县| 临泉县| 肥西县| 开原市| 裕民县| 会东县| 滁州市| 镶黄旗| 五莲县| 阿拉善左旗| 喀喇沁旗| 上蔡县| 凤山市| 云安县| 洪洞县| 新沂市| 台湾省| 鄂伦春自治旗| 大新县| 略阳县| 斗六市| 花莲市| 巴中市| 会宁县| 垣曲县| 永昌县| 织金县| 新沂市| 武山县| 津市市| 东乡| 宜阳县| 通州市|