百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文

十款代码表白特效,一个比一个浪漫

itomcoil 2025-03-07 19:55 9 浏览

提到程序员,就会出现许多关键词,诸如“直男,宅,不懂浪漫,枯燥,憨厚老实,有逻辑,人傻钱多…………”

说程序猿是直男,不可否认,大多数程序猿都挺直,因为我们没有那么多弯弯绕绕,有心思兜圈子,不如回去写几行代码………

雷军曾经说“我喜欢写代码,代码的世界很简单”

程序猿的大多数时间都是面对电脑,所以对待一份感情也会非常的认真。程序猿也许在生活中会比较宅,就比如本人,但是千万不要说程序猿不懂浪漫。当你不开心了,他可以分分钟做出一个玫瑰花、心形等告白小程序给你制造小惊喜…………

程序员一旦浪漫起来,就真没其他人啥事了!接下来就给大家介绍一下程序猿是如何表白收获爱情的………

一、制图表白

1.1玫瑰花

源码如下:

 1 import turtle as t
 2 
 3 def Curve_Draw(n,r,d=1):
 4   for i in range(n):
 5     t.left(d)
 6     t.circle(r,abs(d))
 7 
 8 s = 0.2
 9 t.setup(450*5*s,750*5*s)
10 t.pencolor('black')
11 t.fillcolor('purple')
12 t.speed(100)
13 t.penup()
14 t.goto(0,900*s)
15 t.pendown()
16 
17 t.begin_fill()
18 t.circle(200*s,30)
19 Curve_Draw(60,50*s)
20 t.circle(200*s,30)
21 Curve_Draw(4,100*s)
22 t.circle(200*s,50)
23 Curve_Draw(50,50*s)
24 t.circle(350*s,65)
25 Curve_Draw(40,70*s)
26 t.circle(150*s,50)
27 Curve_Draw(20,50*s,-1)
28 t.circle(400*s,60)
29 Curve_Draw(18,50*s)
30 t.fd(250*s)
31 t.right(150)
32 t.circle(-500*s,12)
33 t.left(140)
34 t.circle(550*s,110)
35 t.left(27)
36 t.circle(650*s,100)
37 t.left(130)
38 t.circle(-300*s,20)
39 t.right(123)
40 t.circle(220*s,57)
41 t.end_fill()
42 
43 t.left(120)
44 t.fd(280*s)
45 t.left(115)
46 t.circle(300*s,33)
47 t.left(180)
48 t.circle(-300*s,33)
49 Curve_Draw(70,225*s,-1)
50 t.circle(350*s,104)
51 t.left(90)
52 t.circle(200*s,105)
53 t.circle(-500*s,63)
54 t.penup()
55 t.goto(170*s,-30*s)
56 t.pendown()
57 t.left(160)
58 Curve_Draw(20,2500*s)
59 Curve_Draw(220,250*s,-1)
60 
61 t.fillcolor('green')
62 t.penup()
63 t.goto(670*s,-180*s)
64 t.pendown()
65 t.right(140)
66 t.begin_fill()
67 t.circle(300*s,120)
68 t.left(60)
69 t.circle(300*s,120)
70 t.end_fill()
71 t.penup()
72 t.goto(180*s,-550*s)
73 t.pendown()
74 t.right(85)
75 t.circle(600*s,40)
76 
77 t.penup()
78 t.goto(-150*s,-1000*s)
79 t.pendown()
80 t.begin_fill()
81 t.rt(120)
82 t.circle(300*s,115)
83 t.left(75)
84 t.circle(300*s,100)
85 t.end_fill()
86 t.penup()
87 t.goto(430*s,-1070*s)
88 t.pendown()
89 t.right(30)
90 t.circle(-600*s,35)
91 t.done()

1.2爱心

源码如下:

 1 import turtle as t
 2 
 3 t.penup()
 4 t.seth(-90)
 5 t.fd(160)
 6 t.pendown()
 7 t.pensize(20)
 8 t.colormode(255)
 9 for j in range(10):
10   t.speed(1000)
11   t.pencolor(25*j,5*j,15*j)
12   t.seth(130)
13   t.fd(220)
14   for i in range(23):
15     t.circle(-80,10)
16   t.seth(100)
17   for i in range(23):
18     t.circle(-80,10)
19   t.fd(220)
20 t.done()

1.3 网页爱心树表白

代码过长,仅展示部分代码:

 1 
 2 
 3 
 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

