程序員的520花式繪制愛心代碼大全
聲明:代碼是祖傳代碼,我不知道原創是誰了,修修改改。主要是為了給情侶們用,雖然自己貴為單身狗。
一、花式浪漫愛心(一)
matlab代碼:
clear; clc; close all; % NOTICE: Your MATLAB version should be at least R2019a ! % --------------------------- functions ------------------------------- f = @(x, y, z)(x.^2 + 2.25*y.^2 + z.^2 - 1).^3 - ... x.^2.* z.^3 - 0.1125*y.^2.*z.^3; g = @(x, y, z)(sqrt(x.^2+y.^2)-2.5).^2 + z.^2 - 0.4^2; % -------------------------- generate data ---------------------------- t = linspace(-5, 5); [x1, y1, z1] = meshgrid(t); [x2, y2, z2] = meshgrid(t); val1 = f(x1, y1, z1); val2 = g(x2, y2, z2); [p1, v1] = isosurface(x1, y1, z1, val1, 0); [p2, v2] = isosurface(x2, y2, z2, val2, 0); % --------------------------- basic plot ------------------------------ figure() subplot(1, 1, 1) h = patch('faces',p1,'vertices',v1,'facevertexcdata',jet(size(v1,1)),... 'facecolor','w','edgecolor','flat'); hold on; patch('faces',p2,'vertices',v2,'facevertexcdata',jet(size(v2,1)),... 'facecolor','w','edgecolor','flat'); grid on; axis equal; axis([-3,3,-3,3,-1.5,1.5]); view(3) title(["$(x^2+\frac{9}{4}y^2+z^2-1)^3-x^2z^3-\frac{9}{80}y^2z^3=0$",... "$(\sqrt{x^2+y^2}-R)^2 +z^2 = r^2$"],'Interpreter','latex','position',[3.3,4]) warning('off'); % 請在此處進行您的演講!% 請在此處進行您的演講! T = suptitle("$I\ Love\ U\ !$"); % 請在此處進行您的演講!% 請在此處進行您的演講! set(T,'Interpreter','latex','FontSize',24) % -------------------------- generate gif ----------------------------- pic_num = 1; for i = 1:20 v1 = 0.98 * v1; set(h, 'vertices', v1); drawnow; F = getframe(gcf); I = frame2im(F); [I,map]=rgb2ind(I,256); if pic_num == 1 imwrite(I,map,'BeatingHeart.gif','gif','Loopcount',inf,'DelayTime',0.05); else imwrite(I,map,'BeatingHeart.gif','gif','WriteMode','append','DelayTime',0.05); end pic_num = pic_num + 1; end for i = 1:20 v1 = v1 / 0.98; set(h, 'vertices', v1); drawnow; F = getframe(gcf); I = frame2im(F); [I,map] = rgb2ind(I,256); imwrite(I,map,'BeatingHeart.gif','gif','WriteMode','append','DelayTime',0.05); pic_num = pic_num + 1; end % ----------------------------- dynamic ------------------------------- while true for i = 1:20 v1 = 0.98 * v1; set(h, 'vertices', v1); drawnow; end for i = 1:20 v1 = v1 / 0.98; set(h, 'vertices', v1); drawnow; end end % ------------------------------- end ---------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
二、花式浪漫愛心(二)
matlab代碼如下:
%愛心1 clear all clc f=@(x,y,z)(x.^2+ (9./4).*y.^2 + z.^2 - 1).^3 - x.^2.*z.^3 - (9./80).*y.^2.*z.^3; [x,y,z]=meshgrid(linspace(-3,3)); val=f(x,y,z); [p,v]=isosurface(x,y,z,val,0); patch('faces',p,'vertices',v,'facevertexcdata',jet(size(v,1)),'facecolor','w','edgecolor','flat'); view(3);grid on;axis equal;
1
2
3
4
5
6
7
8
9
三、花式浪漫愛心(三)
python代碼:
# 1-1導入turtle模塊進行設計 import turtle import time # 1-2畫心形圓弧 def hart_arc(): for i in range(200): turtle.right(1) turtle.forward(2) def move_pen_position(x, y): turtle.hideturtle() # 隱藏畫筆(先) turtle.up() # 提筆 turtle.goto(x, y) # 移動畫筆到指定起始坐標(窗口中心為0,0) turtle.down() # 下筆 turtle.showturtle() # 顯示畫筆 love = input("請輸入表白話語:") signature = input("請簽署你的名字:") date = input("請寫上日期:") if love == '': love = 'I Love You' # 1-3初始化 turtle.setup(width=800, height=500) # 窗口(畫布)大小 turtle.color('red', 'pink') # 畫筆顏色 turtle.pensize(3) # 畫筆粗細 turtle.speed(1) # 描繪速度 # 初始化畫筆起始坐標 move_pen_position(x=0, y=-180) # 移動畫筆位置 turtle.left(140) # 向左旋轉140度 turtle.begin_fill() # 標記背景填充位置 # 1-4畫圖和展示 turtle.forward(224) # 向前移動畫筆,長度為224 # 畫愛心圓弧 hart_arc() # 左側圓弧 turtle.left(120) # 調整畫筆角度 hart_arc() # 右側圓弧 # 畫心形直線( 右下方 ) turtle.forward(224) turtle.end_fill() # 標記背景填充結束位置 move_pen_position(x=70, y=160) # 移動畫筆位置 turtle.left(185) # 向左旋轉180度 turtle.circle(-110, 185) # 右側圓弧 # 畫心形直線( 右下方 ) # turtle.left(20) # 向左旋轉180度 turtle.forward(50) move_pen_position(x=-180, y=-180) # 移動畫筆位置 turtle.left(180) # 向左旋轉140度 # 畫心形直線( 左下方 ) turtle.forward(600) # 向前移動畫筆,長度為224 # 在心形中寫上表白話語 move_pen_position(0, 50) # 表白語位置 turtle.hideturtle() # 隱藏畫筆 turtle.color('#CD5C5C', 'pink') # 字體顏色 # font:設定字體、尺寸(電腦下存在的字體都可設置) align:中心對齊 turtle.write(love, font=('Arial', 20, 'bold'), align="center") # 簽寫署名和日期 if (signature != '') & (date != ''): turtle.color('red', 'pink') time.sleep(2) move_pen_position(220, -180) turtle.hideturtle() # 隱藏畫筆 turtle.write(signature, font=('Arial', 20), align="center") move_pen_position(220, -220) turtle.hideturtle() # 隱藏畫筆 turtle.write(date, font=('Arial', 20), align="center") # 1-5點擊窗口關閉程序 window = turtle.Screen() window.exitonclick()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
四、花式浪漫(四)
python代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
五、花式浪漫(五)
演示:
前端浪漫表白
網站可訪問:
已部署到網址,可訪問:https://yanghanwen.xyz/ai/
此網站用不變更,致曾最愛的人。也許那個人永遠都看不到我的這個網站了。
源碼:
前端源碼文件太多,百度網盤下載:
鏈接:https://pan.baidu.com/s/10ubZKHiyEGdW3qYG_UNS6Q?pwd=zgxk 提取碼:zgxk
1
2
六、花式浪漫(六)
演示:
前端表白源碼
網站:
可訪問網址(建議用電腦):https://yanghanwen.xyz/ai1/
此網站用不變更,致曾最愛的人。也許那個人永遠都看不到我的這個網站了。
源碼文件:
鏈接:https://pan.baidu.com/s/1XcMeF5f3AD7sEeHaWpYEOQ?pwd=oc79 提取碼:oc79
1
2
七、簡約愛心(一)
python代碼:
import matplotlib.pyplot as plt import numpy as np from decimal import Decimal from decimal import getcontext import time def heartfunc(x, y): return (x ** 2 + y ** 2 - 1) ** 3 - x ** 2 * y ** 3 <= 0 def cal_pi(precision): getcontext().prec = precision return sum(1 / Decimal(16) ** k * (Decimal(4) / (8 * k + 1) - Decimal(2) / (8 * k + 4) - Decimal(1) / (8 * k + 5) - Decimal(1) / (8 * k + 6)) for k in range(precision)) def printer(text, delay=0.1314): for ch in text: print(ch, end='', flush=True) time.sleep(delay) if __name__ == '__main__': n = 1314 x = np.linspace(-2, 2, n) y = np.linspace(-2, 2, n) X, Y = np.meshgrid(x, y) plt.contourf(X, Y, heartfunc(X, Y), cmap=plt.cm.autumn) # Colour Query https://matplattlib.org/examples/color/collormaps_reference.html plt.title("5201314") plt.show() loveInPi = str(cal_pi(1314)) heart = ['5', '2', '0', '1', '3', '1', '4'] iloveyou = "5201314" love = "" i, j = 0, 0 while love != iloveyou: if loveInPi[i] == heart[j]: love += loveInPi[i] j += 1 i += 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
八、簡約愛心(二)
python代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
九、關于源碼
具體文字自行調整,可運行,祝天下有情人終成眷屬。當我忙完一天所有事的時候,已經凌晨兩點多了,突然想起520這樣的日子,發現自己還是一個人過,不過還是希望各位好好珍惜身邊擁有,有個愛的你人不容易,好好愛護,不要等到失去才懂得珍惜,我的所有表白系列元素都是她一個人吧。
https Python 開發者
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。