Python 官方文档:入门教程 => 点击学习
声明:代码是祖传代码,我不知道原创是谁了,修修改改。主要是为了给情侣们用,虽然自己贵为单身狗。 一、花式浪漫爱心(一) matlab代码: clear; clc; close all; % NOTI
声明:代码是祖传代码,我不知道原创是谁了,修修改改。主要是为了给情侣们用,虽然自己贵为单身狗。
matlab代码:
clear; clc; close all; % NOTICE: Your MATLAB version should be at least R2019a !% --------------------------- functions -------------------------------f = @(x, y, z)(x.^2 + 2.25*y.^2 + z.^2 - 1).^3 - ... x.^2.* z.^3 - 0.1125*y.^2.*z.^3;g = @(x, y, z)(sqrt(x.^2+y.^2)-2.5).^2 + z.^2 - 0.4^2;% -------------------------- generate data ----------------------------t = linspace(-5, 5);[x1, y1, z1] = meshgrid(t);[x2, y2, z2] = meshgrid(t);val1 = f(x1, y1, z1);val2 = g(x2, y2, z2);[p1, v1] = isosurface(x1, y1, z1, val1, 0);[p2, v2] = isosurface(x2, y2, z2, val2, 0);% --------------------------- basic plot ------------------------------figure()subplot(1, 1, 1)h = patch('faces',p1,'vertices',v1,'facevertexcdata',jet(size(v1,1)),... 'facecolor','w','edgecolor','flat'); hold on;patch('faces',p2,'vertices',v2,'facevertexcdata',jet(size(v2,1)),... 'facecolor','w','edgecolor','flat');grid on; axis equal; axis([-3,3,-3,3,-1.5,1.5]); view(3)title(["$(x^2+\frac{9}{4}y^2+z^2-1)^3-x^2z^3-\frac{9}{80}y^2z^3=0$",... "$(\sqrt{x^2+y^2}-R)^2 +z^2 = r^2$"],'Interpreter','latex','position',[3.3,4])warning('off');% 请在此处进行您的演讲!% 请在此处进行您的演讲!T = suptitle("$I\ Love\ U\ !$"); % 请在此处进行您的演讲!% 请在此处进行您的演讲!set(T,'Interpreter','latex','FontSize',24)% -------------------------- generate gif -----------------------------pic_num = 1;for i = 1:20 v1 = 0.98 * v1; set(h, 'vertices', v1); drawnow; F = getframe(GCf); I = frame2im(F); [I,map]=rgb2ind(I,256); if pic_num == 1 imwrite(I,map,'BeatingHeart.gif','gif','Loopcount',inf,'DelayTime',0.05); else imwrite(I,map,'BeatingHeart.gif','gif','WriteMode','append','DelayTime',0.05); end pic_num = pic_num + 1;endfor i = 1:20 v1 = v1 / 0.98; set(h, 'vertices', v1); drawnow; F = getframe(gcf); I = frame2im(F); [I,map] = rgb2ind(I,256); imwrite(I,map,'BeatingHeart.gif','gif','WriteMode','append','DelayTime',0.05); pic_num = pic_num + 1;end% ----------------------------- dynamic -------------------------------while true for i = 1:20 v1 = 0.98 * v1; set(h, 'vertices', v1); drawnow; end for i = 1:20 v1 = v1 / 0.98; set(h, 'vertices', v1); drawnow; endend% ------------------------------- end ---------------------------
matlab代码如下:
%爱心1clear allclcf=@(x,y,z)(x.^2+ (9./4).*y.^2 + z.^2 - 1).^3 - x.^2.*z.^3 - (9./80).*y.^2.*z.^3;[x,y,z]=meshgrid(linspace(-3,3));val=f(x,y,z);[p,v]=isosurface(x,y,z,val,0);patch('faces',p,'vertices',v,'facevertexcdata',jet(size(v,1)),'facecolor','w','edgecolor','flat');view(3);grid on;axis equal;
python代码:
# 1-1导入turtle模块进行设计import turtleimport time# 1-2画心形圆弧def hart_arc(): for i in range(200): turtle.right(1) turtle.forward(2)def move_pen_position(x, y): turtle.hideturtle() # 隐藏画笔(先) turtle.up() # 提笔 turtle.Goto(x, y) # 移动画笔到指定起始坐标(窗口中心为0,0) turtle.down() # 下笔 turtle.showturtle() # 显示画笔love = input("请输入表白话语:")signature = input("请签署你的名字:")date = input("请写上日期:")if love == '': love = 'I Love You'# 1-3初始化turtle.setup(width=800, height=500) # 窗口(画布)大小turtle.color('red', 'pink') # 画笔颜色turtle.pensize(3) # 画笔粗细turtle.speed(1) # 描绘速度# 初始化画笔起始坐标move_pen_position(x=0, y=-180) # 移动画笔位置turtle.left(140) # 向左旋转140度turtle.begin_fill() # 标记背景填充位置# 1-4画图和展示turtle.forward(224) # 向前移动画笔,长度为224# 画爱心圆弧hart_arc() # 左侧圆弧turtle.left(120) # 调整画笔角度hart_arc() # 右侧圆弧# 画心形直线( 右下方 )turtle.forward(224)turtle.end_fill() # 标记背景填充结束位置move_pen_position(x=70, y=160) # 移动画笔位置turtle.left(185) # 向左旋转180度turtle.circle(-110, 185) # 右侧圆弧# 画心形直线( 右下方 )# turtle.left(20) # 向左旋转180度turtle.forward(50)move_pen_position(x=-180, y=-180) # 移动画笔位置turtle.left(180) # 向左旋转140度# 画心形直线( 左下方 )turtle.forward(600) # 向前移动画笔,长度为224# 在心形中写上表白话语move_pen_position(0, 50) # 表白语位置turtle.hideturtle() # 隐藏画笔turtle.color('#CD5C5C', 'pink') # 字体颜色# font:设定字体、尺寸(电脑下存在的字体都可设置) align:中心对齐turtle.write(love, font=('Arial', 20, 'bold'), align="center")# 签写署名和日期if (signature != '') & (date != ''): turtle.color('red', 'pink') time.sleep(2) move_pen_position(220, -180) turtle.hideturtle() # 隐藏画笔 turtle.write(signature, font=('Arial', 20), align="center") move_pen_position(220, -220) turtle.hideturtle() # 隐藏画笔 turtle.write(date, font=('Arial', 20), align="center")# 1-5点击窗口关闭程序window = turtle.Screen()window.exitonclick()
Python代码:
# coding=gbk"""作者:川川@时间 : 2022/5/20 2:50"""import turtleimport randomdef love(x,y):#在(x,y)处画爱心lalala lv=turtle.Turtle() lv.hideturtle() lv.up() lv.goto(x,y)#定位到(x,y) def curvemove():#画圆弧 for i in range(20): lv.right(10) lv.forward(2) lv.color('red','pink') lv.speed(10000000) lv.pensize(1) #开始画爱心lalala lv.down() lv.begin_fill() lv.left(140) lv.forward(22) curvemove() lv.left(120) curvemove() lv.forward(22) lv.write("思思",font=("Arial",12,"nORMal"),align="center") lv.left(140)#画完复位 lv.end_fill()def tree(branchLen,t): if branchLen > 5:#剩余树枝太少要结束递归 if branchLen<20:#如果树枝剩余长度较短则变绿 t.color("green") t.pensize(random.uniform((branchLen + 5) / 4 - 2, (branchLen + 6) / 4 + 5)) t.down() t.forward(branchLen) love(t.xcor(),t.ycor())#传输现在turtle的坐标 t.up() t.backward(branchLen) t.color("brown") return t.pensize(random.uniform((branchLen+5)/4-2,(branchLen+6)/4+5)) t.down() t.forward(branchLen) # 以下递归 ang=random.uniform(15,45) t.right(ang) tree(branchLen-random.uniform(12,16),t)#随机决定减小长度 t.left(2*ang) tree(branchLen-random.uniform(12,16),t)#随机决定减小长度 t.right(ang) t.up() t.backward(branchLen)myWin = turtle.Screen()t = turtle.Turtle()t.hideturtle()t.speed(1000)t.left(90)t.up()t.backward(200)t.down()t.color("brown")t.pensize(32)t.forward(60)tree(100,t)myWin.exitonclick()
演示:
前端浪漫表白
网站可访问:
已部署到网址,可访问:https://yanghanwen.xyz/ai/
此网站用不变更,致曾最爱的人。也许那个人永远都看不到我的这个网站了。
源码:
前端源码文件太多,百度网盘下载:
链接:Https://pan.baidu.com/s/10ubZKHiyEGdW3qYG_UNS6Q?pwd=zgxk 提取码:zgxk
演示:
前端表白源码
网站:
可访问网址(建议用电脑):https://yanghanwen.xyz/ai1/
此网站用不变更,致曾最爱的人。也许那个人永远都看不到我的这个网站了。
源码文件:
链接:https://pan.baidu.com/s/1XcMeF5f3AD7sEeHaWpYEOQ?pwd=oc79 提取码:oc79
python代码:
import matplotlib.pyplot as pltimport numpy as npfrom decimal import Decimalfrom decimal import getcontextimport timedef heartfunc(x, y): return (x ** 2 + y ** 2 - 1) ** 3 - x ** 2 * y ** 3 <= 0def cal_pi(precision): getcontext().prec = precision return sum(1 / Decimal(16) ** k * (Decimal(4) / (8 * k + 1) - Decimal(2) / (8 * k + 4) - Decimal(1) / (8 * k + 5) - Decimal(1) / (8 * k + 6)) for k in range(precision))def printer(text, delay=0.1314): for ch in text: print(ch, end='', flush=True) time.sleep(delay)if __name__ == '__main__': n = 1314 x = np.linspace(-2, 2, n) y = np.linspace(-2, 2, n) X, Y = np.meshgrid(x, y) plt.contourf(X, Y, heartfunc(X, Y), cmap=plt.cm.autumn)# Colour Query https://matplattlib.org/examples/color/collormaps_reference.html plt.title("5201314") plt.show() loveInPi = str(cal_pi(1314)) heart = ['5', '2', '0', '1', '3', '1', '4'] iloveyou = "5201314" love = "" i, j = 0, 0 while love != iloveyou: if loveInPi[i] == heart[j]: love += loveInPi[i] j += 1 i += 1
python代码:
# coding=gbk"""作者:川川@时间 : 2022/5/20 2:46"""# -*- coding:utf-8 -*-import turtleimport time# 画爱心的顶部def LittleHeart(): for i in range(200): turtle.right(1) turtle.forward(2)# 输入表白的语句,默认I Love youlove = input('请输入表白语句,默认为输入为"I Love you": ')# 输入署名或者赠谁,没有不执行me = input('请输入您心上人的姓名或者昵称: ')if love == '': love = 'I Love you'# 窗口大小turtle.setup(width=800, height=500)# 颜色turtle.color('red', 'pink')# 笔粗细turtle.pensize(5)# 速度turtle.speed(1)# 提笔turtle.up()# 隐藏笔turtle.hideturtle()# 去到的坐标,窗口中心为0,0turtle.goto(0, -180)turtle.showturtle()# 画上线turtle.down()turtle.speed(1)turtle.begin_fill()turtle.left(140)turtle.forward(224)# 调用画爱心左边的顶部LittleHeart()# 调用画爱右边的顶部turtle.left(120)LittleHeart()# 画下线turtle.forward(224)turtle.end_fill()turtle.pensize(5)turtle.up()turtle.hideturtle()# 在心中写字 一次turtle.goto(0, 0)turtle.showturtle()turtle.color('#CD5C5C', 'pink')# 在心中写字 font可以设置字体自己电脑有的都可以设 align开始写字的位置turtle.write(love, font=('gungsuh', 30,), align="center")turtle.up()turtle.hideturtle()time.sleep(2)# 在心中写字 二次turtle.goto(0, 0)turtle.showturtle()turtle.color('red', 'pink')turtle.write(love, font=('gungsuh', 30,), align="center")turtle.up()turtle.hideturtle()# 写署名if me != '': turtle.color('black', 'pink') time.sleep(2) turtle.goto(180, -180) turtle.showturtle() turtle.write(me, font=(20,), align="center", move=True)# 点击窗口关闭window = turtle.Screen()window.exitonclick()
具体文字自行调整,可运行,祝天下有情人终成眷属。当我忙完一天所有事的时候,已经凌晨两点多了,突然想起520这样的日子,发现自己还是一个人过,不过还是希望各位好好珍惜身边拥有,有个爱的你人不容易,好好爱护,不要等到失去才懂得珍惜,我的所有表白系列元素都是她一个人吧。
来源地址:https://blog.csdn.net/weixin_46211269/article/details/124875622
--结束END--
本文标题: 程序员的520花式绘制爱心代码大全
本文链接: https://lsjlt.com/news/410783.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0