原标题:如何正确使用Python进行表白
提到程序员,
可能每个同学都认识一个——
爱穿格子衬衫、冲锋衣,爱宅着敲代码的程序员或者准程序员,
他们仿佛永远在bug和debug的路上,
还总爱自黑自己是“单身狗”,
你可能认为他们是这样的:
这样的
还有这样的
其实不然
一些程序员表面上看似孤身一人
其实人家已经悄咪咪的找了女朋友
单身的朋友依旧独自行走在冬夜的冷风中
总不能用代码写一个女朋友出来吧
程序员版本《恋爱宝典》
你值得拥有
表白的错误示范
大胆冒失型:
缺根筋型:
用力过猛型:
其实程序员们也有属于自己的浪漫啦,譬如Python、C、Java、C#等等等~都有很强悍的撩妹功能。
本期,小编为大家带来使用Python表白的各种姿势。如果再学不会,那就真的是凭自己的本事单身了!
01
初阶版:一行代码画出爱心♡
使用语言:Python
代码:print('n'.join([''.join([('Love umd'[(x-y)%8]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(15,-15,-1)])
效果图:
02
进阶版:python + 数学= LOVE YOU
使用语言:Python
代码:
import matplotlib.pyplot as plt
import seaborn
import numpy
l = numpy.arange(0, 4, 0.01)
L = 1.0 / l
theta = numpy.arange(-4, 4, 0.01)
o = 3.0 * numpy.cos(theta)
O = 3.0 * numpy.sin(theta)
v = numpy.arange(-4, 4, 0.01)
V = numpy.abs(-2.0 * v)
e = numpy.arange(-3, 3, 0.01)
E = -1.0 * numpy.abs(numpy.sin(e))
y = numpy.arange(-10, 10, 0.01)
Y = numpy.log2(numpy.abs(y))
u = numpy.arange(-4, 4, 0.01)
U = 2.0 * u ** 2
points = []
for heartY in numpy.linspace(-100, 100, 500):
for heartX in numpy.linspace(-100, 100, 500):
if ((heartX*0.03)**2+(heartY*0.03)**2-1)**3-(heartX*0.03)**2*(heartY*0.03)**3 <= 0:
points.append({"x": heartX, "y": heartY})
heart_x = list(map(lambda point: point["x"], points))
heart_y = list(map(lambda point: point["y"], points))
fig = plt.figure(figsize=(13, 7))
ax_L = fig.add_subplot(2, 4, 1)
ax_O = fig.add_subplot(2, 4, 2)
ax_V = fig.add_subplot(2, 4, 3)
ax_E = fig.add_subplot(2, 4, 4)
ax_Y = fig.add_subplot(2, 4, 5)
ax_O_2 = fig.add_subplot(2, 4, 6)
ax_U = fig.add_subplot(2, 4, 7)
ax_heart = fig.add_subplot(2, 4, 8)
plt.plot(colos='tomato')
ax_L.plot(l, L)
ax_O.plot(o, O)
ax_V.plot(v, V)
ax_E.plot(E, e)
ax_Y.plot(y, Y)
ax_Y.axis([-10.0, 10.0, -10.0, 5.0])
ax_O_2.plot(o, O)
ax_U.plot(u, U)
ax_heart.scatter(heart_x, heart_y, s=10, alpha=0.5)
seaborn.set_style('whitegrid')
plt.show()
效果图:
03
终极版:用Python画一只玫瑰
使用语言:Python
代码:
import turtle
import time
# writing txt
turtle.hideturtle()
turtle.penup()
turtle.goto(130, 50)
# turtle.pendown()
turtle.color("blue")
turtle.write("亲爱的,给你画个东西", font=("Times", 18, "bold"))
time.sleep(2)
turtle.goto(180, 10)
turtle.write("开始了哈~", font=("Times", 18, "bold"))
time.sleep(2)
turtle.goto(200, -20)
turtle.write("Ready?", font=("Times", 18, "bold"))
time.sleep(2)
turtle.goto(215, -50)
turtle.write("go!", font=("Times", 18, "bold"))
time.sleep(2)
# turtle.end_fill()
#
# 设置初始位置
turtle.goto(0, 0)
turtle.color("black")
turtle.penup()
turtle.left(90)
turtle.fd(200)
turtle.pendown()
turtle.right(90)
# 花蕊
turtle.fillcolor("red")
turtle.begin_fill()
turtle.circle(10, 180)
turtle.circle(25, 110)
turtle.left(50)
turtle.circle(60, 45)
turtle.circle(20, 170)
turtle.right(24)
turtle.fd(30)
turtle.left(10)
turtle.circle(30, 110)
turtle.fd(20)
turtle.left(40)
turtle.circle(90, 70)
turtle.circle(30, 150)
turtle.right(30)
turtle.fd(15)
turtle.circle(80, 90)
turtle.left(15)
turtle.fd(45)
turtle.right(165)
turtle.fd(20)
turtle.left(155)
turtle.circle(150, 80)
turtle.left(50)
turtle.circle(150, 90)
turtle.end_fill()
# 花瓣1
turtle.left(150)
turtle.circle(-90, 70)
turtle.left(20)
turtle.circle(75, 105)
turtle.setheading(60)
turtle.circle(80, 98)
turtle.circle(-90, 40)
# 花瓣2
turtle.left(180)
turtle.circle(90, 40)
turtle.circle(-80, 98)
turtle.setheading(-83)
# 叶子1
turtle.fd(30)
turtle.left(90)
turtle.fd(25)
turtle.left(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(-80, 90)
turtle.right(90)
turtle.circle(-80, 90)
turtle.end_fill()
turtle.right(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(85)
turtle.left(90)
turtle.fd(80)
# 叶子2
turtle.right(90)
turtle.right(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(80, 90)
turtle.left(90)
turtle.circle(80, 90)
turtle.end_fill()
turtle.left(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(60)
turtle.right(90)
turtle.circle(200, 60)
time.sleep(2)
turtle.penup()
turtle.color("blue")
turtle.goto(180, -100)
turtle.write("umd~送给你~", font=("Times", 18, "bold"))
time.sleep(20)
效果图:
怎么样?
各位霸霸们,get到新技能了吗
还有什么新奇的招数
热烈欢迎程序猿霸霸们
在留言板给大家提点一番
编辑丨赵奉超
图源 | 梦游家、网络
责任编辑: