Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 477dace

Browse files
committed
2 parents 4772ecf + d93be47 commit 477dace

File tree

4 files changed

+186
-0
lines changed

4 files changed

+186
-0
lines changed

‎chaoxi/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Python技术 公众号文章代码库
99

1010
## 实例代码
1111

12+
[七夕不懂浪漫?Python 帮你制造惊喜!!!](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/qixi) 七夕不懂浪漫?Python 帮你制造惊喜!!!
13+
1214
[Python 小技之 Office 文件转 PDF](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/FilesToPDF) Python 小技之 Office 文件转 PDF
1315

1416
[Office 文件转 PDF 之服务实战](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/FilesToPDF_Server):Office 文件转 PDF 之服务实战

‎chaoxi/qixi/biu.py‎

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import turtle
2+
import time
3+
from turtle import mainloop, hideturtle
4+
5+
6+
def clear_all():
7+
turtle.penup()
8+
turtle.goto(0, 0)
9+
turtle.color('white')
10+
turtle.pensize(800)
11+
turtle.pendown()
12+
turtle.setheading(0)
13+
turtle.fd(300)
14+
turtle.bk(600)
15+
16+
17+
# 重定位海龟的位置
18+
def go_to(x, y, state):
19+
turtle.pendown() if state else turtle.penup()
20+
turtle.goto(x, y)
21+
22+
23+
def draw_heart(size):
24+
turtle.color('red', 'pink')
25+
turtle.pensize(2)
26+
turtle.pendown()
27+
turtle.setheading(150)
28+
turtle.begin_fill()
29+
turtle.fd(size)
30+
turtle.circle(size * -3.745, 45)
31+
turtle.circle(size * -1.431, 165)
32+
turtle.left(120)
33+
turtle.circle(size * -1.431, 165)
34+
turtle.circle(size * -3.745, 45)
35+
turtle.fd(size)
36+
turtle.end_fill()
37+
38+
39+
# 画出发射爱心的小人
40+
def draw_people(x, y):
41+
turtle.penup()
42+
turtle.goto(x, y)
43+
turtle.pendown()
44+
turtle.pensize(2)
45+
turtle.color('black')
46+
turtle.setheading(0)
47+
turtle.circle(60, 360)
48+
turtle.penup()
49+
turtle.setheading(90)
50+
turtle.fd(75)
51+
turtle.setheading(180)
52+
turtle.fd(20)
53+
turtle.pensize(4)
54+
turtle.pendown()
55+
turtle.circle(2, 360)
56+
turtle.setheading(0)
57+
turtle.penup()
58+
turtle.fd(40)
59+
turtle.pensize(4)
60+
turtle.pendown()
61+
turtle.circle(-2, 360)
62+
turtle.penup()
63+
turtle.goto(x, y)
64+
turtle.setheading(-90)
65+
turtle.pendown()
66+
turtle.fd(20)
67+
turtle.setheading(0)
68+
turtle.fd(35)
69+
turtle.setheading(60)
70+
turtle.fd(10)
71+
turtle.penup()
72+
turtle.goto(x, y)
73+
turtle.setheading(-90)
74+
turtle.pendown()
75+
turtle.fd(40)
76+
turtle.setheading(0)
77+
turtle.fd(35)
78+
turtle.setheading(-60)
79+
turtle.fd(10)
80+
turtle.penup()
81+
turtle.goto(x, y)
82+
turtle.setheading(-90)
83+
turtle.pendown()
84+
turtle.fd(60)
85+
turtle.setheading(-135)
86+
turtle.fd(60)
87+
turtle.bk(60)
88+
turtle.setheading(-45)
89+
turtle.fd(30)
90+
turtle.setheading(-135)
91+
turtle.fd(35)
92+
turtle.penup()
93+
94+
95+
# 绘制文字
96+
def draw_text(text, t_color, font_size, show_time):
97+
turtle.penup()
98+
turtle.goto(-350, 0)
99+
turtle.color(t_color)
100+
turtle.write(text, font=('宋体', font_size, 'normal'))
101+
time.sleep(show_time)
102+
clear_all()
103+
104+
105+
# 爱心发射
106+
def draw_():
107+
turtle.speed(0)
108+
draw_people(-250, 20)
109+
turtle.penup()
110+
turtle.goto(-150, -30)
111+
draw_heart(14)
112+
turtle.penup()
113+
turtle.goto(-200, -200)
114+
turtle.color('pink')
115+
turtle.write('Biu~', font=('宋体', 60, 'normal'))
116+
turtle.penup()
117+
turtle.goto(-20, -60)
118+
draw_heart(25)
119+
turtle.penup()
120+
turtle.goto(-70, -200)
121+
turtle.color('pink')
122+
turtle.write('Biu~', font=('宋体', 60, 'normal'))
123+
turtle.penup()
124+
turtle.goto(200, -100)
125+
draw_heart(45)
126+
turtle.penup()
127+
turtle.goto(150, -200)
128+
turtle.color('pink')
129+
turtle.write('Biu~', font=('宋体', 60, 'normal'))
130+
turtle.hideturtle()
131+
time.sleep(3)
132+
133+
134+
def main():
135+
# 隐藏海龟
136+
hideturtle()
137+
turtle.setup(900, 500)
138+
139+
draw_text("Are You Readly?", "black", 60, 0)
140+
draw_text("接下来", "skyblue", 60, 0)
141+
draw_text("感谢你的出现,让我的日子这么甜!", "pink", 35, 3)
142+
draw_()
143+
144+
# 使用mainloop防止窗口卡死
145+
146+
mainloop()
147+
148+
if __name__ == '__main__':
149+
150+
main()

‎chaoxi/qixi/erweima.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from MyQR import myqr
2+
myqr.run(words="Welcome to Here!",
3+
version=6,
4+
picture="wife.jpg",
5+
colorized=True,
6+
save_name="ewm.png",
7+
)

‎chaoxi/qixi/sumiao.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from PIL import Image
2+
import numpy as np
3+
4+
a = np.asarray(Image.open(r".\wife.jpg").convert('L')).astype('float')
5+
6+
depth = 10. # (0-100)
7+
grad = np.gradient(a) # 取图像灰度的梯度值
8+
grad_x, grad_y = grad # 分别取横纵图像梯度值
9+
grad_x = grad_x * depth / 100.
10+
grad_y = grad_y * depth / 100.
11+
A = np.sqrt(grad_x ** 2 + grad_y ** 2 + 1.)
12+
uni_x = grad_x / A
13+
uni_y = grad_y / A
14+
uni_z = 1. / A
15+
16+
vec_el = np.pi / 2.2 # 光源的俯视角度,弧度值
17+
vec_az = np.pi / 4. # 光源的方位角度,弧度值
18+
dx = np.cos(vec_el) * np.cos(vec_az) # 光源对x 轴的影响
19+
dy = np.cos(vec_el) * np.sin(vec_az) # 光源对y 轴的影响
20+
dz = np.sin(vec_el) # 光源对z 轴的影响
21+
22+
b = 255 * (dx * uni_x + dy * uni_y + dz * uni_z) # 光源归一化
23+
b = b.clip(0, 255)
24+
25+
im = Image.fromarray(b.astype('uint8')) # 重构图像
26+
im.save(r".\result.jpg")
27+
print("保存成功,请查看")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /