require(sm) # DELAY Function Deffinition # Written by JG Kunkel 6-9-2003 # ------------------------------------------------- DELAY<- function(T){ nextT<- Sys.time() + T while (Sys.time() < nextT) { Ret<- T } } # -------------------------------------------------- # End of Function DELAY # Demo Use of DELAY function # -------------------------------------------------- # Read a data file fishwalk<- read.csv('randFishWalk.csv', header = TRUE, sep = ",") attach(fishwalk) cat('fishwalk data\n') cat('xloc: ', xloc, '\n') cat('yloc: ', yloc, '\n') cat('secs: ', xysecs, '\n') cat('Number of steps: ', NN<-length(xysecs), '\n') # Set up plot axes plot(xloc, yloc, col='red',type='n') # Pause to allow timed beginning pause() points(xloc[1], yloc[1]) for (I in 2:NN) { first <- I-1 last <- I x1<- xloc[first] x2<- xloc[last] y1<- yloc[first] y2<- yloc[last] xylength<- ( (x1-x2)^2 + (y1-y2)^2)^0.5 dum <- DELAY(xysecs[I]) lines(xloc[first:last], yloc[first:last], lwd=2, col= 25 + I*5) cat(I, dum, format(Sys.time(), "%X"), xylength, "\n") }