Enjoy the good lift everyday!
程序猿七夕-心心相印 | PyGo²

程序猿七夕-心心相印

python带你过七夕,让程序猿的七夕不再无趣^_^。



邮箱一提到程序猿,大家的映象是这样

chengxuyuan2

这样

chengxuyuan3

或者这样

chengxuyuan4

其实,标配是这样

chengxuyuan1

哈哈,很搞笑是不,我们是程序猿,时代电子技术的领导者,怎么可能那么low呢。言归正传,程序猿也是懂浪漫的,马上七夕了,用一副漫画心心相印程序猿专有方式来陪你们过七夕,拿走不谢。

代码如下:

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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# -*- coding: utf-8 -*-

"""
------------------------------------------------
describe:

usage:


base_info:
__version__ = "v.10"
__author__ = "mingliang.gao"
__time__ = "2018/8/13"
__mail__ = "mingliang.gao@qunar.com"
------------------------------------------------
"""

import time
import turtle
from turtle import *


def write_zi(x, y, content, font_type='Comic Sans MS', font_size=30, font_normal='normal'):
penup()
goto(x, y)
pendown()
write(content, align="left", font=(font_type, font_size, font_normal))


def pen_config(size=2, color='black', speed='slow'):
# 画笔宽度
turtle.pensize(size)
# 画笔颜色
turtle.pencolor(color)
# 画笔速度 0-10
turtle.speed(speed)


def locinit_config():
# 设置框位置
turtle.setup(width=1400, height=900, startx=0, starty=200)
# turtle.screensize(bg='navajowhite')
turtle.screensize(bg='papayawhip')


# 第一个心
def one_heart():
color('deeppink', 'red')
penup()
goto(120, -20)
begin_fill()
pendown()
left(45)
fd(240)
circle(100, 225)
seth(90)
circle(100, 225)
fd(240)
end_fill()


# 第二个心
def two_heart():
color('orange', 'yellow')
penup()
goto(-40, -80)
pendown()
begin_fill()
left(90)
fd(240)
circle(100, 225)
seth(90)
circle(100, 225)
fd(240)
end_fill()


# 箭
def arrow():
# bing
penup()
goto(-410, 0)
pendown()
goto(-100, 60)
penup()
goto(255, 110)
pendown()
goto(540, 160)
# tou
penup()
goto(440, 190)
pendown()
goto(540, 160)
penup()
goto(430, 100)
pendown()
goto(540, 160)


# 诗题
def shi_title():
write_zi(200, -100, "爱", font_size=42)
write_zi(260, -100, "你", font_size=42)
write_zi(320, -100, "一", font_size=42)
write_zi(380, -100, "生", font_size=42)
write_zi(440, -100, "十", font_size=42)
write_zi(500, -100, "世", font_size=42)


# 诗
def shi():
"""
一半飘零一半安,
生逢盛世缘相遇,
十年修得同船渡,
世世生生武雅楠
"""
# 1
write_zi(260, -160, "一")
write_zi(260, -200, "半")
write_zi(260, -240, "飘")
write_zi(260, -280, "零")
write_zi(260, -320, "一")
write_zi(260, -360, "半")
write_zi(260, -400, "安")
# 2
write_zi(330, -160, "生")
write_zi(330, -200, "逢")
write_zi(330, -240, "盛")
write_zi(330, -280, "世")
write_zi(330, -320, "缘")
write_zi(330, -360, "相")
write_zi(330, -400, "遇")
# 3470
write_zi(400, -160, "十")
write_zi(400, -200, "年")
write_zi(400, -240, "修")
write_zi(400, -280, "得")
write_zi(400, -320, "同")
write_zi(400, -360, "船")
write_zi(400, -400, "渡")
# 4
write_zi(470, -160, "世")
write_zi(470, -200, "世")
write_zi(470, -240, "生")
write_zi(470, -280, "生")
write_zi(470, -320, "武")
write_zi(470, -360, "雅")
write_zi(470, -400, "楠")


if __name__ == '__main__':
time.sleep(2)
locinit_config()
pen_config(size=8, speed='fast')
one_heart()
pen_config(size=8, speed='fast')
two_heart()
pen_config(size=12, color='black', speed='normal')
arrow()
pen_config(size=3, color='red', speed='normal')
shi_title()
pen_config(size=3, color='dodgerblue', speed='fast')
shi()
time.sleep(5)

备注

  • 绘画顺序:心->心->箭->诗
  • pen_config 画笔设置,在这个方法可以切换绘画过程中的画笔颜色以及绘画的速度
  • shi 为七言绝句,如果想改其他,记得调整位置
  • 本文作者:mingliang.gao【一个爱老婆的python程序猿。。。。。。】
  • 本文链接: https://gis90.github.io/articles/31296/
  • 版权声明: 本博客所有文章欢迎转载,转载请注明出处!
觉得有帮助,请喝个咖啡
0%