Saturday, August 13, 2016

Matlab code to a heart and display happy valentine day.




close all; % Clear all windows
clear all; % Clear all variables
clc; % Clear console

h=figure('color','k');axis off;
set(h,'menubar','none','toolbar','none');
hold on;
syms x y
s=uicontrol('style','pushbutton','units','normal','position',[.05 .05 .12 .05],'string','Close','callback','close all');
i=0.25;x=0;
a=[-1.5-(x*i) 1.5+(x*i) -1.5-(x*i) 1.5+(x*i)];
text(a(1)+0.01,a(3)+0.05,'Happy Valentine''s Day','color','b','fontsize',2*get(0,'defaulttextfontsize'));
a=randn(1,75);c=randn(1,75);
h1=plot(a,c);
set(h1,'linestyle','none','marker','*','markersize',10,'color','r');axis tight;axis off;axis equal;
iter=0;
while(iter<10)
x=3;i=0.25;
while((x*i)<=2.00 && (x*i)>0)
f1=inline('x.^6+y.^6+3*(x.^4)*(y.^2)+3*(x.^2)*(y.^4)-(x.^2)*(y.^3)-3*(x.^4)-6*(x.^2)*(y.^2)-3*(y.^4)+3*(x.^2)+3*(y.^2)-1');
f2=vectorize(f1);
h=ezplot(f2);axis([-1.5-(x*i) 1.5+(x*i) -1.5-(x*i) 1.5+(x*i)]);
set(h,'LineWidth',6);
set(h,'LineStyle','-.');
x=x-1;
drawnow;
end
pause(0.3);
x=3;i=0.25;
while((x*i)<=0.90)
f1=inline('x.^6+y.^6+3*(x.^4)*(y.^2)+3*(x.^2)*(y.^4)-(x.^2)*(y.^3)-3*(x.^4)-6*(x.^2)*(y.^2)-3*(y.^4)+3*(x.^2)+3*(y.^2)-1');
f2=vectorize(f1);
h=ezplot(f2);axis([-1.5-(x*i) 1.5+(x*i) -1.5-(x*i) 1.5+(x*i)]);
set(h,'LineWidth',6);
set(h,'LineStyle','-.');
x=x+1;
drawnow;
end
iter=iter+1;
end



x=-2:0.001:2;
f=sqrt(1-((abs(x)-1).^2));
g=acos(1-abs(x))-pi;
figure
plot(x,f,x,g)
title ('drawing a heart ..have fun');


No comments:

Post a Comment