提交 a0259ce2 编写于 作者: S sun0225SUN

🚀 update 爱心代码

上级 36b590a8
t=[0:0.1:2*pi] t=[0:0.1:2*pi]
x=16 * sin(t).^3 x=16 * sin(t).^3
y=13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t) y=13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t)
a=(x - min(x))/(max(x) - min(x)) a=(x - min(x))/(max(x) - min(x))
b=(y - min(y))/(max(y) - min(y)) b=(y - min(y))/(max(y) - min(y))
plot(x,y,'r') plot(x,y,'r')
\ No newline at end of file
<img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/001.jpg"/> <img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/001.jpg"/>
% matlab动态心形曲线(保存GIF格式) % matlab动态心形曲线(保存GIF格式)
clc;clear all; clc;clear all;
a=10; a=10;
x=-2:0.01:2; x=-2:0.01:2;
figure(1); figure(1);
set(gcf,'position',[0,0,800,600],'color','w'); set(gcf,'position',[0,0,800,600],'color','w');
for i=1:100 for i=1:100
str_title = strcat('\color{red}a=',num2str(a)); str_title = strcat('\color{red}a=',num2str(a));
y = abs(x).^(2/3)+(0.9*sqrt((3.3-x.^2))).*sin(a*pi*x); y = abs(x).^(2/3)+(0.9*sqrt((3.3-x.^2))).*sin(a*pi*x);
a=i/10; a=i/10;
figure(i); figure(i);
set(gcf,'position',[0,0,800,600],'color','w'); set(gcf,'position',[0,0,800,600],'color','w');
p1 = plot(x,y,'r','LineWidth',3); p1 = plot(x,y,'r','LineWidth',3);
hold on; hold on;
title('\color{red}f(x)=x^2^/^3+e/3*(π-x^2)^1^/^2*sin(a*π*x)','fontsize',15); title('\color{red}f(x)=x^2^/^3+e/3*(π-x^2)^1^/^2*sin(a*π*x)','fontsize',15);
text(-0.2,2.3,str_title,'FontName','Times New Roman','FontSize',20); text(-0.2,2.3,str_title,'FontName','Times New Roman','FontSize',20);
xlim([-2 2]); xlim([-2 2]);
ylim([-1.5 2.5]); ylim([-1.5 2.5]);
frame = getframe(gcf); frame = getframe(gcf);
im = frame2im(frame); im = frame2im(frame);
[I,map] = rgb2ind(im,256); [I,map] = rgb2ind(im,256);
if i==1 if i==1
imwrite(I,map,'心形图.gif','gif','Loopcount',Inf,'DelayTime',0.05); imwrite(I,map,'心形图.gif','gif','Loopcount',Inf,'DelayTime',0.05);
else else
imwrite(I,map,'心形图.gif','gif','WriteMode','append','DelayTime',0.05); imwrite(I,map,'心形图.gif','gif','WriteMode','append','DelayTime',0.05);
end end
close(figure(i)); close(figure(i));
end end
<img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/002.gif"/> <img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/002.gif"/>
f=@(x,y,z)(x.^2+ (9./4).*y.^2 + z.^2 - 1).^3 - x.^2.*z.^3 - (9./80).*y.^2.*z.^3; f=@(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)); [x,y,z]=meshgrid(linspace(-3,3));
val=f(x,y,z); val=f(x,y,z);
[p,v]=isosurface(x,y,z,val,0); [p,v]=isosurface(x,y,z,val,0);
patch('faces',p,'vertices',v,'facevertexcdata',jet(size(v,1)),'facecolor','w','edgecolor','flat'); patch('faces',p,'vertices',v,'facevertexcdata',jet(size(v,1)),'facecolor','w','edgecolor','flat');
view(3);grid on;axis equal; view(3);grid on;axis equal;
\ No newline at end of file
<img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/003.jpg"/> <img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/003.jpg"/>
[X,Y,Z] = meshgrid(-1.2:.02:1.2,-3:.03:3,-1:.02:1.3); [X,Y,Z] = meshgrid(-1.2:.02:1.2,-3:.03:3,-1:.02:1.3);
f = smooth3((X.^2+9*Y.^2/9+Z.^2-1).^3-X.^2.*Z.^3-Y.^2.*Z.^3/20,'gauss'); f = smooth3((X.^2+9*Y.^2/9+Z.^2-1).^3-X.^2.*Z.^3-Y.^2.*Z.^3/20,'gauss');
v = uniquetol(getfield(isosurface(X,Y,Z,f,0),'vertices'),.15,'byrows',1); v = uniquetol(getfield(isosurface(X,Y,Z,f,0),'vertices'),.15,'byrows',1);
n = isonormals(X,Y,Z,f,v); n = isonormals(X,Y,Z,f,v);
ar = bsxfun(@rdivide,n*[0 -1 0;1 0 0;0 0 0],sqrt(sum(n.^2,2))); ar = bsxfun(@rdivide,n*[0 -1 0;1 0 0;0 0 0],sqrt(sum(n.^2,2)));
[x,t] = meshgrid(0:.125:1,(-2:.2:10)*pi); [x,t] = meshgrid(0:.125:1,(-2:.2:10)*pi);
[p,q] = deal(pi/2*exp(-t/(8*pi)),1-(1-mod(3.6*t,2*pi)/pi).^4/2); [p,q] = deal(pi/2*exp(-t/(8*pi)),1-(1-mod(3.6*t,2*pi)/pi).^4/2);
y = 2*(x.^2-x).^2.*sin(p); y = 2*(x.^2-x).^2.*sin(p);
[p,q] = deal(q.*(x.*sin(p)+y.*cos(p)),q.*(x.*cos(p)-y.*sin(p))); [p,q] = deal(q.*(x.*sin(p)+y.*cos(p)),q.*(x.*cos(p)-y.*sin(p)));
figure color w, axis image vis3d off figure color w, axis image vis3d off
h = surface(p.*cos(t),p.*sin(t),q,'EdgeColor','n','FaceColor','r'); h = surface(p.*cos(t),p.*sin(t),q,'EdgeColor','n','FaceColor','r');
arrayfun(@(t,i)copyobj(h,hgtransform('Mat',makehgtform('translate',5*v(i,:),... arrayfun(@(t,i)copyobj(h,hgtransform('Mat',makehgtform('translate',5*v(i,:),...
'axisrotate',ar(i,:),t))),asin(sqrt(sum(ar.^2,2)))',1:size(v,1)) 'axisrotate',ar(i,:),t))),asin(sqrt(sum(ar.^2,2)))',1:size(v,1))
view(32,12), set(camlight('head'),'color',[1 0.84 0.6]), lighting gouraud view(32,12), set(camlight('head'),'color',[1 0.84 0.6]), lighting gouraud
\ No newline at end of file
<img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/004.jpg"/> <img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/004.jpg"/>
<img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/005.jpg"/> <img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/005.jpg"/>
f=@(x,y,z)(x.^2+ (9./4).*y.^2 + z.^2 - 1).^3 - x.^2.*z.^3 - (9./80).*y.^2.*z.^3; f=@(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(-1.5,1.5)); [x,y,z]=meshgrid(linspace(-1.5,1.5));
val=f(x,y,z); val=f(x,y,z);
isosurface(x,y,z,val,0); isosurface(x,y,z,val,0);
axis equal;view(3);colormap([1 0.2 0.2]) axis equal;view(3);colormap([1 0.2 0.2])
%跳动爱心 %跳动爱心
clear; clc; close all; clear; clc; close all;
% NOTICE: Your MATLAB version should be at least R2019a ! % NOTICE: Your MATLAB version should be at least R2019a !
% --------------------------- functions ------------------------------- % --------------------------- functions -------------------------------
f = @(x, y, z)(x.^2 + 2.25*y.^2 + z.^2 - 1).^3 - ... f = @(x, y, z)(x.^2 + 2.25*y.^2 + z.^2 - 1).^3 - ...
x.^2.* z.^3 - 0.1125*y.^2.*z.^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; g = @(x, y, z)(sqrt(x.^2+y.^2)-2.5).^2 + z.^2 - 0.4^2;
% -------------------------- generate data ---------------------------- % -------------------------- generate data ----------------------------
t = linspace(-5, 5); t = linspace(-5, 5);
[x1, y1, z1] = meshgrid(t); [x1, y1, z1] = meshgrid(t);
[x2, y2, z2] = meshgrid(t); [x2, y2, z2] = meshgrid(t);
val1 = f(x1, y1, z1); val1 = f(x1, y1, z1);
val2 = g(x2, y2, z2); val2 = g(x2, y2, z2);
[p1, v1] = isosurface(x1, y1, z1, val1, 0); [p1, v1] = isosurface(x1, y1, z1, val1, 0);
[p2, v2] = isosurface(x2, y2, z2, val2, 0); [p2, v2] = isosurface(x2, y2, z2, val2, 0);
% --------------------------- basic plot ------------------------------ % --------------------------- basic plot ------------------------------
figure() figure()
subplot(1, 1, 1) subplot(1, 1, 1)
h = patch('faces',p1,'vertices',v1,'facevertexcdata',jet(size(v1,1)),... h = patch('faces',p1,'vertices',v1,'facevertexcdata',jet(size(v1,1)),...
'facecolor','w','edgecolor','flat'); hold on; 'facecolor','w','edgecolor','flat'); hold on;
patch('faces',p2,'vertices',v2,'facevertexcdata',jet(size(v2,1)),... patch('faces',p2,'vertices',v2,'facevertexcdata',jet(size(v2,1)),...
'facecolor','w','edgecolor','flat'); 'facecolor','w','edgecolor','flat');
grid on; axis equal; axis([-3,3,-3,3,-1.5,1.5]); view(3) 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$",... 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]) "$(\sqrt{x^2+y^2}-R)^2 +z^2 = r^2$"],'Interpreter','latex','position',[3.3,4])
warning('off'); warning('off');
% 请在此处进行您的演讲!% 请在此处进行您的演讲! % 请在此处进行您的演讲!% 请在此处进行您的演讲!
T = suptitle("$I\ Love\ U\ !$"); T = suptitle("$I\ Love\ U\ !$");
% 请在此处进行您的演讲!% 请在此处进行您的演讲! % 请在此处进行您的演讲!% 请在此处进行您的演讲!
set(T,'Interpreter','latex','FontSize',24) set(T,'Interpreter','latex','FontSize',24)
% -------------------------- generate gif ----------------------------- % -------------------------- generate gif -----------------------------
pic_num = 1; pic_num = 1;
for i = 1:20 for i = 1:20
v1 = 0.98 * v1; v1 = 0.98 * v1;
set(h, 'vertices', v1); drawnow; set(h, 'vertices', v1); drawnow;
F = getframe(gcf); F = getframe(gcf);
I = frame2im(F); I = frame2im(F);
[I,map]=rgb2ind(I,256); [I,map]=rgb2ind(I,256);
if pic_num == 1 if pic_num == 1
imwrite(I,map,'BeatingHeart.gif','gif','Loopcount',inf,'DelayTime',0.05); imwrite(I,map,'BeatingHeart.gif','gif','Loopcount',inf,'DelayTime',0.05);
else else
imwrite(I,map,'BeatingHeart.gif','gif','WriteMode','append','DelayTime',0.05); imwrite(I,map,'BeatingHeart.gif','gif','WriteMode','append','DelayTime',0.05);
end end
pic_num = pic_num + 1; pic_num = pic_num + 1;
end end
for i = 1:20 for i = 1:20
v1 = v1 / 0.98; v1 = v1 / 0.98;
set(h, 'vertices', v1); drawnow; set(h, 'vertices', v1); drawnow;
F = getframe(gcf); F = getframe(gcf);
I = frame2im(F); I = frame2im(F);
[I,map] = rgb2ind(I,256); [I,map] = rgb2ind(I,256);
imwrite(I,map,'BeatingHeart.gif','gif','WriteMode','append','DelayTime',0.05); imwrite(I,map,'BeatingHeart.gif','gif','WriteMode','append','DelayTime',0.05);
pic_num = pic_num + 1; pic_num = pic_num + 1;
end end
% ----------------------------- dynamic ------------------------------- % ----------------------------- dynamic -------------------------------
while true while true
for i = 1:20 for i = 1:20
v1 = 0.98 * v1; v1 = 0.98 * v1;
set(h, 'vertices', v1); drawnow; set(h, 'vertices', v1); drawnow;
end end
for i = 1:20 for i = 1:20
v1 = v1 / 0.98; v1 = v1 / 0.98;
set(h, 'vertices', v1); drawnow; set(h, 'vertices', v1); drawnow;
end end
end end
% ------------------------------- end --------------------------------- % ------------------------------- end ---------------------------------
<img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/006.jpg"/> <img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/006.jpg"/>
<img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/007.jpg"/> <img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/007.jpg"/>
function rose function rose
grid on grid on
[x,t]=meshgrid((0:24)./24,(0:0.5:575)./575.*20.*pi-4*pi); [x,t]=meshgrid((0:24)./24,(0:0.5:575)./575.*20.*pi-4*pi);
p=(pi/2)*exp(-t./(8*pi)); p=(pi/2)*exp(-t./(8*pi));
change=sin(20*t)/150; change=sin(20*t)/150;
u=1-(1-mod(3.3*t,2*pi)./pi).^4./2+change; u=1-(1-mod(3.3*t,2*pi)./pi).^4./2+change;
y=2*(x.^2-x).^2.*sin(p); y=2*(x.^2-x).^2.*sin(p);
r=u.*(x.*sin(p)+y.*cos(p)).*1.5; r=u.*(x.*sin(p)+y.*cos(p)).*1.5;
h=u.*(x.*cos(p)-y.*sin(p)); h=u.*(x.*cos(p)-y.*sin(p));
map=[1.0000 0.6471 0.8275 map=[1.0000 0.6471 0.8275
0.9984 0.6353 0.8130 0.9984 0.6353 0.8130
0.9969 0.6236 0.7985 0.9969 0.6236 0.7985
0.9953 0.6118 0.7840 0.9953 0.6118 0.7840
0.9937 0.6000 0.7695 0.9937 0.6000 0.7695
0.9921 0.5882 0.7550 0.9921 0.5882 0.7550
0.9906 0.5765 0.7404 0.9906 0.5765 0.7404
0.9890 0.5647 0.7259 0.9890 0.5647 0.7259
0.9874 0.5529 0.7114 0.9874 0.5529 0.7114
0.9859 0.5412 0.6969 0.9859 0.5412 0.6969
0.9843 0.5294 0.6824 0.9843 0.5294 0.6824
0.9757 0.5149 0.6730 0.9757 0.5149 0.6730
0.9670 0.5004 0.6636 0.9670 0.5004 0.6636
0.9584 0.4859 0.6541 0.9584 0.4859 0.6541
0.9498 0.4714 0.6447 0.9498 0.4714 0.6447
0.9411 0.4568 0.6353 0.9411 0.4568 0.6353
0.9325 0.4423 0.6259 0.9325 0.4423 0.6259
0.9239 0.4278 0.6165 0.9239 0.4278 0.6165
0.9153 0.4133 0.6070 0.9153 0.4133 0.6070
0.9066 0.3988 0.5976 0.9066 0.3988 0.5976
0.8980 0.3843 0.5882 0.8980 0.3843 0.5882
0.8937 0.3780 0.5756 0.8937 0.3780 0.5756
0.8894 0.3718 0.5631 0.8894 0.3718 0.5631
0.8851 0.3655 0.5505 0.8851 0.3655 0.5505
0.8808 0.3592 0.5380 0.8808 0.3592 0.5380
0.8764 0.3529 0.5254 0.8764 0.3529 0.5254
0.8721 0.3467 0.5129 0.8721 0.3467 0.5129
0.8678 0.3404 0.5003 0.8678 0.3404 0.5003
0.8635 0.3341 0.4878 0.8635 0.3341 0.4878
0.8592 0.3279 0.4752 0.8592 0.3279 0.4752
0.8549 0.3216 0.4627 0.8549 0.3216 0.4627
0.8561 0.3165 0.4596 0.8561 0.3165 0.4596
0.8573 0.3114 0.4564 0.8573 0.3114 0.4564
0.8584 0.3063 0.4533 0.8584 0.3063 0.4533
0.8596 0.3012 0.4502 0.8596 0.3012 0.4502
0.8608 0.2961 0.4471 0.8608 0.2961 0.4471
0.8620 0.2910 0.4439 0.8620 0.2910 0.4439
0.8632 0.2859 0.4408 0.8632 0.2859 0.4408
0.8643 0.2808 0.4377 0.8643 0.2808 0.4377
0.8655 0.2757 0.4345 0.8655 0.2757 0.4345
0.8667 0.2706 0.4314 0.8667 0.2706 0.4314
0.8549 0.2620 0.4165 0.8549 0.2620 0.4165
0.8432 0.2533 0.4016 0.8432 0.2533 0.4016
0.8314 0.2447 0.3867 0.8314 0.2447 0.3867
0.8196 0.2361 0.3718 0.8196 0.2361 0.3718
0.8078 0.2274 0.3569 0.8078 0.2274 0.3569
0.7961 0.2188 0.3420 0.7961 0.2188 0.3420
0.7843 0.2102 0.3271 0.7843 0.2102 0.3271
0.7725 0.2016 0.3122 0.7725 0.2016 0.3122
0.7608 0.1929 0.2973 0.7608 0.1929 0.2973
0.7490 0.1843 0.2824 0.7490 0.1843 0.2824
0.7553 0.1827 0.2855 0.7553 0.1827 0.2855
0.7616 0.1812 0.2887 0.7616 0.1812 0.2887
0.7678 0.1796 0.2918 0.7678 0.1796 0.2918
0.7741 0.1780 0.2949 0.7741 0.1780 0.2949
0.7804 0.1764 0.2980 0.7804 0.1764 0.2980
0.7867 0.1749 0.3012 0.7867 0.1749 0.3012
0.7930 0.1733 0.3043 0.7930 0.1733 0.3043
0.7992 0.1717 0.3074 0.7992 0.1717 0.3074
0.8055 0.1702 0.3106 0.8055 0.1702 0.3106
0.8118 0.1686 0.3137 0.8118 0.1686 0.3137
0.7977 0.1631 0.3023 0.7977 0.1631 0.3023
0.7836 0.1576 0.2910 0.7836 0.1576 0.2910
0.7694 0.1521 0.2796 0.7694 0.1521 0.2796
0.7553 0.1466 0.2682 0.7553 0.1466 0.2682
0.7412 0.1411 0.2569 0.7412 0.1411 0.2569
0.7271 0.1357 0.2455 0.7271 0.1357 0.2455
0.7130 0.1302 0.2341 0.7130 0.1302 0.2341
0.6988 0.1247 0.2227 0.6988 0.1247 0.2227
0.6847 0.1192 0.2114 0.6847 0.1192 0.2114
0.6706 0.1137 0.2000 0.6706 0.1137 0.2000
0.6686 0.1141 0.1996 0.6686 0.1141 0.1996
0.6667 0.1145 0.1992 0.6667 0.1145 0.1992
0.6647 0.1149 0.1988 0.6647 0.1149 0.1988
0.6628 0.1153 0.1984 0.6628 0.1153 0.1984
0.6608 0.1157 0.1981 0.6608 0.1157 0.1981
0.6588 0.1160 0.1977 0.6588 0.1160 0.1977
0.6569 0.1164 0.1973 0.6569 0.1164 0.1973
0.6549 0.1168 0.1969 0.6549 0.1168 0.1969
0.6530 0.1172 0.1965 0.6530 0.1172 0.1965
0.6510 0.1176 0.1961]; 0.6510 0.1176 0.1961];
set(gca,'CameraPosition',[2 2 2]) set(gca,'CameraPosition',[2 2 2])
hold on hold on
Xset=r.*cos(t);Yset=r.*sin(t); Xset=r.*cos(t);Yset=r.*sin(t);
sf=surface(Xset,Yset,h,'EdgeAlpha',0.1,... sf=surface(Xset,Yset,h,'EdgeAlpha',0.1,...
'EdgeColor',[0.5 0.5 0.5],'FaceColor','interp'); 'EdgeColor',[0.5 0.5 0.5],'FaceColor','interp');
colormap(map) colormap(map)
theta=0; theta=0;
while 1 while 1
theta=theta+0.02; theta=theta+0.02;
set(sf,'XData',Xset.*cos(theta)-Yset.*sin(theta),... set(sf,'XData',Xset.*cos(theta)-Yset.*sin(theta),...
'YData',Xset.*sin(theta)+Yset.*cos(theta)) 'YData',Xset.*sin(theta)+Yset.*cos(theta))
pause(0.01) pause(0.01)
end end
end end
<img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/008.jpg"/> <img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/008.jpg"/>
function roseBall function roseBall
clear;clc clear;clc
%曲面数据计算 %曲面数据计算
%========================================================================== %==========================================================================
[x,t]=meshgrid((0:24)./24,(0:0.5:575)./575.*20.*pi+4*pi); [x,t]=meshgrid((0:24)./24,(0:0.5:575)./575.*20.*pi+4*pi);
p=(pi/2)*exp(-t./(8*pi)); p=(pi/2)*exp(-t./(8*pi));
change=sin(15*t)/150; change=sin(15*t)/150;
u=1-(1-mod(3.6*t,2*pi)./pi).^4./2+change; u=1-(1-mod(3.6*t,2*pi)./pi).^4./2+change;
y=2*(x.^2-x).^2.*sin(p); y=2*(x.^2-x).^2.*sin(p);
r=u.*(x.*sin(p)+y.*cos(p)); r=u.*(x.*sin(p)+y.*cos(p));
h=u.*(x.*cos(p)-y.*sin(p)); h=u.*(x.*cos(p)-y.*sin(p));
%颜色映射表 %颜色映射表
%========================================================================== %==========================================================================
hMap=(h-min(min(h)))./(max(max(h))-min(min(h))); hMap=(h-min(min(h)))./(max(max(h))-min(min(h)));
col=size(hMap,2); col=size(hMap,2);
colorList=[0.0200 0.0400 0.3900 colorList=[0.0200 0.0400 0.3900
0 0.0900 0.5800 0 0.0900 0.5800
0 0.1300 0.6400 0 0.1300 0.6400
0.0200 0.0600 0.6900 0.0200 0.0600 0.6900
0 0.0800 0.7900 0 0.0800 0.7900
0.0100 0.1800 0.8500 0.0100 0.1800 0.8500
0 0.1300 0.9600 0 0.1300 0.9600
0.0100 0.2600 0.9900 0.0100 0.2600 0.9900
0 0.3500 0.9900 0 0.3500 0.9900
0.0700 0.6200 1.0000 0.0700 0.6200 1.0000
0.1700 0.6900 1.0000]; 0.1700 0.6900 1.0000];
% colorList=[0.2100 0.0900 0.3800 % colorList=[0.2100 0.0900 0.3800
% 0.2900 0.0700 0.4700 % 0.2900 0.0700 0.4700
% 0.4000 0.1100 0.4900 % 0.4000 0.1100 0.4900
% 0.5500 0.1600 0.5100 % 0.5500 0.1600 0.5100
% 0.7500 0.2400 0.4700 % 0.7500 0.2400 0.4700
% 0.8900 0.3200 0.4100 % 0.8900 0.3200 0.4100
% 0.9700 0.4900 0.3700 % 0.9700 0.4900 0.3700
% 1.0000 0.5600 0.4100 % 1.0000 0.5600 0.4100
% 1.0000 0.6900 0.4900 % 1.0000 0.6900 0.4900
% 1.0000 0.8200 0.5900 % 1.0000 0.8200 0.5900
% 0.9900 0.9200 0.6700 % 0.9900 0.9200 0.6700
% 0.9800 0.9500 0.7100]; % 0.9800 0.9500 0.7100];
% colorList1=[0.2000 0.0800 0.4300 % colorList1=[0.2000 0.0800 0.4300
% 0.2000 0.1300 0.4600 % 0.2000 0.1300 0.4600
% 0.2000 0.2100 0.5000 % 0.2000 0.2100 0.5000
% 0.2000 0.2800 0.5300 % 0.2000 0.2800 0.5300
% 0.2000 0.3700 0.5800 % 0.2000 0.3700 0.5800
% 0.1900 0.4500 0.6200 % 0.1900 0.4500 0.6200
% 0.2000 0.4800 0.6400 % 0.2000 0.4800 0.6400
% 0.1900 0.5400 0.6700 % 0.1900 0.5400 0.6700
% 0.1900 0.5700 0.6900 % 0.1900 0.5700 0.6900
% 0.1900 0.7500 0.7800 % 0.1900 0.7500 0.7800
% 0.1900 0.8000 0.8100 % 0.1900 0.8000 0.8100
% ]; % ];
% colorList2=[0.1300 0.1000 0.1600 % colorList2=[0.1300 0.1000 0.1600
% 0.2000 0.0900 0.2000 % 0.2000 0.0900 0.2000
% 0.2800 0.0800 0.2300 % 0.2800 0.0800 0.2300
% 0.4200 0.0800 0.3000 % 0.4200 0.0800 0.3000
% 0.5100 0.0700 0.3400 % 0.5100 0.0700 0.3400
% 0.6600 0.1200 0.3500 % 0.6600 0.1200 0.3500
% 0.7900 0.2200 0.4000 % 0.7900 0.2200 0.4000
% 0.8800 0.3500 0.4700 % 0.8800 0.3500 0.4700
% 0.9000 0.4500 0.5400 % 0.9000 0.4500 0.5400
% 0.8900 0.7800 0.7900 % 0.8900 0.7800 0.7900
% ]; % ];
% colorList3=[0.3200 0.3100 0.7600 % colorList3=[0.3200 0.3100 0.7600
% 0.3800 0.3400 0.7600 % 0.3800 0.3400 0.7600
% 0.5300 0.4200 0.7500 % 0.5300 0.4200 0.7500
% 0.6400 0.4900 0.7300 % 0.6400 0.4900 0.7300
% 0.7200 0.5500 0.7200 % 0.7200 0.5500 0.7200
% 0.7900 0.6100 0.7100 % 0.7900 0.6100 0.7100
% 0.9100 0.7100 0.6800 % 0.9100 0.7100 0.6800
% 0.9800 0.7600 0.6700 % 0.9800 0.7600 0.6700
% ]; % ];
% colorList4=[0.9500 0.2300 0.6600 % colorList4=[0.9500 0.2300 0.6600
% 0.7500 0.2100 0.6000 % 0.7500 0.2100 0.6000
% 0.6200 0.2000 0.5700 % 0.6200 0.2000 0.5700
% 0.4500 0.1800 0.5200 % 0.4500 0.1800 0.5200
% 0.3200 0.2100 0.5200 % 0.3200 0.2100 0.5200
% 0.2700 0.3100 0.6000 % 0.2700 0.3100 0.6000
% 0.2500 0.3600 0.6400 % 0.2500 0.3600 0.6400
% 0.1900 0.4800 0.7400 % 0.1900 0.4800 0.7400
% ]; % ];
colorFunc=colorFuncFactory(colorList); colorFunc=colorFuncFactory(colorList);
dataMap=colorFunc(hMap'); dataMap=colorFunc(hMap');
colorMap(:,:,1)=dataMap(:,1:col); colorMap(:,:,1)=dataMap(:,1:col);
colorMap(:,:,2)=dataMap(:,col+1:2*col); colorMap(:,:,2)=dataMap(:,col+1:2*col);
colorMap(:,:,3)=dataMap(:,2*col+1:3*col); colorMap(:,:,3)=dataMap(:,2*col+1:3*col);
function colorFunc=colorFuncFactory(colorList) function colorFunc=colorFuncFactory(colorList)
xx=(0:size(colorList,1)-1)./(size(colorList,1)-1); xx=(0:size(colorList,1)-1)./(size(colorList,1)-1);
y1=colorList(:,1);y2=colorList(:,2);y3=colorList(:,3); y1=colorList(:,1);y2=colorList(:,2);y3=colorList(:,3);
colorFunc=@(X)[interp1(xx,y1,X,'linear')',interp1(xx,y2,X,'linear')',interp1(xx,y3,X,'linear')']; colorFunc=@(X)[interp1(xx,y1,X,'linear')',interp1(xx,y2,X,'linear')',interp1(xx,y3,X,'linear')'];
end end
%曲面旋转及绘制 %曲面旋转及绘制
%========================================================================== %==========================================================================
surface(r.*cos(t),r.*sin(t),h+0.35,'EdgeAlpha',0.05,... surface(r.*cos(t),r.*sin(t),h+0.35,'EdgeAlpha',0.05,...
'EdgeColor',[0 0 0],'FaceColor','interp','CData',colorMap) 'EdgeColor',[0 0 0],'FaceColor','interp','CData',colorMap)
hold on hold on
surface(r.*cos(t),r.*sin(t),-h-0.35,'EdgeAlpha',0.05,... surface(r.*cos(t),r.*sin(t),-h-0.35,'EdgeAlpha',0.05,...
'EdgeColor',[0 0 0],'FaceColor','interp','CData',colorMap) 'EdgeColor',[0 0 0],'FaceColor','interp','CData',colorMap)
Xset=r.*cos(t); Xset=r.*cos(t);
Yset=r.*sin(t); Yset=r.*sin(t);
Zset=h+0.35; Zset=h+0.35;
yaw_z=pi*72/180; yaw_z=pi*72/180;
roll_x=pi-acos(-1/sqrt(5)); roll_x=pi-acos(-1/sqrt(5));
R_z_2=[cos(yaw_z),-sin(yaw_z),0; R_z_2=[cos(yaw_z),-sin(yaw_z),0;
sin(yaw_z),cos(yaw_z),0; sin(yaw_z),cos(yaw_z),0;
0,0,1]; 0,0,1];
R_z_1=[cos(yaw_z/2),-sin(yaw_z/2),0; R_z_1=[cos(yaw_z/2),-sin(yaw_z/2),0;
sin(yaw_z/2),cos(yaw_z/2),0; sin(yaw_z/2),cos(yaw_z/2),0;
0,0,1]; 0,0,1];
R_x_2=[1,0,0; R_x_2=[1,0,0;
0,cos(roll_x),-sin(roll_x); 0,cos(roll_x),-sin(roll_x);
0,sin(roll_x),cos(roll_x)]; 0,sin(roll_x),cos(roll_x)];
[nX,nY,nZ]=rotateXYZ(Xset,Yset,Zset,R_x_2); [nX,nY,nZ]=rotateXYZ(Xset,Yset,Zset,R_x_2);
surface(nX,nY,nZ,'EdgeAlpha',0.05,... surface(nX,nY,nZ,'EdgeAlpha',0.05,...
'EdgeColor',[0 0 0],'FaceColor','interp','CData',colorMap) 'EdgeColor',[0 0 0],'FaceColor','interp','CData',colorMap)
for k=1:4 for k=1:4
[nX,nY,nZ]=rotateXYZ(nX,nY,nZ,R_z_2); [nX,nY,nZ]=rotateXYZ(nX,nY,nZ,R_z_2);
surface(nX,nY,nZ,'EdgeAlpha',0.05,... surface(nX,nY,nZ,'EdgeAlpha',0.05,...
'EdgeColor',[0 0 0],'FaceColor','interp','CData',colorMap) 'EdgeColor',[0 0 0],'FaceColor','interp','CData',colorMap)
end end
[nX,nY,nZ]=rotateXYZ(nX,nY,nZ,R_z_1); [nX,nY,nZ]=rotateXYZ(nX,nY,nZ,R_z_1);
for k=1:5 for k=1:5
[nX,nY,nZ]=rotateXYZ(nX,nY,nZ,R_z_2); [nX,nY,nZ]=rotateXYZ(nX,nY,nZ,R_z_2);
surface(nX,nY,-nZ,'EdgeAlpha',0.05,... surface(nX,nY,-nZ,'EdgeAlpha',0.05,...
'EdgeColor',[0 0 0],'FaceColor','interp','CData',colorMap) 'EdgeColor',[0 0 0],'FaceColor','interp','CData',colorMap)
end end
%-------------------------------------------------------------------------- %--------------------------------------------------------------------------
function [nX,nY,nZ]=rotateXYZ(X,Y,Z,R) function [nX,nY,nZ]=rotateXYZ(X,Y,Z,R)
nX=zeros(size(X)); nX=zeros(size(X));
nY=zeros(size(Y)); nY=zeros(size(Y));
nZ=zeros(size(Z)); nZ=zeros(size(Z));
for i=1:size(X,1) for i=1:size(X,1)
for j=1:size(X,2) for j=1:size(X,2)
v=[X(i,j);Y(i,j);Z(i,j)]; v=[X(i,j);Y(i,j);Z(i,j)];
nv=R*v; nv=R*v;
nX(i,j)=nv(1); nX(i,j)=nv(1);
nY(i,j)=nv(2); nY(i,j)=nv(2);
nZ(i,j)=nv(3); nZ(i,j)=nv(3);
end end
end end
end end
%axes属性调整 %axes属性调整
%========================================================================== %==========================================================================
ax=gca; ax=gca;
grid on grid on
ax.GridLineStyle='--'; ax.GridLineStyle='--';
ax.LineWidth=1.2; ax.LineWidth=1.2;
ax.XColor=[1,1,1].*0.4; ax.XColor=[1,1,1].*0.4;
ax.YColor=[1,1,1].*0.4; ax.YColor=[1,1,1].*0.4;
ax.ZColor=[1,1,1].*0.4; ax.ZColor=[1,1,1].*0.4;
ax.DataAspectRatio=[1,1,1]; ax.DataAspectRatio=[1,1,1];
ax.DataAspectRatioMode='manual'; ax.DataAspectRatioMode='manual';
ax.CameraPosition=[-6.5914 -24.1625 -0.0384]; ax.CameraPosition=[-6.5914 -24.1625 -0.0384];
end end
function LoveFunc function LoveFunc
LoveFunchdl=@(x,a)(x.^2).^(1/3)+0.9.*((3.3-x.^2).^(1/2)).*sin(a.*pi.*x); LoveFunchdl=@(x,a)(x.^2).^(1/3)+0.9.*((3.3-x.^2).^(1/2)).*sin(a.*pi.*x);
hold on hold on
grid on grid on
axis([-3 3,-2 4]) axis([-3 3,-2 4])
x=-1.8:0.005:1.8; x=-1.8:0.005:1.8;
text(0,3.3,'$f(x)=x^{\frac{2}{3}}+0.9(3.3-x^2)^{\frac{1}{2}}\sin(\alpha\pi x)$',... text(0,3.3,'$f(x)=x^{\frac{2}{3}}+0.9(3.3-x^2)^{\frac{1}{2}}\sin(\alpha\pi x)$',...
'FontSize',13,'HorizontalAlignment','center','Interpreter','latex'); 'FontSize',13,'HorizontalAlignment','center','Interpreter','latex');
txt2=text(-0.35,2.9,'','FontSize',13,'HorizontalAlignment','left','Interpreter','latex','tag','alphadata'); txt2=text(-0.35,2.9,'','FontSize',13,'HorizontalAlignment','left','Interpreter','latex','tag','alphadata');
for a=1:0.01:20 for a=1:0.01:20
delete(findobj('type','line')) delete(findobj('type','line'))
AlphaString=['$\alpha=',num2str(a),'$']; AlphaString=['$\alpha=',num2str(a),'$'];
Color=([1.0000 0.4902 0.6627]-[0.2118 0.4667 0.9961]).*(a/20)+[0.2118 0.4667 0.9961]; Color=([1.0000 0.4902 0.6627]-[0.2118 0.4667 0.9961]).*(a/20)+[0.2118 0.4667 0.9961];
set(txt2,'string',AlphaString) set(txt2,'string',AlphaString)
plot(x,LoveFunchdl(x,a),'color',Color,'LineWidth',1.2); plot(x,LoveFunchdl(x,a),'color',Color,'LineWidth',1.2);
pause(0.003) pause(0.003)
end end
end end
<img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/009.jpg"/> <img src="https://cdn.jsdelivr.net/gh/sun0225SUN/Awesome-Love-Code/assets/img/matlab/009.jpg"/>
# coding:utf-8 # coding:utf-8
import sys import sys
import os import os
import random import random
import pygame import pygame
from pygame.locals import * from pygame.locals import *
WIDTH, HEIGHT = 640, 480 WIDTH, HEIGHT = 640, 480
BACKGROUND = (255, 255, 255) BACKGROUND = (255, 255, 255)
def button(text, x, y, w, h, color, screen, size): def button(text, x, y, w, h, color, screen, size):
pygame.draw.rect(screen, color, (x, y, w, h)) pygame.draw.rect(screen, color, (x, y, w, h))
font = pygame.font.Font('carton.ttf', size) font = pygame.font.Font('carton.ttf', size)
textRender = font.render(text, True, (0, 0, 0)) textRender = font.render(text, True, (0, 0, 0))
textRect = textRender.get_rect() textRect = textRender.get_rect()
textRect.center = ((x+w/2), (y+h/2)) textRect.center = ((x+w/2), (y+h/2))
screen.blit(textRender, textRect) screen.blit(textRender, textRect)
def title(text, screen, scale, color=(0, 0, 0)): def title(text, screen, scale, color=(0, 0, 0)):
font = pygame.font.Font('carton.ttf', WIDTH//(len(text)*2)) font = pygame.font.Font('carton.ttf', WIDTH//(len(text)*2))
textRender = font.render(text, True, color) textRender = font.render(text, True, color)
textRect = textRender.get_rect() textRect = textRender.get_rect()
textRect.midtop = (WIDTH/scale[0], HEIGHT/scale[1]) textRect.midtop = (WIDTH/scale[0], HEIGHT/scale[1])
screen.blit(textRender, textRect) screen.blit(textRender, textRect)
def get_random_pos(): def get_random_pos():
x, y = random.randint(20, 620), random.randint(20, 460) x, y = random.randint(20, 620), random.randint(20, 460)
return x, y return x, y
def show_like_interface(text, screen, color=(255, 0, 0)): def show_like_interface(text, screen, color=(255, 0, 0)):
screen.fill(BACKGROUND) screen.fill(BACKGROUND)
font = pygame.font.Font('carton.ttf', WIDTH//(len(text))) font = pygame.font.Font('carton.ttf', WIDTH//(len(text)))
textRender = font.render(text, True, color) textRender = font.render(text, True, color)
textRect = textRender.get_rect() textRect = textRender.get_rect()
textRect.midtop = (WIDTH/2, HEIGHT/2) textRect.midtop = (WIDTH/2, HEIGHT/2)
screen.blit(textRender, textRect) screen.blit(textRender, textRect)
pygame.display.update() pygame.display.update()
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == QUIT: if event.type == QUIT:
pygame.quit() pygame.quit()
sys.exit() sys.exit()
def show_like_interface1(screen): def show_like_interface1(screen):
screen.fill(BACKGROUND) screen.fill(BACKGROUND)
img3 = pygame.image.load("3.png") img3 = pygame.image.load("3.png")
imgRect = img3.get_rect() imgRect = img3.get_rect()
imgRect.midtop = WIDTH // 2, HEIGHT // 4 imgRect.midtop = WIDTH // 2, HEIGHT // 4
screen.blit(img3, imgRect) screen.blit(img3, imgRect)
pygame.display.update() pygame.display.update()
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == QUIT: if event.type == QUIT:
pygame.quit() pygame.quit()
sys.exit() sys.exit()
def show_like_interface2(text, screen, color=(255, 0, 0)): def show_like_interface2(text, screen, color=(255, 0, 0)):
screen.fill(BACKGROUND) screen.fill(BACKGROUND)
font = pygame.font.Font('carton.ttf', WIDTH//(len(text))) font = pygame.font.Font('carton.ttf', WIDTH//(len(text)))
textRender = font.render(text, True, color) textRender = font.render(text, True, color)
textRect = textRender.get_rect() textRect = textRender.get_rect()
textRect.midtop = (WIDTH/2, HEIGHT/2) textRect.midtop = (WIDTH/2, HEIGHT/2)
screen.blit(textRender, textRect) screen.blit(textRender, textRect)
pygame.display.update() pygame.display.update()
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == QUIT: if event.type == QUIT:
pygame.quit() pygame.quit()
sys.exit() sys.exit()
def main(): def main():
pygame.init() pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32) screen = pygame.display.set_mode((WIDTH, HEIGHT), 0, 32)
pygame.display.set_caption('来自一个喜欢你很久的小哥哥') pygame.display.set_caption('来自一个喜欢你很久的小哥哥')
clock = pygame.time.Clock() clock = pygame.time.Clock()
unlike_x_pos,unlike_y_pos = 370,380 unlike_x_pos,unlike_y_pos = 370,380
unlike_pos_width, unlike_pos_height = 100,50 unlike_pos_width, unlike_pos_height = 100,50
like_x_pos,like_y_pos = 180,370 like_x_pos,like_y_pos = 180,370
like_pos_width,like_pos_height = 100,50 like_pos_width,like_pos_height = 100,50
running = True running = True
button_color = (192, 192, 192) button_color = (192, 192, 192)
while running: while running:
screen.fill(BACKGROUND) screen.fill(BACKGROUND)
img = pygame.image.load("1.png") img = pygame.image.load("1.png")
imgRect = img.get_rect() imgRect = img.get_rect()
imgRect.midtop = WIDTH//2, HEIGHT//4 imgRect.midtop = WIDTH//2, HEIGHT//4
screen.blit(img, imgRect) screen.blit(img, imgRect)
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN: if event.type == pygame.MOUSEBUTTONDOWN:
mouse_pos = pygame.mouse.get_pos() mouse_pos = pygame.mouse.get_pos()
if mouse_pos[0] < like_x_pos+like_pos_width+5 and mouse_pos[0] > like_x_pos-5 and\ if mouse_pos[0] < like_x_pos+like_pos_width+5 and mouse_pos[0] > like_x_pos-5 and\
mouse_pos[1] < like_y_pos+like_pos_height+5 and mouse_pos[1] > like_y_pos-5: mouse_pos[1] < like_y_pos+like_pos_height+5 and mouse_pos[1] > like_y_pos-5:
button_color = BACKGROUND button_color = BACKGROUND
running = False running = False
mouse_pos = pygame.mouse.get_pos() mouse_pos = pygame.mouse.get_pos()
if mouse_pos[0] < unlike_x_pos+unlike_pos_width+5 and mouse_pos[0] > unlike_x_pos-5 and\ if mouse_pos[0] < unlike_x_pos+unlike_pos_width+5 and mouse_pos[0] > unlike_x_pos-5 and\
mouse_pos[1] < unlike_y_pos+unlike_pos_height+5 and mouse_pos[1] > unlike_y_pos-5: mouse_pos[1] < unlike_y_pos+unlike_pos_height+5 and mouse_pos[1] > unlike_y_pos-5:
while True: while True:
unlike_x_pos, unlike_y_pos = get_random_pos() unlike_x_pos, unlike_y_pos = get_random_pos()
if mouse_pos[0] < unlike_x_pos+unlike_pos_width+5 and mouse_pos[0] > unlike_x_pos-5 and\ if mouse_pos[0] < unlike_x_pos+unlike_pos_width+5 and mouse_pos[0] > unlike_x_pos-5 and\
mouse_pos[1] < unlike_y_pos+unlike_pos_height+5 and mouse_pos[1] > unlike_y_pos-5: mouse_pos[1] < unlike_y_pos+unlike_pos_height+5 and mouse_pos[1] > unlike_y_pos-5:
continue continue
break break
title('小姐姐,我观察你很久了', screen, scale=[2, 10]) title('小姐姐,我观察你很久了', screen, scale=[2, 10])
title('做我女朋友好不好呀? *^_^*', screen, scale=[2, 6]) title('做我女朋友好不好呀? *^_^*', screen, scale=[2, 6])
button('好呀', like_x_pos, like_y_pos, like_pos_width, like_pos_height, button_color, screen, 20) button('好呀', like_x_pos, like_y_pos, like_pos_width, like_pos_height, button_color, screen, 20)
button('算了吧', unlike_x_pos, unlike_y_pos, unlike_pos_width/2, unlike_pos_height/2, button_color, screen, 10) button('算了吧', unlike_x_pos, unlike_y_pos, unlike_pos_width/2, unlike_pos_height/2, button_color, screen, 10)
pygame.display.flip() pygame.display.flip()
pygame.display.update() pygame.display.update()
clock.tick(60) clock.tick(60)
if not os.path.exists("3.png"): if not os.path.exists("3.png"):
show_like_interface2('我就知道小姐姐你也喜欢我 *^_^*', screen, color=(0, 0, 0)) show_like_interface2('我就知道小姐姐你也喜欢我 *^_^*', screen, color=(0, 0, 0))
else: else:
show_like_interface1(screen=screen) show_like_interface1(screen=screen)
if __name__ == '__main__': if __name__ == '__main__':
main() main()
\ No newline at end of file
# -*- mode: python -*- # -*- mode: python -*-
block_cipher = None block_cipher = None
a = Analysis(['love.py'], a = Analysis(['love.py'],
pathex=['/Users/MING/.virtualenvs/PythonCodingTime-8iFaVP-J/', '/Users/MING/Github/love-with-python/be_my_girlfriend_mac'], pathex=['/Users/MING/.virtualenvs/PythonCodingTime-8iFaVP-J/', '/Users/MING/Github/love-with-python/be_my_girlfriend_mac'],
binaries=[], binaries=[],
datas=[('01.ming','.'),('PingFang.ttc','PingFang.ttc')], datas=[('01.ming','.'),('PingFang.ttc','PingFang.ttc')],
hiddenimports=[], hiddenimports=[],
hookspath=[], hookspath=[],
runtime_hooks=[], runtime_hooks=[],
excludes=[], excludes=[],
win_no_prefer_redirects=False, win_no_prefer_redirects=False,
win_private_assemblies=False, win_private_assemblies=False,
cipher=block_cipher) cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data, pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher) cipher=block_cipher)
exe = EXE(pyz, exe = EXE(pyz,
a.scripts, a.scripts,
a.binaries, a.binaries,
a.zipfiles, a.zipfiles,
a.datas, a.datas,
name='love', name='love',
debug=False, debug=False,
strip=False, strip=False,
upx=True, upx=True,
runtime_tmpdir=None, runtime_tmpdir=None,
console=False ) console=False )
""" """
-*- coding: utf-8 -*- -*- coding: utf-8 -*-
@Time : 2022/2/13 下午 1:34 @Time : 2022/2/13 下午 1:34
@Author : SunGuoqi @Author : SunGuoqi
@Website : https://sunguoqi.com @Website : https://sunguoqi.com
@Github: https://github.com/sun0225SUN @Github: https://github.com/sun0225SUN
""" """
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
fig = plt.figure() fig = plt.figure()
ax = fig.gca(projection='3d') ax = fig.gca(projection='3d')
[x, t] = np.meshgrid( [x, t] = np.meshgrid(
np.array(range(25)) / 24.0, np.array(range(25)) / 24.0,
np.arange(0, 575.5, 0.5) / 575 * 30 * np.pi - 4 * np.pi) np.arange(0, 575.5, 0.5) / 575 * 30 * np.pi - 4 * np.pi)
p = (np.pi / 2) * np.exp(-t / (8 * np.pi)) p = (np.pi / 2) * np.exp(-t / (8 * np.pi))
change = np.sin(20 * t) / 50 change = np.sin(20 * t) / 50
u = 1 - (1 - np.mod(3.3 * t, 2 * np.pi) / np.pi)**4 / 2 + change u = 1 - (1 - np.mod(3.3 * t, 2 * np.pi) / np.pi)**4 / 2 + change
y = 2 * (x**2 - x)**2 * np.sin(p) y = 2 * (x**2 - x)**2 * np.sin(p)
r = u * (x * np.sin(p) + y * np.cos(p)) * 1.5 r = u * (x * np.sin(p) + y * np.cos(p)) * 1.5
h = u * (x * np.cos(p) - y * np.sin(p)) h = u * (x * np.cos(p) - y * np.sin(p))
c = plt.get_cmap('magma') c = plt.get_cmap('magma')
surf = ax.plot_surface(r * np.cos(t), surf = ax.plot_surface(r * np.cos(t),
r * np.sin(t), r * np.sin(t),
h, h,
rstride=1, rstride=1,
cstride=1, cstride=1,
cmap=c, cmap=c,
linewidth=0, linewidth=0,
antialiased=True) antialiased=True)
plt.show() plt.show()
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib import cm from matplotlib import cm
fig = plt.figure() fig = plt.figure()
ax = fig.gca(projection='3d') ax = fig.gca(projection='3d')
[x, t] = np.meshgrid( [x, t] = np.meshgrid(
np.array(range(25)) / 24.0, np.array(range(25)) / 24.0,
np.arange(0, 575.5, 0.5) / 575 * 17 * np.pi - 2 * np.pi) np.arange(0, 575.5, 0.5) / 575 * 17 * np.pi - 2 * np.pi)
p = (np.pi / 2) * np.exp(-t / (8 * np.pi)) p = (np.pi / 2) * np.exp(-t / (8 * np.pi))
u = 1 - (1 - np.mod(3.6 * t, 2 * np.pi) / np.pi)**4 / 2 u = 1 - (1 - np.mod(3.6 * t, 2 * np.pi) / np.pi)**4 / 2
y = 2 * (x**2 - x)**2 * np.sin(p) y = 2 * (x**2 - x)**2 * np.sin(p)
r = u * (x * np.sin(p) + y * np.cos(p)) r = u * (x * np.sin(p) + y * np.cos(p))
h = u * (x * np.cos(p) - y * np.sin(p)) h = u * (x * np.cos(p) - y * np.sin(p))
c = cm.gist_rainbow_r c = cm.gist_rainbow_r
surf = ax.plot_surface(r * np.cos(t), surf = ax.plot_surface(r * np.cos(t),
r * np.sin(t), r * np.sin(t),
h, h,
rstride=1, rstride=1,
cstride=1, cstride=1,
cmap=c, cmap=c,
linewidth=0, linewidth=0,
antialiased=True) antialiased=True)
plt.show() plt.show()
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib import cm from matplotlib import cm
fig = plt.figure() fig = plt.figure()
ax = fig.gca(projection='3d') ax = fig.gca(projection='3d')
[x, t] = np.meshgrid( [x, t] = np.meshgrid(
np.array(range(25)) / 24.0, np.array(range(25)) / 24.0,
np.arange(0, 575.5, 0.5) / 575 * 17 * np.pi - 2 * np.pi) np.arange(0, 575.5, 0.5) / 575 * 17 * np.pi - 2 * np.pi)
p = (np.pi / 2) * np.exp(-t / (8 * np.pi)) p = (np.pi / 2) * np.exp(-t / (8 * np.pi))
u = 1 - (1 - np.mod(3.6 * t, 2 * np.pi) / np.pi)**4 / 2 u = 1 - (1 - np.mod(3.6 * t, 2 * np.pi) / np.pi)**4 / 2
y = 2 * (x**2 - x)**2 * np.sin(p) y = 2 * (x**2 - x)**2 * np.sin(p)
r = u * (x * np.sin(p) + y * np.cos(p)) r = u * (x * np.sin(p) + y * np.cos(p))
h = u * (x * np.cos(p) - y * np.sin(p)) h = u * (x * np.cos(p) - y * np.sin(p))
c = cm.get_cmap('spring_r') c = cm.get_cmap('spring_r')
surf = ax.plot_surface(r * np.cos(t), surf = ax.plot_surface(r * np.cos(t),
r * np.sin(t), r * np.sin(t),
h, h,
rstride=1, rstride=1,
cstride=1, cstride=1,
cmap=c, cmap=c,
linewidth=0, linewidth=0,
antialiased=True) antialiased=True)
plt.show() plt.show()
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
fig = plt.figure() fig = plt.figure()
ax = fig.gca(projection='3d') ax = fig.gca(projection='3d')
# 将相位向后移动了6*pi # 将相位向后移动了6*pi
[x, t] = np.meshgrid( [x, t] = np.meshgrid(
np.array(range(25)) / 24.0, np.array(range(25)) / 24.0,
np.arange(0, 575.5, 0.5) / 575 * 20 * np.pi + 4 * np.pi) np.arange(0, 575.5, 0.5) / 575 * 20 * np.pi + 4 * np.pi)
p = (np.pi / 2) * np.exp(-t / (8 * np.pi)) p = (np.pi / 2) * np.exp(-t / (8 * np.pi))
# 添加边缘扰动 # 添加边缘扰动
change = np.sin(15 * t) / 150 change = np.sin(15 * t) / 150
# 将t的参数减少,使花瓣的角度变大 # 将t的参数减少,使花瓣的角度变大
u = 1 - (1 - np.mod(3.3 * t, 2 * np.pi) / np.pi)**4 / 2 + change u = 1 - (1 - np.mod(3.3 * t, 2 * np.pi) / np.pi)**4 / 2 + change
y = 2 * (x**2 - x)**2 * np.sin(p) y = 2 * (x**2 - x)**2 * np.sin(p)
r = u * (x * np.sin(p) + y * np.cos(p)) r = u * (x * np.sin(p) + y * np.cos(p))
h = u * (x * np.cos(p) - y * np.sin(p)) h = u * (x * np.cos(p) - y * np.sin(p))
c = plt.get_cmap('Reds') c = plt.get_cmap('Reds')
surf = ax.plot_surface(r * np.cos(t), surf = ax.plot_surface(r * np.cos(t),
r * np.sin(t), r * np.sin(t),
h, h,
rstride=1, rstride=1,
cstride=1, cstride=1,
cmap=c, cmap=c,
linewidth=0, linewidth=0,
antialiased=True) antialiased=True)
plt.show() plt.show()
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
fig = plt.figure() fig = plt.figure()
ax = fig.gca(projection='3d') ax = fig.gca(projection='3d')
[x, t] = np.meshgrid( [x, t] = np.meshgrid(
np.array(range(25)) / 24.0, np.array(range(25)) / 24.0,
np.arange(0, 575.5, 0.5) / 575 * 6 * np.pi - 4 * np.pi) np.arange(0, 575.5, 0.5) / 575 * 6 * np.pi - 4 * np.pi)
p = (np.pi / 2) * np.exp(-t / (8 * np.pi)) p = (np.pi / 2) * np.exp(-t / (8 * np.pi))
change = np.sin(10 * t) / 20 change = np.sin(10 * t) / 20
u = 1 - (1 - np.mod(5.2 * t, 2 * np.pi) / np.pi)**4 / 2 + change u = 1 - (1 - np.mod(5.2 * t, 2 * np.pi) / np.pi)**4 / 2 + change
y = 2 * (x**2 - x)**2 * np.sin(p) y = 2 * (x**2 - x)**2 * np.sin(p)
r = u * (x * np.sin(p) + y * np.cos(p)) * 1.5 r = u * (x * np.sin(p) + y * np.cos(p)) * 1.5
h = u * (x * np.cos(p) - y * np.sin(p)) h = u * (x * np.cos(p) - y * np.sin(p))
c = plt.get_cmap('spring_r') c = plt.get_cmap('spring_r')
surf = ax.plot_surface(r * np.cos(t), surf = ax.plot_surface(r * np.cos(t),
r * np.sin(t), r * np.sin(t),
h, h,
rstride=1, rstride=1,
cstride=1, cstride=1,
cmap=c, cmap=c,
linewidth=0, linewidth=0,
antialiased=True) antialiased=True)
plt.show() plt.show()
# 安装所需库 # 安装所需库
``` ```
pip install pillow pip install pillow
pip install matplotlib pip install matplotlib
pip install numpy pip install numpy
``` ```
# 运行 # 运行
``` ```
python 文件名.py python 文件名.py
``` ```
![](./img/eg.png) ![](./img/eg.png)
# 效果 # 效果
![01](./img/01.png) ![01](./img/01.png)
![02](./img/02.png) ![02](./img/02.png)
![03](./img/03.png) ![03](./img/03.png)
![04](./img/04.png) ![04](./img/04.png)
![05](./img/05.png) ![05](./img/05.png)
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
def heart_3d(x, y, z): def heart_3d(x, y, z):
return (x**2 + (9 / 4) * y**2 + z**2 - return (x**2 + (9 / 4) * y**2 + z**2 -
1)**3 - x**2 * z**3 - (9 / 80) * y**2 * z**3 1)**3 - x**2 * z**3 - (9 / 80) * y**2 * z**3
def plot_implicit(fn, bbox=(-1.5, 1.5)): def plot_implicit(fn, bbox=(-1.5, 1.5)):
''' create a plot of an implicit function ''' create a plot of an implicit function
fn ...implicit function (plot where fn==0) fn ...implicit function (plot where fn==0)
bbox ..the x,y,and z limits of plotted interval''' bbox ..the x,y,and z limits of plotted interval'''
xmin, xmax, ymin, ymax, zmin, zmax = bbox * 3 xmin, xmax, ymin, ymax, zmin, zmax = bbox * 3
fig = plt.figure() fig = plt.figure()
ax = fig.add_subplot(111, projection='3d') ax = fig.add_subplot(111, projection='3d')
A = np.linspace(xmin, xmax, 100) # resolution of the contour A = np.linspace(xmin, xmax, 100) # resolution of the contour
B = np.linspace(xmin, xmax, 40) # number of slices B = np.linspace(xmin, xmax, 40) # number of slices
A1, A2 = np.meshgrid(A, A) # grid on which the contour is plotted A1, A2 = np.meshgrid(A, A) # grid on which the contour is plotted
for z in B: # plot contours in the XY plane for z in B: # plot contours in the XY plane
X, Y = A1, A2 X, Y = A1, A2
Z = fn(X, Y, z) Z = fn(X, Y, z)
cset = ax.contour(X, Y, Z + z, [z], zdir='z', colors=('red', )) cset = ax.contour(X, Y, Z + z, [z], zdir='z', colors=('red', ))
# [z] defines the only level to plot # [z] defines the only level to plot
# for this contour for this value of z # for this contour for this value of z
for y in B: # plot contours in the XZ plane for y in B: # plot contours in the XZ plane
X, Z = A1, A2 X, Z = A1, A2
Y = fn(X, y, Z) Y = fn(X, y, Z)
cset = ax.contour(X, Y + y, Z, [y], zdir='y', colors=('red', )) cset = ax.contour(X, Y + y, Z, [y], zdir='y', colors=('red', ))
for x in B: # plot contours in the YZ plane for x in B: # plot contours in the YZ plane
Y, Z = A1, A2 Y, Z = A1, A2
X = fn(x, Y, Z) X = fn(x, Y, Z)
cset = ax.contour(X + x, Y, Z, [x], zdir='x', colors=('red', )) cset = ax.contour(X + x, Y, Z, [x], zdir='x', colors=('red', ))
# must set plot limits because the contour will likely extend # must set plot limits because the contour will likely extend
# way beyond the displayed level. Otherwise matplotlib extends the plot limits # way beyond the displayed level. Otherwise matplotlib extends the plot limits
# to encompass all values in the contour. # to encompass all values in the contour.
ax.set_zlim3d(zmin, zmax) ax.set_zlim3d(zmin, zmax)
ax.set_xlim3d(xmin, xmax) ax.set_xlim3d(xmin, xmax)
ax.set_ylim3d(ymin, ymax) ax.set_ylim3d(ymin, ymax)
plt.show() plt.show()
if __name__ == '__main__': if __name__ == '__main__':
plot_implicit(heart_3d) plot_implicit(heart_3d)
\ No newline at end of file
# 安装所需库 # 安装所需库
``` ```
pip install matplotlib pip install matplotlib
pip install numpy pip install numpy
``` ```
# 运行 # 运行
``` ```
python 文件名.py python 文件名.py
``` ```
![](./img/eg.jpg) ![](./img/eg.jpg)
# 运行 # 运行
``` ```
python 文件名.py python 文件名.py
``` ```
![](./img/1.jpg) ![](./img/1.jpg)
import turtle import turtle
import math import math
turtle.pen() turtle.pen()
t = turtle t = turtle
t.up() t.up()
t.goto(0, 150) t.goto(0, 150)
t.down() t.down()
t.color('red') t.color('red')
t.begin_fill() t.begin_fill()
t.fillcolor('red') t.fillcolor('red')
t.speed(1) t.speed(1)
t.left(45) t.left(45)
t.forward(150) t.forward(150)
t.right(45) t.right(45)
t.forward(100) t.forward(100)
t.right(45) t.right(45)
t.forward(100) t.forward(100)
t.right(45) t.right(45)
t.forward(100) t.forward(100)
t.right(45) t.right(45)
t.forward(250 + math.sqrt(2) * 100) t.forward(250 + math.sqrt(2) * 100)
t.right(90) t.right(90)
t.speed(2) t.speed(2)
t.forward(250 + 100 * math.sqrt(2)) t.forward(250 + 100 * math.sqrt(2))
t.right(45) t.right(45)
t.forward(100) t.forward(100)
t.right(45) t.right(45)
t.forward(100) t.forward(100)
t.right(45) t.right(45)
t.forward(100) t.forward(100)
t.right(45) t.right(45)
t.forward(150) t.forward(150)
t.end_fill() t.end_fill()
t.goto(-10, 0) t.goto(-10, 0)
t.pencolor('white') t.pencolor('white')
# L # L
t.pensize(10) t.pensize(10)
t.goto(-50, 0) t.goto(-50, 0)
t.goto(-50, 80) t.goto(-50, 80)
t.up() t.up()
# I # I
t.goto(-100, 0) t.goto(-100, 0)
t.down() t.down()
t.goto(-160, 0) t.goto(-160, 0)
t.goto(-130, 0) t.goto(-130, 0)
t.goto(-130, 80) t.goto(-130, 80)
t.goto(-160, 80) t.goto(-160, 80)
t.goto(-100, 80) t.goto(-100, 80)
t.up() t.up()
# O # O
t.goto(10, 25) t.goto(10, 25)
t.down() t.down()
t.right(45) t.right(45)
t.circle(25, extent=180) t.circle(25, extent=180)
t.goto(60, 55) t.goto(60, 55)
t.circle(25, extent=180) t.circle(25, extent=180)
t.goto(10, 25) t.goto(10, 25)
t.up() t.up()
t.goto(75, 80) t.goto(75, 80)
t.down() t.down()
t.goto(100, 0) t.goto(100, 0)
t.goto(125, 80) t.goto(125, 80)
t.up() t.up()
t.goto(180, 80) t.goto(180, 80)
t.down() t.down()
t.goto(140, 80) t.goto(140, 80)
t.goto(140, 0) t.goto(140, 0)
t.goto(180, 0) t.goto(180, 0)
t.up() t.up()
t.goto(180, 40) t.goto(180, 40)
t.down() t.down()
t.goto(140, 40) t.goto(140, 40)
# U # U
t.up() t.up()
t.goto(-40, -30) t.goto(-40, -30)
t.down() t.down()
t.goto(-40, -80) t.goto(-40, -80)
t.circle(40, extent=180) t.circle(40, extent=180)
t.goto(40, -30) t.goto(40, -30)
t.hideturtle() t.hideturtle()
# 安装依赖 # 安装依赖
``` ```
pip install turtle pip install turtle
``` ```
# 运行 # 运行
``` ```
python 文件名.py python 文件名.py
``` ```
# 效果 # 效果
![](./img/1.jpg) ![](./img/1.jpg)
from tkinter import *
from matplotlib import pyplot as plt
from PIL import Image
import random
import math
import numpy as np
import os
import colorsys
import cv2
from scipy.ndimage.filters import gaussian_filter
canvas_width = 600
canvas_height = 600
world_width = 0.05
world_heigth = 0.05
# 中间心的参数
points = None
fixed_point_size = 20000
fixed_scale_range = (4, 4.3)
min_scale = np.array([1.0, 1.0, 1.0]) * 0.9
max_scale = np.array([1.0, 1.0, 1.0]) * 0.9
min_heart_scale = -15
max_heart_scale = 16
# 外围随机心参数
random_point_szie = 7000
random_scale_range = (3.5, 3.9)
random_point_maxvar = 0.2
# 心算法参数
mid_point_ignore = 0.95
# 相机参数
camera_close_plane = 0.1
camera_position = np.array([0.0, -2.0, 0.0])
# 点的颜色
hue = 0.92
color_strength = 255
# 常用向量缓存
zero_scale = np.array([0.0, 0.0, 0.0])
unit_scale = np.array([1.0, 1.0, 1.0])
color_white = np.array([255, 255, 255])
axis_y = np.array([0.0, 1.0, 0.0])
# 渲染缓存
render_buffer = np.empty((canvas_width, canvas_height, 3), dtype=int)
strength_buffer = np.empty((canvas_width, canvas_height), dtype=float)
# 随机点文件缓存
points_file = "temp.txt"
# 渲染结果
total_frames = 30
output_dir = "./output"
# 格式
image_fmt = "jpg"
def color(value):
digit = list(map(str, range(10))) + list("ABCDEF")
string = '#'
for i in value:
a1 = i // 16
a2 = i % 16
string += digit[a1] + digit[a2]
return string
def heart_func(x, y, z, scale):
bscale = scale
bscale_half = bscale / 2
x = x * bscale - bscale_half
y = y * bscale - bscale_half
z = z * bscale - bscale_half
return (x**2 + 9/4*(y**2) + z**2 - 1)**3 - (x**2)*(z**3) - 9/200*(y**2)*(z**3)
def lerp_vector(a, b, ratio):
result = a.copy()
for i in range(3):
result[i] = a[i] + (b[i] - a[i]) * ratio
return result
def lerp_int(a, b, ratio):
return (int)(a + (b - a) * ratio)
def lerp_float(a, b, ratio):
return (a + (b - a) * ratio)
def distance(point):
return (point[0]**2 + point[1]**2 + point[2]**2) ** 0.5
def dot(a, b):
return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]
def inside_rand(tense):
x = random.random()
y = -tense * math.log(x)
return y
# 生成中间心
def genPoints(pointCount, heartScales):
result = np.empty((pointCount, 3))
index = 0
while index < pointCount:
# 生成随机点
x = random.random()
y = random.random()
z = random.random()
# 扣掉心中间的点
mheartValue = heart_func(x, 0.5, z, heartScales[1])
mid_ignore = random.random()
if mheartValue < 0 and mid_ignore < mid_point_ignore:
continue
heartValue = heart_func(x, y, z, heartScales[0])
z_shrink = 0.01
sz = z - z_shrink
sheartValue = heart_func(x, y, sz, heartScales[1])
# 保留在心边上的点
if heartValue < 0 and sheartValue > 0:
result[index] = [x - 0.5, y - 0.5, z - 0.5]
# 向内扩散
len = 0.7
result[index] = result[index] * (1 - len * inside_rand(0.2))
# 重新赋予深度
newY = random.random() - 0.5
rheartValue = heart_func(result[index][0] + 0.5, newY + 0.5, result[index][2] + 0.5, heartScales[0])
if rheartValue > 0:
continue
result[index][1] = newY
# 删掉肚脐眼
dist = distance(result[index])
if dist < 0.12:
continue
index = index + 1
if index % 100 == 0:
print("{ind} generated {per}%".format(ind=index, per=((index / pointCount) * 100)))
return result
# 生成随机心
def genRandPoints(pointCount, heartScales, maxVar, ratio):
result = np.empty((pointCount, 3))
index = 0
while index < pointCount:
x = random.random()
y = random.random()
z = random.random()
mheartValue = heart_func(x, 0.5, z, heartScales[1])
mid_ignore = random.random()
if mheartValue < 0 and mid_ignore < mid_point_ignore:
continue
heartValue = heart_func(x, y, z, heartScales[0])
sheartValue = heart_func(x, y, z, heartScales[1])
if heartValue < 0 and sheartValue > 0:
result[index] = [x - 0.5, y - 0.5, z - 0.5]
dist = distance(result[index])
if dist < 0.12:
continue
len = 0.7
result[index] = result[index] * (1 - len * inside_rand(0.2))
index = index + 1
for i in range(pointCount):
var = maxVar * ratio
randScale = 1 + random.normalvariate(0, var)
result[i] = result[i] * randScale
return result
# 世界坐标到相机本地坐标
def world_2_cameraLocalSapce(world_point):
new_point = world_point.copy()
new_point[1] = new_point[1] + camera_position[1]
return new_point
# 相机本地坐标到相机空间坐标
def cameraLocal_2_cameraSpace(cameraLocalPoint):
depth = distance(cameraLocalPoint)
cx = cameraLocalPoint[0] * (camera_close_plane / cameraLocalPoint[1])
cz = -cameraLocalPoint[2] * (cx / cameraLocalPoint[0])
cameraLocalPoint[0] = cx
cameraLocalPoint[1] = cz
return cameraLocalPoint, depth
# 相机空间坐标到屏幕坐标
def camerSpace_2_screenSpace(cameraSpace):
x = cameraSpace[0]
y = cameraSpace[1]
# convert to view space
centerx = canvas_width / 2
centery = canvas_height / 2
ratiox = canvas_width / world_width
ratioy = canvas_height / world_heigth
viewx = centerx + x * ratiox
viewy = canvas_height - (centery + y * ratioy)
cameraSpace[0] = viewx
cameraSpace[1] = viewy
return cameraSpace.astype(int)
# 绘制世界坐标下的点
def draw_point(worldPoint):
cameraLocal = world_2_cameraLocalSapce(worldPoint)
cameraSpsace, depth = cameraLocal_2_cameraSpace(cameraLocal)
screeSpace = camerSpace_2_screenSpace(cameraSpsace)
draw_size = int(random.random() * 3 + 1)
draw_on_buffer(screeSpace, depth, draw_size)
# 绘制到缓存上
def draw_on_buffer(screenPos, depth, draw_size):
if draw_size == 0:
return
elif draw_size == 1:
draw_point_on_buffer(screenPos[0], screenPos[1], color_strength, depth)
elif draw_size == 2:
draw_point_on_buffer(screenPos[0], screenPos[1], color_strength, depth)
draw_point_on_buffer(screenPos[0] + 1, screenPos[1] + 1, color_strength, depth)
elif draw_size == 3:
draw_point_on_buffer(screenPos[0], screenPos[1], color_strength, depth)
draw_point_on_buffer(screenPos[0] + 1, screenPos[1] + 1, color_strength, depth)
draw_point_on_buffer(screenPos[0] + 1, screenPos[1], color_strength, depth)
elif draw_size == 4:
draw_point_on_buffer(screenPos[0], screenPos[1], color_strength, depth)
draw_point_on_buffer(screenPos[0] + 1, screenPos[1], color_strength, depth)
draw_point_on_buffer(screenPos[0], screenPos[1] + 1, color_strength, depth)
draw_point_on_buffer(screenPos[0] + 1, screenPos[1] + 1, color_strength, depth)
# 根据色调和颜色强度获取颜色
def get_color(strength):
result = None
if strength >= 1:
result = colorsys.hsv_to_rgb(hue, 2 - strength, 1)
else:
result = colorsys.hsv_to_rgb(hue, 1, strength)
r = min(result[0] * 256, 255)
g = min(result[1] * 256, 255)
b = min(result[2] * 256, 255)
return np.array((r, g, b), dtype=int)
# 可以根据深度做一些好玩的
def draw_point_on_buffer(x, y, color, depth):
if x < 0 or x >= canvas_width or y < 0 or y >= canvas_height:
return
# 混合
strength = float(color) / 255
strength_buffer[x, y] = strength_buffer[x, y] + strength
# 绘制缓存
def draw_buffer_on_canvas(output = None):
render_buffer.fill(0)
for i in range(render_buffer.shape[0]):
for j in range(render_buffer.shape[1]):
render_buffer[i, j] = get_color(strength_buffer[i, j])
im = Image.fromarray(np.uint8(render_buffer))
im = im.rotate(-90)
if output is None:
plt.imshow(im)
plt.show()
else:
im.save(output)
def paint_heart(ratio, randratio, outputFile = None):
global strength_buffer
global render_buffer
global points
# 清空缓存
strength_buffer.fill(0)
for i in range(fixed_point_size):
# 缩放
point = points[i] * lerp_vector(min_scale, max_scale, ratio)
# 球型场
dist = distance(point)
radius = 0.4
sphere_scale = radius / dist
point = point * lerp_float(0.9, sphere_scale, ratio * 0.3)
# 绘制
draw_point(point)
# 生成一组随机点
randPoints = genRandPoints(random_point_szie, random_scale_range, random_point_maxvar, randratio)
for i in range(random_point_szie):
# 绘制
draw_point(randPoints[i])
# 高斯模糊
for i in range(1):
strength_buffer = gaussian_filter(strength_buffer, sigma=0.8)
# 绘制缓存
draw_buffer_on_canvas(outputFile)
def show_images():
img = None
for i in range(total_frames):
save_name = "{name}.{fmt}".format(name=i, fmt=image_fmt)
save_path = os.path.join(output_dir, save_name)
img = cv2.imread(save_path, cv2.IMREAD_ANYCOLOR)
cv2.imshow("Img", img)
cv2.waitKey(25)
def gen_images():
global points
if not os.path.isdir(output_dir):
os.mkdir(output_dir)
# 尝试加载或生成中间心
if not os.path.exists(points_file):
print("未发现缓存点,重新生成中")
points = genPoints(fixed_point_size, fixed_scale_range)
np.savetxt(points_file, points)
else:
print("发现缓存文件,跳过生成")
points = np.loadtxt(points_file)
for i in range(total_frames):
print("正在处理图片... ", i)
frame_ratio = float(i) / (total_frames - 1)
frame_ratio = frame_ratio ** 2
ratio = math.sin(frame_ratio * math.pi) * 0.743144
randratio = math.sin(frame_ratio * math.pi * 2 + total_frames / 2)
save_name = "{name}.{fmt}".format(name=i, fmt=image_fmt)
save_path = os.path.join(output_dir, save_name)
paint_heart(ratio, randratio, save_path)
print("图片已保存至", save_path)
if __name__ == "__main__":
gen_images()
while True:
show_images()
此差异已折叠。
import random
from math import sin, cos, pi, log
from tkinter import *
CANVAS_WIDTH = 640 # 画布的宽
CANVAS_HEIGHT = 640 # 画布的高
CANVAS_CENTER_X = CANVAS_WIDTH / 2 # 画布中心的X轴坐标
CANVAS_CENTER_Y = CANVAS_HEIGHT / 2 # 画布中心的Y轴坐标
IMAGE_ENLARGE = 11 # 放大比例
HEART_COLOR = "#e77c8e" # 心的颜色#ff7171
def heart_function(t, shrink_ratio: float = IMAGE_ENLARGE):
"""
“爱心函数生成器”
:param shrink_ratio: 放大比例
:param t: 参数
:return: 坐标
"""
# 基础函数
x = 16 * (sin(t) ** 3)
y = -(13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t))
# 放大
x *= shrink_ratio
y *= shrink_ratio
# 移到画布中央
x += CANVAS_CENTER_X
y += CANVAS_CENTER_Y
return int(x), int(y)
def scatter_inside(x, y, beta=0.15):
"""
随机内部扩散
:param x: 原x
:param y: 原y
:param beta: 强度
:return: 新坐标
"""
ratio_x = - beta * log(random.random())
ratio_y = - beta * log(random.random())
dx = ratio_x * (x - CANVAS_CENTER_X)
dy = ratio_y * (y - CANVAS_CENTER_Y)
return x - dx, y - dy
def shrink(x, y, ratio):
"""
抖动
:param x: 原x
:param y: 原y
:param ratio: 比例
:return: 新坐标
"""
force = -1 / (((x - CANVAS_CENTER_X) ** 2 + (y - CANVAS_CENTER_Y) ** 2) ** 0.6) # 这个参数...
dx = ratio * force * (x - CANVAS_CENTER_X)
dy = ratio * force * (y - CANVAS_CENTER_Y)
return x - dx, y - dy
def curve(p):
"""
自定义曲线函数,调整跳动周期
:param p: 参数
:return: 正弦
"""
# 可以尝试换其他的动态函数,达到更有力量的效果(贝塞尔?)
return 2 * (3 * sin(4 * p)) / (2 * pi)
class Heart:
"""
爱心类
"""
def __init__(self, generate_frame=20):
self._points = set() # 原始爱心坐标集合
self._edge_diffusion_points = set() # 边缘扩散效果点坐标集合
self._center_diffusion_points = set() # 中心扩散效果点坐标集合
self.all_points = {} # 每帧动态点坐标
self.build(2000)
self.random_halo = 1000
self.generate_frame = generate_frame
for frame in range(generate_frame):
self.calc(frame)
def build(self, number):
# 爱心
for _ in range(number):
t = random.uniform(0, 2 * pi) # 随机不到的地方造成爱心有缺口
x, y = heart_function(t)
self._points.add((x, y))
# 爱心内扩散
for _x, _y in list(self._points):
for _ in range(3):
x, y = scatter_inside(_x, _y, 0.05)
self._edge_diffusion_points.add((x, y))
# 爱心内再次扩散
point_list = list(self._points)
for _ in range(4000):
x, y = random.choice(point_list)
x, y = scatter_inside(x, y, 0.17)
self._center_diffusion_points.add((x, y))
@staticmethod
def calc_position(x, y, ratio):
# 调整缩放比例
force = 1 / (((x - CANVAS_CENTER_X) ** 2 + (y - CANVAS_CENTER_Y) ** 2) ** 0.520) # 魔法参数
dx = ratio * force * (x - CANVAS_CENTER_X) + random.randint(-1, 1)
dy = ratio * force * (y - CANVAS_CENTER_Y) + random.randint(-1, 1)
return x - dx, y - dy
def calc(self, generate_frame):
ratio = 10 * curve(generate_frame / 10 * pi) # 圆滑的周期的缩放比例
halo_radius = int(4 + 6 * (1 + curve(generate_frame / 10 * pi)))
halo_number = int(3000 + 4000 * abs(curve(generate_frame / 10 * pi) ** 2))
all_points = []
# 光环
heart_halo_point = set() # 光环的点坐标集合
for _ in range(halo_number):
t = random.uniform(0, 2 * pi) # 随机不到的地方造成爱心有缺口
x, y = heart_function(t, shrink_ratio=11.6) # 魔法参数
x, y = shrink(x, y, halo_radius)
if (x, y) not in heart_halo_point:
# 处理新的点
heart_halo_point.add((x, y))
x += random.randint(-14, 14)
y += random.randint(-14, 14)
size = random.choice((1, 2, 2))
all_points.append((x, y, size))
# 轮廓
for x, y in self._points:
x, y = self.calc_position(x, y, ratio)
size = random.randint(1, 3)
all_points.append((x, y, size))
# 内容
for x, y in self._edge_diffusion_points:
x, y = self.calc_position(x, y, ratio)
size = random.randint(1, 2)
all_points.append((x, y, size))
for x, y in self._center_diffusion_points:
x, y = self.calc_position(x, y, ratio)
size = random.randint(1, 2)
all_points.append((x, y, size))
self.all_points[generate_frame] = all_points
def render(self, render_canvas, render_frame):
for x, y, size in self.all_points[render_frame % self.generate_frame]:
render_canvas.create_rectangle(x, y, x + size, y + size, width=0, fill=HEART_COLOR)
def draw(main: Tk, render_canvas: Canvas, render_heart: Heart, render_frame=0):
render_canvas.delete('all')
render_heart.render(render_canvas, render_frame)
main.after(160, draw, main, render_canvas, render_heart, render_frame + 1)
if __name__ == '__main__':
root = Tk() # 一个Tk
root.title('宝贝爱你哟')#将标题设置为'tkinter'
canvas = Canvas(root, bg='black', height=CANVAS_HEIGHT, width=CANVAS_WIDTH)
canvas.pack()
heart = Heart() # 心
draw(root, canvas, heart) # 开始画
root.mainloop()
\ No newline at end of file
import random
from math import sin, cos, pi, log
from tkinter import *
CANVAS_WIDTH = 840 # 画布的宽
CANVAS_HEIGHT = 680 # 画布的高
CANVAS_CENTER_X = CANVAS_WIDTH / 2 # 画布中心的X轴坐标
CANVAS_CENTER_Y = CANVAS_HEIGHT / 2 # 画布中心的Y轴坐标
IMAGE_ENLARGE = 11 # 放大比例
HEART_COLOR = "RED" # 引号内修改颜色!
def heart_function(t, shrink_ratio: float = IMAGE_ENLARGE):
"""
“爱心函数生成器”
:param shrink_ratio: 放大比例
:param t: 参数
:return: 坐标
"""
# 基础函数
x = 17 * (sin(t) ** 3)
y = -(16 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(3 * t))
# 放大
# x *= shrink_ratio
# y *= shrink_ratio
x *= IMAGE_ENLARGE
y *= IMAGE_ENLARGE
# 移到画布中央
x += CANVAS_CENTER_X
y += CANVAS_CENTER_Y
return int(x), int(y)
def scatter_inside(x, y, beta=0.15):
"""
随机内部扩散
:param x: 原x
:param y: 原y
:param beta: 强度
:return: 新坐标
"""
ratio_x = - beta * log(random.random())
ratio_y = - beta * log(random.random())
dx = ratio_x * (x - CANVAS_CENTER_X)
dy = ratio_y * (y - CANVAS_CENTER_Y)
return x - dx, y - dy
def shrink(x, y, ratio):
"""
抖动
:param x: 原x
:param y: 原y
:param ratio: 比例
:return: 新坐标
"""
force = -1 / (((x - CANVAS_CENTER_X) ** 2 + (y - CANVAS_CENTER_Y) ** 2) ** 0.6) # 这个参数...
dx = ratio * force * (x - CANVAS_CENTER_X)
dy = ratio * force * (y - CANVAS_CENTER_Y)
return x - dx, y - dy
def curve(p):
"""
自定义曲线函数,调整跳动周期
:param p: 参数
:return: 正弦
"""
# 可以尝试换其他的动态函数,达到更有力量的效果(贝塞尔?)
return 2 * (2 * sin(4 * p)) / (2 * pi)
class Heart:
"""
爱心类
"""
def __init__(self, generate_frame=20):
self._points = set() # 原始爱心坐标集合
self._edge_diffusion_points = set() # 边缘扩散效果点坐标集合
self._center_diffusion_points = set() # 中心扩散效果点坐标集合
self.all_points = {} # 每帧动态点坐标
self.build(2000)
self.random_halo = 1000
self.generate_frame = generate_frame
for frame in range(generate_frame):
self.calc(frame)
def build(self, number):
# 爱心
for _ in range(number):
t = random.uniform(0, 2 * pi) # 随机不到的地方造成爱心有缺口
x, y = heart_function(t)
self._points.add((x, y))
# 爱心内扩散
for _x, _y in list(self._points):
for _ in range(3):
x, y = scatter_inside(_x, _y, 0.05)
self._edge_diffusion_points.add((x, y))
# 爱心内再次扩散
point_list = list(self._points)
for _ in range(10000):
x, y = random.choice(point_list)
x, y = scatter_inside(x, y, 0.27)
self._center_diffusion_points.add((x, y))
@staticmethod
def calc_position(x, y, ratio):
# 调整缩放比例
force = 1 / (((x - CANVAS_CENTER_X) ** 2 + (y - CANVAS_CENTER_Y) ** 2) ** 0.420) # 魔法参数
dx = ratio * force * (x - CANVAS_CENTER_X) + random.randint(-1, 1)
dy = ratio * force * (y - CANVAS_CENTER_Y) + random.randint(-1, 1)
return x - dx, y - dy
def calc(self, generate_frame):
ratio = 15 * curve(generate_frame / 10 * pi) # 圆滑的周期的缩放比例
halo_radius = int(4 + 6 * (1 + curve(generate_frame / 10 * pi)))
halo_number = int(3000 + 4000 * abs(curve(generate_frame / 10 * pi) ** 2))
all_points = []
# 光环
heart_halo_point = set() # 光环的点坐标集合
for _ in range(halo_number):
t = random.uniform(0, 2 * pi) # 随机不到的地方造成爱心有缺口
x, y = heart_function(t, shrink_ratio=-15) # 魔法参数
x, y = shrink(x, y, halo_radius)
if (x, y) not in heart_halo_point:
# 处理新的点
heart_halo_point.add((x, y))
x += random.randint(-60, 60)
y += random.randint(-60, 60)
size = random.choice((1, 1, 2))
all_points.append((x, y, size))
all_points.append((x + 20, y + 20, size))
all_points.append((x - 20, y - 20, size))
all_points.append((x + 20, y - 20, size))
all_points.append((x - 20, y + 20, size))
# 轮廓
for x, y in self._points:
x, y = self.calc_position(x, y, ratio)
size = random.randint(1, 3)
all_points.append((x, y, size))
# 内容
for x, y in self._edge_diffusion_points:
x, y = self.calc_position(x, y, ratio)
size = random.randint(1, 2)
all_points.append((x, y, size))
for x, y in self._center_diffusion_points:
x, y = self.calc_position(x, y, ratio)
size = random.randint(1, 2)
all_points.append((x, y, size))
self.all_points[generate_frame] = all_points
def render(self, render_canvas, render_frame):
for x, y, size in self.all_points[render_frame % self.generate_frame]:
render_canvas.create_rectangle(x, y, x + size, y + size, width=0, fill=HEART_COLOR)
def draw(main: Tk, render_canvas: Canvas, render_heart: Heart, render_frame=0):
render_canvas.delete('all')
render_heart.render(render_canvas, render_frame)
main.after(1, draw, main, render_canvas, render_heart, render_frame + 1)
if __name__ == '__main__':
root = Tk()
root.title("晚上星月争辉,美梦陪你入睡")
canvas = Canvas(root, bg='black', height=CANVAS_HEIGHT, width=CANVAS_WIDTH)
canvas.pack()
heart = Heart()
draw(root, canvas, heart)
root.mainloop()
\ No newline at end of file
此差异已折叠。
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>小孙同学</title> <title>小孙同学</title>
<meta name="language" content="zh-CN"> <meta name="language" content="zh-CN">
<meta name="title" content="小孙同学"> <meta name="title" content="小孙同学">
<meta name="github" content="https://github.com/sun0225SUN/Awesome-Love-Code"> <meta name="github" content="https://github.com/sun0225SUN/Awesome-Love-Code">
<meta name="describe" content="收集不易,您的star是我坚持的动力,同时也欢迎各位PR哦! "> <meta name="describe" content="收集不易,您的star是我坚持的动力,同时也欢迎各位PR哦! ">
<link rel="icon" type="image/x-icon" href="https://cdn.jsdelivr.net/gh/sun0225SUN/photos/img/20210715233345.png"> <link rel="icon" type="image/x-icon" href="https://cdn.jsdelivr.net/gh/sun0225SUN/photos/img/20210715233345.png">
<style> <style>
* { * {
padding: 0; padding: 0;
margin: 0; margin: 0;
} }
body { body {
background-color: pink; background-color: pink;
} }
#frame { #frame {
position: relative; position: relative;
width: 400px; width: 400px;
height: 300px; height: 300px;
margin: 250px auto; margin: 250px auto;
} }
.left, .left,
.right { .right {
top: 0; top: 0;
width: 200px; width: 200px;
height: 200px; height: 200px;
border-radius: 50%; border-radius: 50%;
} }
.left { .left {
left: 35px; left: 35px;
} }
.right { .right {
right: 35px; right: 35px;
z-index: -1; z-index: -1;
} }
.bottom { .bottom {
bottom: 36px; bottom: 36px;
left: 100px; left: 100px;
width: 200px; width: 200px;
height: 200px; height: 200px;
transform: rotate(45deg); transform: rotate(45deg);
z-index: -1; z-index: -1;
} }
.heart { .heart {
position: absolute; position: absolute;
box-shadow: 0 0 40px #d5093c; box-shadow: 0 0 40px #d5093c;
animation: beat .4s ease infinite normal; animation: beat .4s ease infinite normal;
background: linear-gradient(-90deg, #F50A45 0%, #d5093c 40%); background: linear-gradient(-90deg, #F50A45 0%, #d5093c 40%);
} }
@keyframes beat { @keyframes beat {
0% { 0% {
transform: scale(1) rotate(225deg); transform: scale(1) rotate(225deg);
box-shadow: 0 0 40px #d5093c; box-shadow: 0 0 40px #d5093c;
} }
50% { 50% {
transform: scale(1.1) rotate(225deg); transform: scale(1.1) rotate(225deg);
box-shadow: 0 0 70px #d5093c; box-shadow: 0 0 70px #d5093c;
} }
100% { 100% {
transform: scale(1) rotate(225deg); transform: scale(1) rotate(225deg);
box-shadow: 0 0 40px #d5093c; box-shadow: 0 0 40px #d5093c;
; ;
} }
} }
.word { .word {
position: absolute; position: absolute;
width: 50%; width: 50%;
top: 75%; top: 75%;
left: 25%; left: 25%;
text-align: center; text-align: center;
transform: translateY(-50%); transform: translateY(-50%);
font-family: 'Love Ya Like A Sister', cursive; font-family: 'Love Ya Like A Sister', cursive;
font-size: 40px; font-size: 40px;
color: #c70012; color: #c70012;
padding: 0 20px; padding: 0 20px;
} }
</style> </style>
</head> </head>
<body> <body>
<div id="frame"> <div id="frame">
<div class="heart left"></div> <div class="heart left"></div>
<div class="heart right"></div> <div class="heart right"></div>
<div class="heart bottom"></div> <div class="heart bottom"></div>
</div> </div>
<b class="word">每次遇见你都心跳加速!</b> <b class="word">每次遇见你都心跳加速!</b>
<audio autoplay="autopaly" loop="loop" id="audios" preload="auto"> <audio autoplay="autopaly" loop="loop" id="audios" preload="auto">
<source src="http://music.163.com/song/media/outer/url?id=526464145.mp3" /> <source src="http://music.163.com/song/media/outer/url?id=526464145.mp3" />
</audio> </audio>
<script> <script>
var b = document.body; var b = document.body;
var c = document.getElementsByTagName('canvas')[0]; var c = document.getElementsByTagName('canvas')[0];
var a = c.getContext('2d'); var a = c.getContext('2d');
document.body.clientWidth; document.body.clientWidth;
with (m = Math) C = cos, S = sin, P = pow, R = random; c.width = c.height = f = 600; h = -250; function p(a, b, c) { if (c > 60) return [S(a * 7) * (13 + 5 / (.2 + P(b * 4, 4))) - S(b) * 50, b * f + 50, 625 + C(a * 7) * (13 + 5 / (.2 + P(b * 4, 4))) + b * 400, a * 1 - b / 2, a]; A = a * 2 - 1; B = b * 2 - 1; if (A * A + B * B < 1) { if (c > 37) { n = (j = c & 1) ? 6 : 4; o = .5 / (a + .01) + C(b * 125) * 3 - a * 300; w = b * h; return [o * C(n) + w * S(n) + j * 610 - 390, o * S(n) - w * C(n) + 550 - j * 350, 1180 + C(B + A) * 99 - j * 300, .4 - a * .1 + P(1 - B * B, -h * 6) * .15 - a * b * .4 + C(a + b) / 5 + P(C((o * (a + 1) + (B > 0 ? w : -w)) / 25), 30) * .1 * (1 - B * B), o / 1e3 + .7 - o * w * 3e-6] } if (c > 32) { c = c * 1.16 - .15; o = a * 45 - 20; w = b * b * h; z = o * S(c) + w * C(c) + 620; return [o * C(c) - w * S(c), 28 + C(B * .5) * 99 - b * b * b * 60 - z / 2 - h, z, (b * b * .3 + P((1 - (A * A)), 7) * .15 + .3) * b, b * .7] } o = A * (2 - b) * (80 - c * 2); w = 99 - C(A) * 120 - C(b) * (-h - c * 4.9) + C(P(1 - b, 7)) * 50 + c * 2; z = o * S(c) + w * C(c) + 700; return [o * C(c) - w * S(c), B * 99 - C(P(b, 7)) * 50 - c / 3 - z / 1.35 + 450, z, (1 - b / 1.2) * .9 + a * .1, P((1 - b), 20) / 4 + .05] } } setInterval('for(i=0;i<1e4;i++)if(s=p(R(),R(),i%46/.74)){z=s[2];x=~~(s[0]*f/z-h);y=~~(s[1]*f/z-h);if(!m[q=y*f+x]|m[q]>z)m[q]=z,a.fillStyle="rgb("+~(s[3]*h)+","+~(s[4]*h)+","+~(s[3]*s[3]*-80)+")",a.fillRect(x,y,1,1)}', 0) with (m = Math) C = cos, S = sin, P = pow, R = random; c.width = c.height = f = 600; h = -250; function p(a, b, c) { if (c > 60) return [S(a * 7) * (13 + 5 / (.2 + P(b * 4, 4))) - S(b) * 50, b * f + 50, 625 + C(a * 7) * (13 + 5 / (.2 + P(b * 4, 4))) + b * 400, a * 1 - b / 2, a]; A = a * 2 - 1; B = b * 2 - 1; if (A * A + B * B < 1) { if (c > 37) { n = (j = c & 1) ? 6 : 4; o = .5 / (a + .01) + C(b * 125) * 3 - a * 300; w = b * h; return [o * C(n) + w * S(n) + j * 610 - 390, o * S(n) - w * C(n) + 550 - j * 350, 1180 + C(B + A) * 99 - j * 300, .4 - a * .1 + P(1 - B * B, -h * 6) * .15 - a * b * .4 + C(a + b) / 5 + P(C((o * (a + 1) + (B > 0 ? w : -w)) / 25), 30) * .1 * (1 - B * B), o / 1e3 + .7 - o * w * 3e-6] } if (c > 32) { c = c * 1.16 - .15; o = a * 45 - 20; w = b * b * h; z = o * S(c) + w * C(c) + 620; return [o * C(c) - w * S(c), 28 + C(B * .5) * 99 - b * b * b * 60 - z / 2 - h, z, (b * b * .3 + P((1 - (A * A)), 7) * .15 + .3) * b, b * .7] } o = A * (2 - b) * (80 - c * 2); w = 99 - C(A) * 120 - C(b) * (-h - c * 4.9) + C(P(1 - b, 7)) * 50 + c * 2; z = o * S(c) + w * C(c) + 700; return [o * C(c) - w * S(c), B * 99 - C(P(b, 7)) * 50 - c / 3 - z / 1.35 + 450, z, (1 - b / 1.2) * .9 + a * .1, P((1 - b), 20) / 4 + .05] } } setInterval('for(i=0;i<1e4;i++)if(s=p(R(),R(),i%46/.74)){z=s[2];x=~~(s[0]*f/z-h);y=~~(s[1]*f/z-h);if(!m[q=y*f+x]|m[q]>z)m[q]=z,a.fillStyle="rgb("+~(s[3]*h)+","+~(s[4]*h)+","+~(s[3]*s[3]*-80)+")",a.fillRect(x,y,1,1)}', 0)
</script> </script>
</body> </body>
</html> </html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>小孙同学</title> <title>小孙同学</title>
<meta name="language" content="zh-CN"> <meta name="language" content="zh-CN">
<meta name="title" content="小孙同学"> <meta name="title" content="小孙同学">
<meta name="github" content="https://github.com/sun0225SUN/Awesome-Love-Code"> <meta name="github" content="https://github.com/sun0225SUN/Awesome-Love-Code">
<meta name="describe" content="收集不易,您的star是我坚持的动力,同时也欢迎各位PR哦! "> <meta name="describe" content="收集不易,您的star是我坚持的动力,同时也欢迎各位PR哦! ">
<link rel="icon" type="image/x-icon" href="https://cdn.jsdelivr.net/gh/sun0225SUN/photos/img/20210715233345.png"> <link rel="icon" type="image/x-icon" href="https://cdn.jsdelivr.net/gh/sun0225SUN/photos/img/20210715233345.png">
<style> <style>
.container { .container {
background: rgb(255, 192, 203); background: rgb(255, 192, 203);
color: white; color: white;
text-align: center; text-align: center;
width: 500px; width: 500px;
height: 500px; height: 500px;
margin-top: 100px; margin-top: 100px;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
} }
.word { .word {
position: fixed; position: fixed;
text-align: center; text-align: center;
width: 500px; width: 500px;
height: 100px; height: 100px;
transform: translateY(-50%); transform: translateY(-50%);
font-family: 楷体; font-family: 楷体;
font-size: 40px; font-size: 40px;
color: #c70012; color: #c70012;
} }
</style> </style>
</head> </head>
     
<body class="container">  <body class="container"> 
<audio autoplay="autopaly" loop="loop" id="audios" preload="auto"> <audio autoplay="autopaly" loop="loop" id="audios" preload="auto">
<source src="http://music.163.com/song/media/outer/url?id=526464145.mp3" /> <source src="http://music.163.com/song/media/outer/url?id=526464145.mp3" />
</audio> </audio>
<div class="word">浪漫至死不渝</div> <div class="word">浪漫至死不渝</div>
<canvas id="c"></canvas> <canvas id="c"></canvas>
     
<script>   <script>  
var b = document.body; var b = document.body;
var c = document.getElementsByTagName('canvas')[0]; var c = document.getElementsByTagName('canvas')[0];
var a = c.getContext('2d'); var a = c.getContext('2d');
document.body.clientWidth;  document.body.clientWidth; 
</script>   </script>  
<script>   <script>  
with (m = Math) C = cos, S = sin, P = pow, R = random; c.width = c.height = f = 600; h = -250; function p(a, b, c) { if (c > 60) return [S(a * 7) * (13 + 5 / (.2 + P(b * 4, 4))) - S(b) * 50, b * f + 50, 625 + C(a * 7) * (13 + 5 / (.2 + P(b * 4, 4))) + b * 400, a * 1 - b / 2, a]; A = a * 2 - 1; B = b * 2 - 1; if (A * A + B * B < 1) { if (c > 37) { n = (j = c & 1) ? 6 : 4; o = .5 / (a + .01) + C(b * 125) * 3 - a * 300; w = b * h; return [o * C(n) + w * S(n) + j * 610 - 390, o * S(n) - w * C(n) + 550 - j * 350, 1180 + C(B + A) * 99 - j * 300, .4 - a * .1 + P(1 - B * B, -h * 6) * .15 - a * b * .4 + C(a + b) / 5 + P(C((o * (a + 1) + (B > 0 ? w : -w)) / 25), 30) * .1 * (1 - B * B), o / 1e3 + .7 - o * w * 3e-6] } if (c > 32) { c = c * 1.16 - .15; o = a * 45 - 20; w = b * b * h; z = o * S(c) + w * C(c) + 620; return [o * C(c) - w * S(c), 28 + C(B * .5) * 99 - b * b * b * 60 - z / 2 - h, z, (b * b * .3 + P((1 - (A * A)), 7) * .15 + .3) * b, b * .7] } o = A * (2 - b) * (80 - c * 2); w = 99 - C(A) * 120 - C(b) * (-h - c * 4.9) + C(P(1 - b, 7)) * 50 + c * 2; z = o * S(c) + w * C(c) + 700; return [o * C(c) - w * S(c), B * 99 - C(P(b, 7)) * 50 - c / 3 - z / 1.35 + 450, z, (1 - b / 1.2) * .9 + a * .1, P((1 - b), 20) / 4 + .05] } } setInterval('for(i=0;i<1e4;i++)if(s=p(R(),R(),i%46/.74)){z=s[2];x=~~(s[0]*f/z-h);y=~~(s[1]*f/z-h);if(!m[q=y*f+x]|m[q]>z)m[q]=z,a.fillStyle="rgb("+~(s[3]*h)+","+~(s[4]*h)+","+~(s[3]*s[3]*-80)+")",a.fillRect(x,y,1,1)}', 0)   with (m = Math) C = cos, S = sin, P = pow, R = random; c.width = c.height = f = 600; h = -250; function p(a, b, c) { if (c > 60) return [S(a * 7) * (13 + 5 / (.2 + P(b * 4, 4))) - S(b) * 50, b * f + 50, 625 + C(a * 7) * (13 + 5 / (.2 + P(b * 4, 4))) + b * 400, a * 1 - b / 2, a]; A = a * 2 - 1; B = b * 2 - 1; if (A * A + B * B < 1) { if (c > 37) { n = (j = c & 1) ? 6 : 4; o = .5 / (a + .01) + C(b * 125) * 3 - a * 300; w = b * h; return [o * C(n) + w * S(n) + j * 610 - 390, o * S(n) - w * C(n) + 550 - j * 350, 1180 + C(B + A) * 99 - j * 300, .4 - a * .1 + P(1 - B * B, -h * 6) * .15 - a * b * .4 + C(a + b) / 5 + P(C((o * (a + 1) + (B > 0 ? w : -w)) / 25), 30) * .1 * (1 - B * B), o / 1e3 + .7 - o * w * 3e-6] } if (c > 32) { c = c * 1.16 - .15; o = a * 45 - 20; w = b * b * h; z = o * S(c) + w * C(c) + 620; return [o * C(c) - w * S(c), 28 + C(B * .5) * 99 - b * b * b * 60 - z / 2 - h, z, (b * b * .3 + P((1 - (A * A)), 7) * .15 + .3) * b, b * .7] } o = A * (2 - b) * (80 - c * 2); w = 99 - C(A) * 120 - C(b) * (-h - c * 4.9) + C(P(1 - b, 7)) * 50 + c * 2; z = o * S(c) + w * C(c) + 700; return [o * C(c) - w * S(c), B * 99 - C(P(b, 7)) * 50 - c / 3 - z / 1.35 + 450, z, (1 - b / 1.2) * .9 + a * .1, P((1 - b), 20) / 4 + .05] } } setInterval('for(i=0;i<1e4;i++)if(s=p(R(),R(),i%46/.74)){z=s[2];x=~~(s[0]*f/z-h);y=~~(s[1]*f/z-h);if(!m[q=y*f+x]|m[q]>z)m[q]=z,a.fillStyle="rgb("+~(s[3]*h)+","+~(s[4]*h)+","+~(s[3]*s[3]*-80)+")",a.fillRect(x,y,1,1)}', 0)  
</script>   </script>  
</body>  </body> 
   
</html>  </html> 
body { body {
margin: 0; margin: 0;
padding: 0; padding: 0;
background: #ffc0cb; background: #ffc0cb;
font-size: 20px; font-size: 20px;
font-family: '微软雅黑', '宋体', sans-serif; font-family: '微软雅黑', '宋体', sans-serif;
color: #000000; color: #000000;
overflow: auto overflow: auto
} }
a { a {
color: #000; color: #000;
font-size: 14px; font-size: 14px;
} }
#main { #main {
width: 100%; width: 100%;
} }
#wrap { #wrap {
position: relative; position: relative;
margin: 0 auto; margin: 0 auto;
width: 1100px; width: 1100px;
height: 680px; height: 680px;
margin-top: 10px; margin-top: 10px;
} }
#text { #text {
width: 400px; width: 400px;
height: 425px; height: 425px;
left: 60px; left: 60px;
top: 80px; top: 80px;
position: absolute; position: absolute;
} }
#code { #code {
display: none; display: none;
font-size: 16px; font-size: 16px;
} }
#clock-box { #clock-box {
position: absolute; position: absolute;
left: 60px; left: 60px;
top: 550px; top: 550px;
font-size: 28px; font-size: 28px;
display: none; display: none;
} }
#clock-box a { #clock-box a {
font-size: 28px; font-size: 28px;
text-decoration: none; text-decoration: none;
} }
#clock { #clock {
margin-left: 48px; margin-left: 48px;
} }
#clock .digit { #clock .digit {
font-size: 64px; font-size: 64px;
} }
#canvas { #canvas {
margin: 0 auto; margin: 0 auto;
width: 1100px; width: 1100px;
height: 680px; height: 680px;
} }
#error { #error {
margin: 0 auto; margin: 0 auto;
text-align: center; text-align: center;
margin-top: 60px; margin-top: 60px;
display: none; display: none;
} }
.hand { .hand {
cursor: pointer; cursor: pointer;
} }
.say { .say {
margin-left: 5px; margin-left: 5px;
} }
.space { .space {
margin-right: 150px; margin-right: 150px;
} }
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册