1.4 烟花表白

1.5 网页爱心表白

源码如下:

  1 
  2 
  3 
  4   
  5   爱心
  6   
 10 
 11 
 12 
 13   
 14 
 15   <script>
 16     var hearts = [];
 17     var canvas = document.getElementById('drawHeart');
 18     var wW = window.innerWidth;
 19     var wH = window.innerHeight;
 20     // 创建画布
 21     var ctx = canvas.getContext('2d');
 22     // 创建图片对象
 23     var heartImage = new Image();
 24     heartImage.src = 'img/heart.svg';
 25     var num = 100;
 26 
 27     init();
 28 
 29     window.addEventListener('resize', function(){
 30        wW = window.innerWidth;
 31        wH = window.innerHeight;
 32     });
 33     // 初始化画布大小
 34     function init(){
 35       canvas.width = wW;
 36       canvas.height = wH;
 37       for(var i = 0; i < num i 38 hearts.pushnew hearti5 39 40 requestanimationframerender 41 42 43 function getcolor 44 var val='Math.random()' 10 45 ifval> 0 && val <= 1 46 return 00f 47 else ifval> 1 && val <= 2 48 return f00 49 else ifval> 2 && val <= 3 50 return 0f0 51 else ifval> 3 && val <= 4 52 return 368 53 else ifval> 4 && val <= 5 54 return 666 55 else ifval> 5 && val <= 6 56 return 333 57 else ifval> 6 && val <= 7 58 return f50 59 else ifval> 7 && val <= 8 60 return e96d5b 61 else ifval> 8 && val <= 9 62 return 5be9e9 63 else 64 return d41d50 65 66 67 68 function gettext 69 var val='Math.random()' 10 70 ifval> 1 && val <= 3 71 return 72 else ifval> 3 && val <= 5 73 return 74 else ifval> 5 && val <= 8 75 return 76 else 77 return i love you 78 79 80 81 function hearttype 82 this.type='type;' 83 84 this.x='Math.random()' ww 85 this.y='Math.random()' wh 86 87 this.opacity='Math.random()' .5 .5 88 89 90 this.vel='{' 91 x: math.random - .5 5 92 y: math.random - .5 5 93 94 95 this.initialw='wW' .5 96 this.initialh='wH' .5 97 98 this.targetscale='Math.random()' .15 .02 0.02 99 this.scale='Math.random()' this.targetscale 100 101 102 this.fx='Math.random()' ww 103 this.fy='Math.random()' wh 104 this.fs='Math.random()' 10 105 this.text='getText();' 106 107 this.fvel='{' 108 x: math.random - .5 5 109 y: math.random - .5 5 110 f: math.random - .5 2 111 112 113 114 heart.prototype.draw='function(){' 115 ctx.save 116 ctx.globalalpha='this.opacity;' 117 ctx.drawimageheartimage this.x this.y this.width this.height 118 ctx.scalethis.scale 1 this.scale 1 119 ifthis.type 120 121 ctx.fillstyle='getColor();' 122 ctx.font='italic' this.fs px sans-serif 123 124 ctx.filltextthis.text this.fx this.fy 125 126 ctx.restore 127 128 heart.prototype.update='function(){' 129 this.x 130 this.y 131 132 ifthis.x - this.width> wW || this.x + this.width < 0 133 134 this.scale='0;' 135 this.x='Math.random()' ww 136 this.y='Math.random()' wh 137 138 ifthis.y - this.height> wH || this.y + this.height < 0 139 140 this.scale='0;' 141 this.x='Math.random()' ww 142 this.y='Math.random()' wh 143 144 145 146 this.scale - this.scale .1 147 this.height='this.scale' this.initialh 148 this.width='this.height' 1.4 149 150 ---------- 151 this.fx 152 this.fy 153 this.fs 154 155 ifthis.fs> 50){
156         this.fs = 2;
157       }
158 
159       if(this.fx - this.fs > wW || this.fx + this.fs < 0 160 161 this.fx='Math.random()' ww 162 this.fy='Math.random()' wh 163 164 ifthis.fy - this.fs> wH || this.fy + this.fs < 0){
165         // 重新初始化位置
166         this.fx = Math.random() * wW;
167         this.fy = Math.random() * wH;
168       }
169     }
170 
171     function render(){
172       ctx.clearRect(0, 0, wW, wH);
173       for(var i = 0; i < hearts.length; i++){
174         hearts[i].draw();
175         hearts[i].update();
176       }
177       requestAnimationFrame(render);
178     }
179   </script>
180 
181 

