Skip to content

Commit c361506

Browse files
committed
提交代码
1 parent 8ca09d5 commit c361506

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

.DS_Store

0 Bytes
Binary file not shown.

chaoxi/521_love/love.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import matplotlib.pyplot as plt
2+
import seaborn
3+
import numpy
4+
5+
# 定义方法
6+
def draw_love():
7+
#拼凑字母
8+
l = numpy.arange(0, 4, 0.01)
9+
L = 1.0 / l
10+
theta = numpy.arange(-4, 4, 0.01)
11+
o = 3.0 * numpy.cos(theta)
12+
O = 3.0 * numpy.sin(theta)
13+
v = numpy.arange(-4, 4, 0.01)
14+
V = numpy.abs(-2.0 * v)
15+
e = numpy.arange(-3, 3, 0.01)
16+
E = -1.0 * numpy.abs(numpy.sin(e))
17+
y = numpy.arange(-10, 10, 0.01)
18+
Y = numpy.log2(numpy.abs(y))
19+
u = numpy.arange(-4, 4, 0.01)
20+
U = 2.0 * u ** 2
21+
points = []
22+
23+
for heartY in numpy.linspace(-100, 100, 500):
24+
for heartX in numpy.linspace(-100, 100, 500):
25+
if ((heartX * 0.03) ** 2 + (heartY * 0.03) ** 2 - 1) ** 3 - (heartX * 0.03) ** 2 * (
26+
heartY * 0.03) ** 3 <= 0:
27+
points.append({"x": heartX, "y": heartY})
28+
# 设置直角坐标系
29+
heart_x = list(map(lambda point: point["x"], points))
30+
heart_y = list(map(lambda point: point["y"], points))
31+
32+
# 添加网格
33+
fig = plt.figure(figsize=(13, 7))
34+
ax_L = fig.add_subplot(2, 4, 1)
35+
ax_O = fig.add_subplot(2, 4, 2)
36+
ax_V = fig.add_subplot(2, 4, 3)
37+
ax_E = fig.add_subplot(2, 4, 4)
38+
ax_Y = fig.add_subplot(2, 4, 5)
39+
ax_O_2 = fig.add_subplot(2, 4, 6)
40+
ax_U = fig.add_subplot(2, 4, 7)
41+
ax_heart = fig.add_subplot(2, 4, 8)
42+
43+
# 设置坐标
44+
ax_L.plot(l, L)
45+
ax_O.plot(o, O)
46+
ax_V.plot(v, V)
47+
ax_E.plot(E, e)
48+
ax_Y.plot(y, Y)
49+
ax_Y.axis([-10.0, 10.0, -10.0, 5.0])
50+
ax_O_2.plot(o, O)
51+
52+
ax_U.plot(u, U)
53+
54+
ax_heart.scatter(heart_x, heart_y, s=10, alpha=0.5)
55+
# 设置颜色
56+
plt.plot(color='red')
57+
# 展示结果
58+
plt.show()
59+
60+
# 主函数
61+
if __name__ == '__main__':
62+
seaborn.set_style('dark')
63+
draw_love()

chaoxi/521_love/love1.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import turtle
2+
import time
3+
4+
def hart_arc():
5+
for i in range(200):
6+
turtle.right(1)
7+
turtle.forward(2)
8+
9+
10+
def move_pen_position(x, y):
11+
turtle.hideturtle() # 隐藏画笔(先)
12+
turtle.up() # 提笔
13+
turtle.goto(x, y) # 移动画笔到指定起始坐标(窗口中心为0,0)
14+
turtle.down() # 下笔
15+
turtle.showturtle() # 显示画笔
16+
17+
18+
love = input("请输入表白话语:")
19+
signature = input("请签署你的名字:")
20+
date=input("请写上日期:")
21+
22+
if love == '':
23+
love = 'I Love You'
24+
25+
turtle.setup(width=800, height=500) # 窗口(画布)大小
26+
turtle.color('red', 'pink') # 画笔颜色
27+
turtle.pensize(3) # 画笔粗细
28+
turtle.speed(1) # 描绘速度
29+
# 初始化画笔起始坐标
30+
move_pen_position(x=0, y=-180) # 移动画笔位置
31+
turtle.left(140) # 向左旋转140度
32+
33+
turtle.begin_fill() # 标记背景填充位置
34+
35+
# 画图和展示
36+
turtle.forward(224) # 向前移动画笔,长度为224
37+
# 画爱心圆弧
38+
hart_arc() # 左侧圆弧
39+
turtle.left(120) # 调整画笔角度
40+
hart_arc() # 右侧圆弧
41+
# 画心形直线( 右下方 )
42+
turtle.forward(224)
43+
44+
turtle.end_fill() # 标记背景填充结束位置
45+
46+
move_pen_position(x=70, y=160) # 移动画笔位置
47+
turtle.left(185) # 向左旋转180度
48+
turtle.circle(-110,185) # 右侧圆弧
49+
# 画心形直线( 右下方 )
50+
#turtle.left(20) # 向左旋转180度
51+
turtle.forward(50)
52+
move_pen_position(x=-180, y=-180) # 移动画笔位置
53+
turtle.left(180) # 向左旋转140度
54+
55+
# 画心形直线( 左下方 )
56+
turtle.forward(600) # 向前移动画笔,长度为224
57+
58+
# 在心形中写上表白话语
59+
move_pen_position(0,50) # 表白语位置
60+
turtle.hideturtle() # 隐藏画笔
61+
turtle.color('#CD5C5C', 'pink') # 字体颜色
62+
# font:设定字体、尺寸(电脑下存在的字体都可设置) align:中心对齐
63+
turtle.write(love, font=('Arial', 20, 'bold'), align="center")
64+
65+
# 签写署名和日期
66+
if (signature != '') & (date != ''):
67+
turtle.color('red', 'pink')
68+
time.sleep(2)
69+
move_pen_position(220, -180)
70+
turtle.hideturtle() # 隐藏画笔
71+
turtle.write(signature, font=('Arial', 20), align="center")
72+
move_pen_position(220, -220)
73+
turtle.hideturtle() # 隐藏画笔
74+
turtle.write(date, font=('Arial', 20), align="center")
75+
76+
#点击窗口关闭程序
77+
window = turtle.Screen()
78+
window.exitonclick()
79+

0 commit comments

Comments
 (0)