Skip to content

Instantly share code, notes, and snippets.

@Ram-N
Created April 22, 2013 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ram-N/5437942 to your computer and use it in GitHub Desktop.
Save Ram-N/5437942 to your computer and use it in GitHub Desktop.
Function to get the segments (walls) of cells ready for plotting
#plotting
createXYWalls <- function (cells) {
#let each cell start at its XY position
xs<- NULL; ys<-NULL; xe <- NULL; ye<-NULL
for (i in 1:nrow(cells)) {
if(cells$W[i])
{
xs <- c(xs, cells$x[i]+1)
ys <- c(ys, cells$y[i]+0)
xe <- c(xe, cells$x[i]+1)
ye <- c(ye, cells$y[i]+1)
}
if(cells$E[i])
{
xs <- c(xs, cells$x[i]+0)
ys <- c(ys, cells$y[i]+0)
xe <- c(xe, cells$x[i]+0)
ye <- c(ye, cells$y[i]+1)
}
if(cells$N[i])
{
xs <- c(xs, cells$x[i]+0)
ys <- c(ys, cells$y[i]+0)
xe <- c(xe, cells$x[i]+1)
ye <- c(ye, cells$y[i]+0)
}
if(cells$S[i])
{
xs <- c(xs, cells$x[i]+0)
ys <- c(ys, cells$y[i]+1)
xe <- c(xe, cells$x[i]+1)
ye <- c(ye, cells$y[i]+1)
}
}
walls <- data.frame(xs,ys,xe,ye)
return(walls)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment