七夕來襲!是時候展現專屬於程序員的浪漫了!你打算怎麼給心愛的人表達愛意?鮮花禮物?代碼表白?還是創意DIY?或者…無論那種形式,快來秀我們一臉吧!
Participate in publishing articles to get【話題達人】勳章,Participating in multiple topics can also upgrade medals!
浪漫,Unexplainable for men,不理解、不知道、難以揣測、難以衡量、難以捉摸,But the easiest way is to express your love with long-term company,Then this article uses photos of various experiences that accompany you to compose some romantic gifts that can express some love.
Hope it can be of value to all of you.
編碼語言:Python3.x
編碼環境:PyCharm Community Edition 2021.2
目錄
那些浪漫的開始
創意代碼表白
Picture graphic combination
3d庫
3d參考源碼:
3d實際效果:
庫:
pip3 config set global.index-url https://repo.huaweicloud.com/repository/pypi/simple
pip3 config list
pip3 install --upgrade pip
pip3 install Image
The first item here is to modify the mirror address,Huawei's I downloaded faster at school,The second checks whether the modification is successful,第三個是將pip升級到最新版本,The last one is what we need to useImage圖片庫.
There must be a picture in the corresponding location,否則會讀取失敗.
編碼如下:
from PIL import Image
import os
map = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1],
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
[1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
]
count = 0
for item in map:
for item1 in item:
if item1 == 0:
count += 1
print("需要圖片:", count, "張")
# 圖片路徑-自定義就行
img_dir = r"D:/images/"
# 獲取img_dir下的所有文件,It's all one type of picture
imgs = os.listdir(img_dir)
# Set the size of all images,別太大
img_h = 192
img_w = 192
# 獲取行數
rows = len(map)
# 獲取列數
columns = len(map[0])
# 設定圖片
figure = Image.new("RGB", (img_w * columns, img_h * rows), "white")
# 初始圖片下標
count = 0
# Start placing pictures
for i in range(len(map)):
for j in range(len(map[i])):
# if the element is not1,Just put pictures
if map[i][j] != 1:
# 異常處理,Prevent some pictures from being unreadable
try:
# 使用Image.open("圖片路徑")方法獲取圖片對象
image = Image.open(os.path.join(img_dir, imgs[count]))
except:
continue
# resize((自定義寬,自定義高))用來改變圖片的尺寸
image = image.resize((img_w, img_h))
# 將修改尺寸後的圖片(image)粘貼(paste)到畫布(figure)上
# 第一個參數 是圖片對象
# 第二個參數是 圖片在畫布上的位置,相當於單元格的位置
figure.paste(image, (img_w * j, img_h * i))
# Post the next chapter when you're done
count += 1
# 顯示圖片
figure.show()
# 保存路徑,The default is the project execution location
figure.save('MyHeartWillGoOn.png')
效果如下圖:
其中的map是可以隨意修改的,我根據1與0The transformation between the stitched pictures.
更換成I LOVE YOU
map = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1],
[1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1],
[1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1],
[1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
]
如果有興趣,You can also print a special one:
pip3 install matplotlib
pip3 install numpy
import matplotlib.pyplot as plt
import numpy as np
xZhou, yZhou, zZhou = np.linspace(-10, 10, 520), np.linspace(-10, 10, 520), np.linspace(-10, 10, 520)
X, Y, Z = [], [], []
for x in xZhou:
for y in yZhou:
for z in zZhou:
if (x ** 2 + (9 / 4) * y ** 2 + z ** 2 - 1) ** 3 - (9 / 80) * y ** 2 * z ** 3 - x ** 2 * z ** 3 <= 0:
X.append(x)
Y.append(y)
Z.append(z)
plt.title("I LOVE YOU")
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X, Y, Z, s=20, alpha=0.5, color="pink")
plt.show()
You can change the color yourself,It's Valentine's Day after all,Love is red,so lover....Pink is also good.
My computer's performance is average,等了大概2分鐘.
情人節了,Hope to be of some value to your lover.
送你一首【離騷】
長太息以掩涕兮,哀民生之多艱.余雖好修姱以鞿羁兮,Jian Zhaoying and Xixi for.既替余以蕙纕兮,又申之以攬茝.亦余心之所善兮,雖九死其猶未悔.The mighty spirit of resentment,Never mind the hearts of the people.眾女嫉余之蛾眉兮,謠诼謂余以善淫.
I wish you to find your true soulmate.
Those who follow the Dao cannot be separated from the Dao for an instant.
The 13th National tournament o
abnormal : reason : When uploa