Skip to content

Instantly share code, notes, and snippets.

@dinob0t
Last active August 29, 2015 13:56
Show Gist options
  • Save dinob0t/9063469 to your computer and use it in GitHub Desktop.
Save dinob0t/9063469 to your computer and use it in GitHub Desktop.
A Valentine's Day inspired function to plot concentric rainbow love hearts.
function valentinesDay(figureHandle, heartNumber)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Win the affections of any geek on Valentine's Day with this MATLAB %
% script to generate and plot a set of concentric rainbow love hearts. %
% %
% INPUT %
% figureHandle : A handle to the figure in which the plotting is to be %
% done %
% heartNumber: The number of colour steps and hearts to plot (~100 %
% looks nice) %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(0, 'currentfigure', figureHandle);
hold on
% Set up the colour space
colors = hsv(heartNumber);
% Calculate parametric equations for a pleasing cardoid curve
% http://mathworld.wolfram.com/HeartCurve.html
t = -10:0.001:10;
x = 16*sin(t).^3;
y = 13*cos(t) - 5*cos(2.*t) - 2*cos(3.*t) - cos(4.*t);
% For each colour, plot a another smaller heart in reverse colour order
for i = 1:heartNumber
plot(i.*x./heartNumber, i.*y./heartNumber, ...
'LineWidth', 2, 'Color', colors(heartNumber-i+1,:))
end
% Remove tick marks and resize plot
set(gca, 'visible', 'off');
axis equal
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment