If you haven't sent your loved one a Valentine's Day greeting yet, it's not too late! Thanks to Guillermo Santos who pointed out an R script from Berkeley's Concepts in Computing with Data course, I created the following Valentine's Day card for my husband:
If you want to make one for your loved one, you can use the R code below (which I modified slightly from the original):
# Source: http://statistics.berkeley.edu/classes/s133/heart.r heart1 = function(name){ t = seq(0,60,len=100) plot(c(-8,8),c(0,20),type='n',axes=FALSE,xlab='',ylab='') x = -.01*(-t^2+40*t+1200)*sin(pi*t/180) y = .01*(-t^2+40*t+1200)*cos(pi*t/180) lines(x,y, lwd=4) lines(-x,y, lwd=4) text(0,7,"Happy Valentine's Day",col='red',cex=2.5) text(0,5.5,name,col='red',cex=2.5) }
I also sent one of these cute science-themed Valentines cards that I bought on Etsy (guess which one).
For an alternate parameterization (with a more pointy bottom) see my Valentine to my spouse. I also include some math-geeky phrases of affection, such as "You are more beautiful than Euler's identity!"
Posted by: Rick Wicklin | February 15, 2013 at 05:29
Saw this great solution on Stackoverflow: http://stackoverflow.com/questions/8082429/plot-a-heart-in-r
```
dat<- data.frame(t=seq(0, 2*pi, by=0.1) )
xhrt <- function(t) 16*sin(t)^3
yhrt <- function(t) 13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t)
dat$y=yhrt(dat$t)
dat$x=xhrt(dat$t)
plot(y ~ x, data=dat, type="l", bty="n", xaxt="n", yaxt="n", ann=FALSE)
with(dat, polygon(x,y, col="hotpink"))
points(c(10,-10, -15, 15), c(-10, -10, 10, 10), pch=169, font=5)
```
Posted by: Jared | February 15, 2013 at 09:45