News for hackers. Stuff that matters.

R is for Love

# Paste into R then hit return

# Start

draw = function(color="#FFC0CB",border="#FF0000") {

    t = seq (0, 60, by = .1)

    x=-.01 * (-t^2 + 40*t + 1200) * sin(pi*t/180)

    y=.01 * (-t^2 + 40*t + 1200) * cos(pi*t/180)

    x=c(x,rev(.01 * (-t^2 + 40*t + 1200) * sin(pi*t/180)))

    y=c(y,rev(.01 * (-t^2 + 40*t + 1200) * cos(pi*t/180)))

    polygon(x,y, col=color, border=border)
}

msgA="\x48\x61\x70\x70\x79\x20"

msgB="\x56\x61\x6c\x65\x6e\x74\x69\x6e\x65\x73\x20"

msgC="\x44\x61\x79\x20\x3a\x29"

msg=paste(msgA,msgB,msgC,sep='')

plot(c(-9,9), c(0,16), type="n", xlab=msg, ylab="", axes="FALSE")

i=1

paletteLength=50

q = c(colorRampPalette(c("#FFC0CB", "#FF0000"),bias = .1)( paletteLength ))

while(1) {

    sleepTime = .01

    for (i in seq(1:paletteLength)) {

        draw(q[i],q[paletteLength+1-i])

        Sys.sleep(sleepTime)

    }

    for (i in rev(seq(1:paletteLength))) {

        draw(q[i],q[paletteLength+1-i])

        Sys.sleep(sleepTime)

    }
}

# End

( 2 comments | 3 points | on HN )
Re:R is for Love by samartioli on Thursday February 14, 2013 @11:51AM (#5220297)
Sorry, initial post stripped newlines. Edited the post.. had to put 2 newlines in order to maintain line breaks. (Tried <code> </code>.. didn't work.) Should work now!
Re:R is for Love by samartioli on Thursday February 14, 2013 @11:55AM (#5220323)