├── .gitignore ├── be_my_girlfriend ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── carton.TTF ├── readme.md ├── love.spec └── love.py ├── one_line_love.py ├── README.md ├── all_love_in_picture.py ├── draw_love.py └── send_love.py /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | *.pyc 3 | -------------------------------------------------------------------------------- /be_my_girlfriend/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iswbm/love-with-python/HEAD/be_my_girlfriend/1.png -------------------------------------------------------------------------------- /be_my_girlfriend/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iswbm/love-with-python/HEAD/be_my_girlfriend/2.png -------------------------------------------------------------------------------- /be_my_girlfriend/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iswbm/love-with-python/HEAD/be_my_girlfriend/3.png -------------------------------------------------------------------------------- /be_my_girlfriend/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iswbm/love-with-python/HEAD/be_my_girlfriend/4.png -------------------------------------------------------------------------------- /be_my_girlfriend/carton.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iswbm/love-with-python/HEAD/be_my_girlfriend/carton.TTF -------------------------------------------------------------------------------- /be_my_girlfriend/readme.md: -------------------------------------------------------------------------------- 1 | 打包 2 | ```shell 3 | $ pyinstaller love.py 4 | ``` 5 | 6 | 执行 7 | ```shell 8 | $ python love.py 9 | ``` -------------------------------------------------------------------------------- /one_line_love.py: -------------------------------------------------------------------------------- 1 | print('\n'.join([line for line in [''.join([('Love'[(x-y) % len('Love')] if ((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3 <= 0 else ' ') for x in range(-30, 30)]) for y in range(30, -30, -1)] if line != ' '])) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 属于 Python 程序员的表白神器 2 | 3 | 整理了一份适合 Python 程序员的表白套路,目前仅收录四个,将会不断更新中... 4 | 5 | 以下是简易的使用指南 6 | 7 | ## 1. 单行画爱心 8 | 9 | ```shell 10 | $ python3 one_line_love.py 11 | ``` 12 | 13 | ## 2. 将满满的喜欢拼成你的样子 14 | 15 | ```shell 16 | $ python3 -m pip install pillow 17 | $ python3 all_love_in_picture.py 18 | ``` 19 | 20 | ## 3. 灵魂画手工程师的浪漫 21 | 22 | ```shell 23 | $ python3 send_love.py 24 | ``` 25 | 26 | ## 4. 让女神欲罢不能的套路 27 | 28 | ```shell 29 | $ python3 -m pip install pygame 30 | $ cd be_my_girlfriend 31 | $ python3 love.py 32 | ``` 33 | 34 | ![](http://image.iswbm.com/20200517234703.png) -------------------------------------------------------------------------------- /all_love_in_picture.py: -------------------------------------------------------------------------------- 1 | from PIL import Image, ImageDraw, ImageFont 2 | 3 | font_size, text = 7, "我喜欢你!" 4 | input_img_path = "/Users/MING/Github/love-with-python/girl.jpeg" 5 | output_img_path = "/Users/MING/Github/love-with-python/girl.png" 6 | 7 | img_raw = Image.open(input_img_path) 8 | img_array = img_raw.load() 9 | 10 | img_new = Image.new("RGB", img_raw.size, (0, 0, 0)) 11 | draw = ImageDraw.Draw(img_new) 12 | font = ImageFont.truetype('/System/Library/Fonts/PingFang.ttc', font_size) 13 | 14 | def character_generator(text): 15 | while True: 16 | for i in range(len(text)): 17 | yield text[i] 18 | 19 | ch_gen = character_generator(text) 20 | 21 | for y in range(0, img_raw.size[1], font_size): 22 | for x in range(0, img_raw.size[0], font_size): 23 | draw.text((x, y), next(ch_gen), font=font, fill=img_array[x, y], direction=None) 24 | 25 | img_new.convert('RGB').save(output_img_path) -------------------------------------------------------------------------------- /be_my_girlfriend/love.spec: -------------------------------------------------------------------------------- 1 | # -*- mode: python -*- 2 | 3 | block_cipher = None 4 | 5 | 6 | a = Analysis(['love.py'], 7 | pathex=['/Users/MING/.virtualenvs/PythonCodingTime-8iFaVP-J/', '/Users/MING/Github/love-with-python/be_my_girlfriend_mac'], 8 | binaries=[], 9 | datas=[('01.ming','.'),('PingFang.ttc','PingFang.ttc')], 10 | hiddenimports=[], 11 | hookspath=[], 12 | runtime_hooks=[], 13 | excludes=[], 14 | win_no_prefer_redirects=False, 15 | win_private_assemblies=False, 16 | cipher=block_cipher) 17 | 18 | pyz = PYZ(a.pure, a.zipped_data, 19 | cipher=block_cipher) 20 | exe = EXE(pyz, 21 | a.scripts, 22 | a.binaries, 23 | a.zipfiles, 24 | a.datas, 25 | name='love', 26 | debug=False, 27 | strip=False, 28 | upx=True, 29 | runtime_tmpdir=None, 30 | console=False ) 31 | -------------------------------------------------------------------------------- /draw_love.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | import time 3 | 4 | # 画心形圆弧 5 | def hart_arc(): 6 | for i in range(200): 7 | turtle.right(1) 8 | turtle.forward(2) 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("请输入表白话语,默认为‘I Love You’:") 19 | signature = input("请签署你的大名,不填写默认不显示:") 20 | 21 | if love == '': 22 | love = 'I Love You' 23 | 24 | time.sleep(1) 25 | 26 | # 初始化 27 | turtle.setup(width=800, height=500) # 窗口(画布)大小 28 | turtle.color('red', 'pink') # 画笔颜色 29 | turtle.pensize(3) # 画笔粗细 30 | turtle.speed(1) # 描绘速度 31 | # 初始化画笔起始坐标 32 | move_pen_position(x=0,y=-180) # 移动画笔位置 33 | turtle.left(140) # 向左旋转140度 34 | 35 | turtle.begin_fill() # 标记背景填充位置 36 | 37 | # 画心形直线( 左下方 ) 38 | turtle.forward(224) # 向前移动画笔,长度为224 39 | # 画爱心圆弧 40 | hart_arc() # 左侧圆弧 41 | turtle.left(120) # 调整画笔角度 42 | hart_arc() # 右侧圆弧 43 | # 画心形直线( 右下方 ) 44 | turtle.forward(224) 45 | 46 | turtle.end_fill() # 标记背景填充结束位置 47 | 48 | # 在心形中写上表白话语 49 | move_pen_position(0,0) # 表白语位置 50 | turtle.hideturtle() # 隐藏画笔 51 | turtle.color('#CD5C5C', 'pink') # 字体颜色 52 | # font:设定字体、尺寸(电脑下存在的字体都可设置) align:中心对齐 53 | turtle.write(love, font=('Arial', 30, 'bold'), align="center") 54 | 55 | # 签写署名 56 | if signature != '': 57 | turtle.color('red', 'pink') 58 | time.sleep(2) 59 | move_pen_position(180, -180) 60 | turtle.hideturtle() # 隐藏画笔 61 | turtle.write(signature, font=('Arial', 20), align="center") 62 | 63 | # 点击窗口关闭程序 64 | window = turtle.Screen() 65 | window.exitonclick() 66 | -------------------------------------------------------------------------------- /be_my_girlfriend/love.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import sys 3 | import os 4 | import random 5 | import pygame 6 | from pygame.locals import * 7 | 8 | 9 | WIDTH, HEIGHT = 640, 480 10 | BACKGROUND = (255, 255, 255) 11 | 12 | def button(text, x, y, w, h, color, screen, size): 13 | pygame.draw.rect(screen, color, (x, y, w, h)) 14 | font = pygame.font.Font('carton.ttf', size) 15 | textRender = font.render(text, True, (0, 0, 0)) 16 | textRect = textRender.get_rect() 17 | textRect.center = ((x+w/2), (y+h/2)) 18 | screen.blit(textRender, textRect) 19 | 20 | 21 | def title(text, screen, scale, color=(0, 0, 0)): 22 | font = pygame.font.Font('carton.ttf', WIDTH//(len(text)*2)) 23 | textRender = font.render(text, True, color) 24 | textRect = textRender.get_rect() 25 | textRect.midtop = (WIDTH/scale[0], HEIGHT/scale[1]) 26 | screen.blit(textRender, textRect) 27 | 28 | 29 | def get_random_pos(): 30 | x, y = random.randint(20, 620), random.randint(20, 460) 31 | return x, y 32 | 33 | 34 | def show_like_interface(text, screen, color=(255, 0, 0)): 35 | screen.fill(BACKGROUND) 36 | font = pygame.font.Font('carton.ttf', WIDTH//(len(text))) 37 | textRender = font.render(text, True, color) 38 | textRect = textRender.get_rect() 39 | textRect.midtop = (WIDTH/2, HEIGHT/2) 40 | screen.blit(textRender, textRect) 41 | pygame.display.update() 42 | while True: 43 | for event in pygame.event.get(): 44 | if event.type == QUIT: 45 | pygame.quit() 46 | sys.exit() 47 | 48 | def show_like_interface1(screen): 49 | screen.fill(BACKGROUND) 50 | img3 = pygame.image.load("3.png") 51 | imgRect = img3.get_rect() 52 | imgRect.midtop = WIDTH // 2, HEIGHT // 4 53 | screen.blit(img3, imgRect) 54 | pygame.display.update() 55 | while True: 56 | for event in pygame.event.get(): 57 | if event.type == QUIT: 58 | pygame.quit() 59 | sys.exit() 60 | 61 | def show_like_interface2(text, screen, color=(255, 0, 0)): 62 | screen.fill(BACKGROUND) 63 | font = pygame.font.Font('carton.ttf', WIDTH//(len(text))) 64 | textRender = font.render(text, True, color) 65 | textRect = textRender.get_rect() 66 | textRect.midtop = (WIDTH/2, HEIGHT/2) 67 | screen.blit(textRender, textRect) 68 | pygame.display.update() 69 | while True: 70 | for event in pygame.event.get(): 71 | if event.type == QUIT: 72 | pygame.quit() 73 | sys.exit() 74 | 75 | 76 | def main(): 77 | pygame.init() 78 | screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32) 79 | pygame.display.set_caption('来自一个喜欢你很久的小哥哥') 80 | clock = pygame.time.Clock() 81 | 82 | unlike_x_pos,unlike_y_pos = 370,380 83 | unlike_pos_width, unlike_pos_height = 100,50 84 | like_x_pos,like_y_pos = 180,370 85 | like_pos_width,like_pos_height = 100,50 86 | 87 | running = True 88 | button_color = (192, 192, 192) 89 | while running: 90 | screen.fill(BACKGROUND) 91 | img = pygame.image.load("1.png") 92 | imgRect = img.get_rect() 93 | imgRect.midtop = WIDTH//2, HEIGHT//4 94 | screen.blit(img, imgRect) 95 | for event in pygame.event.get(): 96 | if event.type == pygame.MOUSEBUTTONDOWN: 97 | mouse_pos = pygame.mouse.get_pos() 98 | if mouse_pos[0] < like_x_pos+like_pos_width+5 and mouse_pos[0] > like_x_pos-5 and\ 99 | mouse_pos[1] < like_y_pos+like_pos_height+5 and mouse_pos[1] > like_y_pos-5: 100 | button_color = BACKGROUND 101 | running = False 102 | mouse_pos = pygame.mouse.get_pos() 103 | if mouse_pos[0] < unlike_x_pos+unlike_pos_width+5 and mouse_pos[0] > unlike_x_pos-5 and\ 104 | mouse_pos[1] < unlike_y_pos+unlike_pos_height+5 and mouse_pos[1] > unlike_y_pos-5: 105 | while True: 106 | unlike_x_pos, unlike_y_pos = get_random_pos() 107 | if mouse_pos[0] < unlike_x_pos+unlike_pos_width+5 and mouse_pos[0] > unlike_x_pos-5 and\ 108 | mouse_pos[1] < unlike_y_pos+unlike_pos_height+5 and mouse_pos[1] > unlike_y_pos-5: 109 | continue 110 | break 111 | title('小姐姐,我观察你很久了', screen, scale=[2, 10]) 112 | title('做我女朋友好不好呀? *^_^*', screen, scale=[2, 6]) 113 | button('好呀', like_x_pos, like_y_pos, like_pos_width, like_pos_height, button_color, screen, 20) 114 | button('算了吧', unlike_x_pos, unlike_y_pos, unlike_pos_width/2, unlike_pos_height/2, button_color, screen, 10) 115 | pygame.display.flip() 116 | pygame.display.update() 117 | clock.tick(60) 118 | 119 | if not os.path.exists("3.png"): 120 | show_like_interface2('我就知道小姐姐你也喜欢我 *^_^*', screen, color=(0, 0, 0)) 121 | else: 122 | show_like_interface1(screen=screen) 123 | 124 | if __name__ == '__main__': 125 | main() -------------------------------------------------------------------------------- /send_love.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | import time 3 | 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 | # 画线 24 | # state为真时海龟回到原点,为假时不回到原来的出发点 25 | def draw_line(length, angle, state): 26 | turtle.pensize(1) 27 | turtle.pendown() 28 | turtle.setheading(angle) 29 | turtle.fd(length) 30 | turtle.bk(length) if state else turtle.penup() 31 | turtle.penup() 32 | 33 | 34 | # 画箭羽 35 | def draw_feather(size): 36 | angle = 30 # 箭的倾角 37 | feather_num = size//6 # 羽毛的数量 38 | feather_length = size // 3 # 羽毛的长度 39 | feather_gap = size//10 # 羽毛的间隔 40 | for i in range(feather_num): 41 | draw_line(feather_gap, angle+180, False) # 箭柄,不折返 42 | draw_line(feather_length, angle + 145, True) # 羽翼,要折返 43 | draw_line(feather_length, angle + 145, False) 44 | draw_line(feather_num*feather_gap, angle, False) 45 | draw_line(feather_length, angle + 145 + 180, False) 46 | for i in range(feather_num): 47 | draw_line(feather_gap, angle+180, False) # 箭柄,不折返 48 | draw_line(feather_length, angle - 145, True) # 羽翼,要折返 49 | draw_line(feather_length, angle - 145, False) 50 | draw_line(feather_num*feather_gap, angle, False) 51 | draw_line(feather_length, angle - 145 + 180, False) 52 | 53 | 54 | # 画爱心 55 | def draw_heart(size): 56 | turtle.color('red', 'pink') 57 | turtle.pensize(2) 58 | turtle.pendown() 59 | turtle.setheading(150) 60 | turtle.begin_fill() 61 | turtle.fd(size) 62 | turtle.circle(size * -3.745, 45) 63 | turtle.circle(size * -1.431, 165) 64 | turtle.left(120) 65 | turtle.circle(size * -1.431, 165) 66 | turtle.circle(size * -3.745, 45) 67 | turtle.fd(size) 68 | turtle.end_fill() 69 | 70 | 71 | def hart_arc(): 72 | for i in range(200): 73 | turtle.right(1) 74 | turtle.forward(2) 75 | 76 | # 画箭 77 | def draw_arrow(size): 78 | angle = 30 79 | turtle.color('black') 80 | draw_feather(size) 81 | turtle.pensize(4) 82 | turtle.setheading(angle) 83 | turtle.pendown() 84 | turtle.fd(size*2) 85 | 86 | 87 | # 一箭穿心 88 | # 箭的头没有画出来,而是用海龟来代替 89 | def arrow_heart(x, y, size): 90 | go_to(x, y, False) 91 | draw_heart(size*1.15) 92 | turtle.setheading(-150) 93 | turtle.penup() 94 | turtle.fd(size*2.2) 95 | draw_heart(size) 96 | turtle.penup() 97 | turtle.setheading(150) 98 | turtle.fd(size * 2.2) 99 | draw_arrow(size) 100 | 101 | 102 | # 画出发射爱心的小人 103 | def draw_people(x, y): 104 | turtle.penup() 105 | turtle.goto(x, y) 106 | turtle.pendown() 107 | turtle.pensize(2) 108 | turtle.color('black') 109 | turtle.setheading(0) 110 | turtle.circle(60, 360) 111 | turtle.penup() 112 | turtle.setheading(90) 113 | turtle.fd(75) 114 | turtle.setheading(180) 115 | turtle.fd(20) 116 | turtle.pensize(4) 117 | turtle.pendown() 118 | turtle.circle(2, 360) 119 | turtle.setheading(0) 120 | turtle.penup() 121 | turtle.fd(40) 122 | turtle.pensize(4) 123 | turtle.pendown() 124 | turtle.circle(-2, 360) 125 | turtle.penup() 126 | turtle.goto(x, y) 127 | turtle.setheading(-90) 128 | turtle.pendown() 129 | turtle.fd(20) 130 | turtle.setheading(0) 131 | turtle.fd(35) 132 | turtle.setheading(60) 133 | turtle.fd(10) 134 | turtle.penup() 135 | turtle.goto(x, y) 136 | turtle.setheading(-90) 137 | turtle.pendown() 138 | turtle.fd(40) 139 | turtle.setheading(0) 140 | turtle.fd(35) 141 | turtle.setheading(-60) 142 | turtle.fd(10) 143 | turtle.penup() 144 | turtle.goto(x, y) 145 | turtle.setheading(-90) 146 | turtle.pendown() 147 | turtle.fd(60) 148 | turtle.setheading(-135) 149 | turtle.fd(60) 150 | turtle.bk(60) 151 | turtle.setheading(-45) 152 | turtle.fd(30) 153 | turtle.setheading(-135) 154 | turtle.fd(35) 155 | turtle.penup() 156 | 157 | 158 | # 第一个画面,显示文字 159 | def page0(): 160 | turtle.penup() 161 | turtle.goto(-350, 0) 162 | turtle.color('black') 163 | turtle.write('专属于我们的情人节', font=('宋体', 60, 'normal')) 164 | time.sleep(3) 165 | 166 | 167 | # 第二个画面,显示发射爱心的小人 168 | def page1(): 169 | turtle.speed(10) 170 | draw_people(-250, 20) 171 | turtle.penup() 172 | turtle.goto(-150, -30) 173 | draw_heart(14) 174 | turtle.penup() 175 | turtle.goto(-20, -60) 176 | draw_heart(25) 177 | turtle.penup() 178 | turtle.goto(250, -100) 179 | draw_heart(45) 180 | turtle.hideturtle() 181 | time.sleep(3) 182 | 183 | 184 | # 最后一个画面,一箭穿心 185 | def page2(): 186 | turtle.speed(1) 187 | turtle.penup() 188 | turtle.goto(-200, -200) 189 | turtle.color('blue') 190 | turtle.pendown() 191 | turtle.write('大笨蛋 小笨蛋', font=('wisdom', 50, 'normal')) 192 | turtle.penup() 193 | turtle.goto(0, -190) 194 | draw_heart(10) 195 | arrow_heart(20, -60, 51) 196 | turtle.showturtle() 197 | 198 | 199 | def main(): 200 | turtle.setup(900, 500) 201 | page0() 202 | clear_all() 203 | page1() 204 | clear_all() 205 | page2() 206 | turtle.done() 207 | 208 | 209 | main() 210 | --------------------------------------------------------------------------------