# flower.R # Oh joy, a toy! # # Calculate an optical illusion of flower. See Figure 1 in # Barrow, Bhavsar, Sonoda: # Minimal spanning trees, filaments and galaxy clustering # Mon.Not.R.astr.Soc. (1985),216, p.17-35 # # Author: Tuomas Rajala # # Function: # flower() # parameters: # ncircles : number of circles emanating from centre # npoints : number of points to evenly spread on each circle # R : radius of outmost circle # skip : illusion parameter, how many circles to skip before setting a point in same radial angle # window : rectangle window in format c(xmin,xmax,ymin,ymax) # x0 , y0 : the centre # # # Example: # # pp<-flower(ncircles=50,npoints=100,skip=1) # plot(pp$x,pp$y,cex=.5+.1*pp$m,col=rgb(.0-.0*pp$m,runif(pp$n,.1+.8*pp$m,.2+.8*pp$m),.0),pch=19) # ########################################################################### flower<-function(ncircles=20, npoints=100, R=4,skip=1,window=c(0,10,0,10),x0=5,y0=5) { rvec<-seq(0,4,length=ncircles) x<-x0 y<-y0 t<-0 m<-0 for(i in 2:ncircles) { for(j in 0:(npoints-1)) { angle<-(t+(1+skip)*j)* 2*pi/(npoints*(1+skip)) x<-c(x, x0+cos(angle)*rvec[i]) y<-c(y, y0+sin(angle)*rvec[i]) m<-c(m,i) } t<-t+1 if(t>skip) t<-0 } list(x=x,y=y,m=m/max(m),n=length(x)) } flower.meadow<-function(N=5,Rvec=c(1,1,1,1,1)) { for(R in Rvec) { pp<-kukkanen(R=R,ncircles=40,x0=runif(1,0,10),y0=runif(1,0,10)) plot(pp,cex=.2,pch=19,col=heat.colors(max(pp$m))[pp$m],xlim=c(-4,14),ylim=c(-4,14)) par(new=T) } par(new=F) } #Test run #pp<-flower(ncircles=100,npoints=100,skip=1) #plot(pp$x,pp$y,cex=.5+.1*pp$m,col=rgb(.0-.0*pp$m,runif(pp$n,.1+.8*pp$m,.2+.8*pp$m),.0),pch=19)