As another toy project, I've written a program that tries to simulate a roulette wheel. Unfortunately, rapidly changing the graph to provide an animation-like effect brings out some of the shortcomings of the R graphic model. However, if your computer is relatively fast, the program may give the illusion of a roulette wheel.
Here's a screenshot:
wheel.png
Here's the code:
rotat = function(vals){
   l = length(vals)
   vals[c(2:l,1)]
   }

spinn = function(...){
   n = sample(40:80,size=1)
   for(i in 1:n){
      spin()
#  If you don't see the wheel spinning, uncomment this line
#      Sys.sleep(.04)
      }
}

spin = function(){
   thenums <<- rotat(thenums)
   colrs = c('red','black')[thenums %% 2 + 1]
   pie(rep(1,36),labels=thenums,col=colrs)
   arrows(-.1,1.07,-.1,.9,xpd=TRUE)
}


require(tcltk)
main = tktoplevel()
tkwm.title(main,"Wheel")

onum = sample(seq(1,36,by=2))
enum = sample(seq(2,36,by=2))

thenums = as.vector(rbind(onum,enum))
colors = c('red','black')[thenums %% 2 + 1]

tkpack(tkbutton(main,text='Spin',command=spinn))
spin()




File translated from TEX by TTH, version 3.67.
On 17 Apr 2006, 11:12.