Tuesday, 10 January 2012

postcard


My post card for this new year was done in R :)
and the respective code down there.



install.packages("animation")
required(animation)
# My postcard
#star=locator() #make your drawings and save the values
 
tree=data.frame(x=c(2.428064, 2.402075, 1.414481, 2.298118, 1.518438, 2.454053, 1.856299, 3.129775, 4.065390, 3.493626, 4.351273,
  3.623572, 4.325283, 3.493626, 3.545604), y=c(0.7471496, 2.1247874, 2.2013228, 3.6554960, 3.8468346, 5.4158110, 5.5688819, 8.6302992, 5.6836850, 5.5688819,
  3.6554960, 3.3876220, 2.2013228, 2.1247874, 0.7854173))
bals=data.frame(x=c(1.334286, 1.477931, 1.789163, 4.159310, 4.446601, 4.422660),y=c(2.170709, 3.854488, 5.500000, 5.653071, 3.548346, 2.017638))
star=data.frame(x=c(3.105911, 2.435567, 2.842562, 2.124335, 2.866502, 3.034089, 3.153793, 3.848079, 3.345320, 3.728374, 3.153793),y=c(8.676220, 8.063937, 9.173701, 9.518110, 9.479843, 10.283465, 9.518110, 9.594646, 9.097165, 8.293543, 8.599685))
kk=data.frame(x=c(1.619165 1.595283 1.308698 1.213170 1.260934 1.356462 1.451990 1.499754 1.547518 1.547518 1.643047, 1.738575 1.834103 1.834103 1.786339 1.738575 1.571400), y=c(1.067253 2.064176 2.170989 2.491429 2.598242 2.598242 2.527033 2.349011 2.064176 2.064176 2.384615, 2.527033 2.491429 2.420220 2.206593 2.028571 2.028571))
kk1=data.frame(x=c(2.956560, 2.932678, 2.813268, 2.550565, 2.502801, 2.622211, 2.598329, 2.837150, 2.837150, 2.884914, 2.956560, 2.956560, 3.052088, 3.267027, 3.267027, 3.075971, 2.980442, 2.813268, 2.789386, 2.598329, 2.598329, 2.884914,3.028206, 3.219263, 3.314791, 3.434201), y=c(1.031648, 3.025495, 3.061099, 3.310330, 3.630769, 3.880000, 3.880000, 3.701978, 3.595165, 3.239121, 3.061099, 3.595165, 3.880000, 3.630769, 3.452747, 3.239121, 2.989890, 2.811868, 2.740659, 2.455824, 2.455824, 3.061099, 2.811868, 2.527033, 2.491429, 2.633846))
kk2=data.frame(x=c(4.819361, 4.843243, 4.580541, 4.413366, 4.532776, 4.747715, 4.843243, 4.699951, 4.795479, 4.986536, 4.891007, 4.819361, 4.938771, 5.177592, 5.273120, 5.201474, 4.771597), y=c(0.996044, 2.527033, 2.562637, 2.811868, 2.811868, 2.740659, 2.562637, 3.096703, 3.274725, 3.167912, 2.740659, 2.527033, 2.989890, 3.096703, 2.705055, 2.562637, 2.527033))
 
# define an animation function to show the jitter effect
jitter.ani2 <- function(amount = 0.2, ...) {
    i <- 1
    while (i <= ani.options("nmax")) {
  plot(1:10, 1:10, typ="n", axes=F, xlab="", ylab="")
  mtext("by Marta Rufino, using R-project",4,las=0, col="#CC00CC")
  box(col="magenta", lty=3)
  rect(1,1,10,10,col="blue4", border=NA)
  polygon(tree, col="yellow4", border=NA) 
  polygon(c(2.407273, 2.383391, 3.481966, 3.529730),c(0.7468132, 2.1353846, 2.1353846, 0.8536264), col=c("brown"), border=NA)  
 
  polygon(x=c(1,1,2,2)+3+i/20, y=c(1,2,2,1), col="mediumvioletred", border=NA)
  lines(kk$x+3+i/20,kk$y, col="mediumpurple")
  polygon(x=c(2,2,4,4)+3+i/20, y=c(1,3,3,1), col="lightseagreen", border=NA)
  lines(kk1$x+3+i/20,kk1$y, col="blue")
  polygon(x=c(4,4,5.5,5.5)+3+i/20, y=c(1,2.5,2.5,1), col="salmon", border=NA)
  lines(kk2$x+3+i/20,kk2$y, col="brown")
 
   points(runif(20,0,10),runif(20,0,10), cex=runif(20,0.1,1),col="yellow", pch=8)
      text(7, 7, "Merry Christmas & Happy New Year", srt = i/3, col = rainbow(100)[i], cex = i/20)
         points(jitter(bals$x, amount = amount), jitter(bals$y, amount = amount),col=rainbow(6), cex=3, pch=16)
   polygon(jitter(star$x),jitter(star$y), col="gold", border=NA)
   #points(rep(1:3, 3), rep(1:3, each = 3), cex = 3, pch = 19)
         #ani.pause()
         i <- i + 1}}
 
# SAVE GIF
saveMovie(jitter.ani2(), interval = 0.5, ani.width = 600, ani.height = 600, outdir = getwd()) 
Created by Pretty R at inside-R.org

No comments:

Post a Comment