# Copia e incolla ... poi batti ora(). Se arresti con ESC
# il programma, poi battendo ora() lo puoi riattivare
ora <- function() {
 dev.new(width=3,height=1)
 par(mai=c(0,0,0,0),bg="yellow")
 plot(c(-1,1),c(-1,1),asp=1,fg="white",type="n")
 text(0,0.7,"CLICCA per avviare",cex=1.4)
 text(0,0,"l'orologio",cex=1.4)
 text(0,-0.7,"Premi ESC per fermarlo",cex=1.4)
 i <- 0; while(i < 1) {locator(1); i <- 1}
 b <- format(Sys.time(), "%X")
 while(1 < 2) {
  plot(c(-1,1),c(-1,1),asp=1,fg="white",type="n")
  text(0,0.5,format(Sys.time(), "%X"),cex=3,col="blue")
  text(0,-0.5,b,cex=2,col="red")
  a <- format(Sys.time(), "%X")
# lo fermo 1 secondo:
  while(format(Sys.time(), "%X") == a) {a <- a}  }  }
ora()



#
# ora <- function(x) ... è una funzione a 0 input; se chiamo ora()
# vengono eseguiti i successivi seguenti, racchiusi tra { e }
#
# dev.new(width=3,height=1) definisce una piccola finestra, larga circa 3 pollici ed
# alta 1, in cui inserire, con text, il messaggio iniziale e, poi, l'ora
#
# i <- 0; while(i < 1) {locator(1); i <- 1}  serve ad attendere il clic dell'utente
# b <- format(Sys.time(), "%X")  mette in b l'ora del clic
#
# while(1 < 2) { } è un ciclo senza fine (fino a che l'utente non preme ESC)
# 
# while(format(Sys.time(), "%X") == a) {a <- a} non fa praticamente nulla, finche'
# non scatta 1 sec

ALTRO OROLOGIO

ora <- function() {
 dev.new(width=1.5,height=1.5)
 par(mai=c(0,0,0,0))
 plot(c(-1,1),c(-1,1),asp=1,fg="white",type="n")
 text(0,0.7,"CLICCA per",cex=1)
 text(0,0.3,"l'avviare orologio",cex=1)
 text(0,-0.3,"Premi ESC",cex=1)
 text(0,-0.7,"per fermarlo",cex=1)
 i <- 0; while(i < 1) {locator(1); i <- 1}
 t <- function(x) strtoi(format(Sys.time(),paste("%",x,sep="")))
 # STRings TO Integers
 plot(c(-1,1),c(-1,1),asp=1,fg="white",type="n")
 while(1 < 2) {
  h <- t("H"); if (h > 13) h <- h-12;
  u <- -(t("M")-15)/30*pi
  u1 <- -(h+t("M")/60-3)/6*pi
  symbols(0, 0, circles=1, inches=FALSE, add=TRUE, fg="blue",bg="yellow")
  for (a in (0:5)*pi/6) lines(c(-cos(a),cos(a)),c(-sin(a),sin(a)),lty=3,col="red")
  lines(c(0,cos(u)*0.9),c(0,sin(u)*0.85),lwd=3)
  lines(c(0,cos(u1)*0.7),c(0,sin(u1)*0.6),lwd=5)
  a <- t("M")
  while( t("M") == a ) {x <- 1} } }
ora()