明天又是一年一度的520了,而今年这个情人节又恰逢周六,不知道大家都有什么样的打算呢?
520这天如果你和我一样,身边有男(女)朋友,那这件事真的是:泰酷辣!
对程序员来说,单身这件事是个大“bug”,关键是这个bug还无法调试!
虽然咱们程序员一直被冠上了“不懂浪漫”、格子衫、大平头的刻板印象
但是吧,咱浪漫起来也是个技术流
今天,小千就和大家一起来围观“那些程序员er专属的浪漫”
代码中的浪漫
是谁说程序员不懂浪漫,是我们不懂程序员表达浪漫的方式
比如,用python画一颗心
爱心图形和圆形、椭圆……类似,都是由一系列的点(X,Y)构成的曲线,X,Y又满足一定的关系。这样就可以确定出一个表达式expression,然后就是两个for循环(for y in range;for x in range)逐行逐列地开始打印,满足条件expression的打印出字符,否则打印空格符。
如果你觉得只画一颗心太单调了,那我们再把它再优化一下,让它动起来,像这样:
print(‘\n’.join([‘’.join([(‘Love’[(x-y) % len(‘Love’)] if ((x0.05)**2+(y0.1)**2-1)**3-(x0.05)*2(y0.1)**3 <= 0 else ’ ') for x in range(-30, 30)]) for y in range(30, -30, -1)]))
怎么样,没想到吧!枯燥的代码也可以这么浪漫~
继续看,还有更浪漫的呢
比如,用SQL算出与你相识的多少个520
MySQL
select
year(curdate()) ‘年份’,
month(curdate()) ‘月份’,
weekofyear(curdate()) ‘本年周’,
dayofyear(curdate()) ‘本年天’,
DATE_FORMAT(now(), ‘%Y-%m-%d’) ‘日期’,
TIMESTAMPDIFF(DAY,‘2017-08-23’, DATE_FORMAT(now(), ‘%Y-%m-%d’)) ‘与你第一次相识的天数’,
TIMESTAMPDIFF(YEAR,‘1998-05-20’, DATE_FORMAT(now(), ‘%Y-%m-%d’)) ‘多少个520’\G
Oracle
select
to_char(sysdate, ‘yyyy’) 年份,
to_char(sysdate, ‘MM’) 月份,
to_char(sysdate,‘iw’) 本年周,
to_char(sysdate,‘DDD’) 本年天,
to_char(sysdate, ‘yyyy-mm-dd’) 日期,
trunc(months_between(sysdate,to_date(‘19980520’,‘yyyymmdd’))/12) 多少个520
from dual;
这一套代码拿出去,谁能不感动!
要是以上这些,还是觉得不够浪漫,那你.. 是不是对浪漫过敏???
那咱们再来看个更厉害的!用python画一个动态爱心
# Import turtle package
import turtle
# Creating a turtle object(pen)
pen = turtle.Turtle()
# Defining a method to draw curve
def curve():
for i in range(200):
# Defining step by step curve motion
pen.right(1)
pen.forward(1)
# Defining method to draw a full heart
def heart():
# Set the fill color to red
pen.fillcolor('red')
# Start filling the color
pen.begin_fill()
# Draw the left line
pen.left(140)
pen.forward(113)
# Draw the left curve
curve()
pen.left(120)
# Draw the right curve
curve()
# Draw the right line
pen.forward(112)
# Ending the filling of the color
pen.end_fill()
# Defining method to write text
def txt():
# Move turtle to air
pen.up()
# Move turtle to a given position
pen.setpos(-68, 95)
# Move the turtle to the ground
pen.down()
# Set the text color to lightgreen
pen.color('lightgreen')
# Write the specified text in
# specified font style and size
pen.write("GeeksForGeeks", font=(
"Verdana", 12, "bold"))
#更改"GeeksForGeeks"里面的内容为你自己的话
# Draw a heart
heart()
# Write text
txt()
# To hide turtle
pen.ht()
呈现效果如下:
怎么样,这些程序员表达浪漫的方式,你get了吗 ~ 速速分享给朋友一起操练起来
有女朋友的发给女朋友,没女朋友的收藏起来以后发给女朋友!
最后,不管是有对象的,还是“单身狼族”,小千都祝大家
周末快乐!
前程似锦!
一生幸福!
往期精彩推荐:
更多IT资讯/程序员相关信息/技术类干货,关注@千锋教育