二、程序语言表白

2.1程序语言表白一

2.2程序语言表白二

2.3程序语言表白三

2.4程序语言表白四

相关推荐

Python自动化——pytest常用插件详解

前言Pytest是Python的一种单元测试框架,与unittest相比,使用起来更简洁、效率更高,也是目前大部分使用python编写测试用例的小伙伴们的第一选择了。除了框架本身提供的功能外,Pyte...

全网最全pytest大型攻略,单元测试学这就够了

pytest是一款以python为开发语言的第三方测试,主要特点如下:比自带的unittest更简洁高效,兼容unittest框架支持参数化可以更精确的控制要测试的测试用例丰富的插件,已有30...

Python Logging 最佳实践(python logging配置)

Pythonlogging的“最佳实践”可以概括为一句话:让日志既能在开发时帮你排错,也能在生产里帮你定位问题,同时不给运维埋坑。下面给出一份可直接落地的checklist,分场景逐条说明。1....

Python单元测试框架对比(python中unittest框架)

一、核心框架对比特性unittest(标准库)pytest(主流第三方)nose2(unittest扩展)doctest(文档测试)安装Python标准库pipinstallpytestp...

如何使用Python进行单元测试(pycharm单元测试)

前言在我的日常工作中,我是一名专业程序员。我使用c++、c#和Javascript。我是一个开发团队的一员,他们使用单元测试来验证我们的代码是否按照它应该的方式工作。在本文中,我将通过讨论以下主题来研...

Python单元测试(pycharm单元测试)

1.单元测试概述1.1什么是单元测试单元测试(UnitTesting)是指对软件中的最小可测试单元进行检查和验证的过程。在Python中,最小单元通常指函数、方法或类。1.2单元测试的特性独立...

pytest框架之fixture测试夹具详解

前言大家晚上好呀,今天呢来和大家唠唠pytest中的fixtures夹具的详解,废话就不多说了咱们直接进入主题哈。一、fixture的优势pytest框架的fixture测试夹具就相当于unitte...

Pytest精髓Fixture功能实例!测试效率暴涨!

前言大家好!我们今天来学习Python测试框架中的最具特色的功能之一:Fixture。可以说,掌握了Fixture,你就掌握了Pytest的精髓。它不仅能让你的测试代码更简洁、更优雅、更易于...

Python最常见的170道面试题全解析答案(二)

60.请写一个Python逻辑,计算一个文件中的大写字母数量答:withopen(‘A.txt’)asfs:count=0foriinfs.read():ifi.isupper...

为什么python高手都爱用闭包?这个实时函数技巧绝了

杂谈我想很多人都玩过python的闭包,其中最有趣的部分应该就是装饰器了。但我想很多人应该没运用上闭包的特性——外部局部变量的存储。什么意思呢?其实就是当闭包引用外部的局部变量将会被存储起来,而不会随...

春节停车难?用Python找空车位(用python编写停车场停车收费)

【导语】今天这篇文章的选题非常贴近生活。营长生活在北京,深知开车出门最怕的就是堵车和找不到停车位。记得冬至那个周末,几个小伙伴滑雪回来找了一家饺子馆吃饺子,结果七拐八拐,好不容易才找到一个停车位。看到...

PYTHON数据分析必备知识(2)(python数据分析范例)

1.二分钟快速给项目添加日志信息"""给项目添加日志信息"""#导Python内置包importloggingimporttime...

春节回家!车位难求啊!看我用Python自动寻找空车位!

作者通过相机结合深度学习算法,基于Python语言建立一个高精度的停车位的通知系统,每当有新停车位时就会发短信提醒我。听起来好像很复杂,真的方便实用吗?但实际上所使用的工具都是现成的,只要将这些工...

“==”和“is”有什么区别?一个问题就能暴露你的Python水平

可能在网上你经常能看到关于这个问题的答案和解析,但是依然有很多刚开始学习Python的人,不了解这个问题,也不知道为什么问这个问题时会暴露自己是“菜鸟”,这个问题就是:“==”和“is”之间有什么...

Python条件语句怎么用(python中条件语句的用法)

if条件判断语句python语句是按固定顺序执行的,先执行前面的语句,再执行后面的语句。如果你像要程序按照你自己定制的流程执行,就需要用到流程控制的语句,最主要用到的是条件语句和循环语句。条件语句...