R/roll.rgl.die.R

Defines functions roll.rgl.die

Documented in roll.rgl.die

roll.rgl.die <- function( side=sample(6,1), steps=250 ) {

  rgl::rgl.viewpoint(45,45)


  tmp <- seq(45, by=90, length=4)
  tmp2 <- c(-1,1,-1,1)
  
  for (j in 1:4) {
    for (i in seq(0,90,length=steps)) {
      rgl::rgl.viewpoint(tmp[j]+i, -tmp2[j]*45+tmp2[j]*i)
    }
  }

  if( side==1 ){
    for(i in seq(0,45, length=steps/2)) {
      rgl::rgl.viewpoint(45+i, 45+i)
    }
  } else if( side==6 ) {
    for(i in seq(0,90, length=steps)) {
      rgl::rgl.viewpoint(45+i, 45-i)
    }
    for(i in seq(0,45, length=steps/2)) {
      rgl::rgl.viewpoint(135+i, -45-i)
    }
  } else {
    tmp3 <- c(NA,3,0,2,1)[side]
    for(j in seq(1,length=tmp3)){
      for(i in seq(0,90,length=steps)) {
        rgl::rgl.viewpoint(tmp[j]+i, -tmp2[j]*45+tmp2[j]*i)
      }
    }
    for(i in seq(0,45, length=steps/2)) {
      rgl::rgl.viewpoint(tmp[tmp3+1]+i, -tmp2[tmp3+1]*45+tmp2[tmp3+1]*i)
    }
  }
  return(side)
}

Try the TeachingDemos package in your browser

Any scripts or data that you put into this service are public.

TeachingDemos documentation built on May 29, 2024, 5:59 a.m.