-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRomanDateClock.R
174 lines (156 loc) · 7.1 KB
/
RomanDateClock.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
## Roman numeral date & clock
## Corey Bradshaw
## Flinders University
## April 2022
## modified from plotClock in the caroline package
plotClockRoman <- function (hour, minute, x0 = 0, y0 = 0, r = 1) {
circleXY <- caroline::makeElipseCoords(x0=x0,y0=y0,b=1.1*r,a=1.1*r,alpha=0,pct.range=c(0,1),len=50)
quarHourTickMarksXY <- caroline::makeElipseCoords(x0=x0,y0=y0,b=1.05*r,a=1.05*r,alpha=(pi/2),pct.range=c((12*5-1)/(12*5),0),len=12*5)
hourLabelsXY <- caroline::makeElipseCoords(x0=x0,y0=y0,b=0.9*r,a=0.9*r,alpha=(pi/2),pct.range=c(11/12,0),len=12)
polygon(circleXY)
if (hour >= 12) {
roman.seq <- utils::as.roman(c(seq(13,23),12))
} else {
roman.seq <- utils::as.roman(seq(1,12))
}
text(hourLabelsXY[, 1],hourLabelsXY[, 2],roman.seq,cex=0.5,vfont=c("serif","EUC"))
text(quarHourTickMarksXY[,1],quarHourTickMarksXY[, 2],".", col="dark grey")
minuteV <- minute/60
minuteVXY <- caroline::makeElipseCoords(x0=x0,y0=y0,b=r,a=r,alpha=0,pct.range=(0.25-rep(minuteV,2)),len=1)
segments(x0,y0,minuteVXY$x[1],minuteVXY$y[1],col="grey")
hourV <- hour/12 + minuteV/12 # adjust hour hand for fractions of the hour by minute
hourVXY <- caroline::makeElipseCoords(x0=x0,y0=y0,b=0.7*r,a=0.7*r,alpha=0,pct.range=(0.25-rep(hourV,2)),len=1)
segments(x0, y0, hourVXY$x, hourVXY$y,lwd=1.5)
}
# get current time and date
currentTime <- Sys.time() # current time
date.now <- format(strptime(as.Date(currentTime), format="%Y-%m-%d"), "%d %b %Y")
year.now <- lubridate::year(currentTime)
month.now <- lubridate::month(currentTime)
day.now <- lubridate::day(currentTime)
hour.now <- sprintf("%02d", lubridate::hour(currentTime))
hour12 <- ifelse(as.numeric(hour.now) > 12, as.numeric(hour.now)-12, as.numeric(hour.now))
min.now <- sprintf("%02d", lubridate::minute(currentTime))
# Latin date characteristics
LatinWeekday <- c("Dies Lvnae","Dies Martis","Dies Mercvris","Dies Iovis","Dies Veneris", "Dies Satvrni", "Dies Solis")
EnglishWeekday <- c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
Ldow <- LatinWeekday[which(EnglishWeekday == weekdays(currentTime))]
LatinMonth <- c("Ianvarivs","Febrvarivs","Martivs","Aprilis","Maivs","Ivnivs","Ivlivs","Avgvstvs","September","October","November","December")
# Latin special days
# Ides
Ides <- c(13,13,15,13,15,13,15,13,13,15,13,13) # either 15th (Mar, Jul, Oct, May) or 13th (every other month)
if (day.now == Ides[month.now]) {
LatinDateDesc <- paste("Idibvs", LatinMonth[month.now], sep=" ")
}
# Nones
Nones <- Ides - 8 # 8 days earlier than the Ides
if (day.now == Nones[month.now]) {
LatinDateDesc <- paste("Nonis", LatinMonth[month.now], sep=" ")
}
# Kalends
if (day.now == 1) {
LatinDateDesc <- paste("Calendas", LatinMonth[month.now], sep=" ")
}
# Other days
if (day.now > 1 & day.now < (Nones[month.now] - 1)) {
daycount <- as.roman(as.numeric(Nones[month.now] - day.now + 1))
LatinDateDesc <- paste(daycount, "Nonis", LatinMonth[month.now], sep=" ")
}
if (day.now > Nones[month.now] & day.now < (Ides[month.now] - 1)) {
daycount <- as.roman(as.numeric(Ides[month.now] - day.now + 1))
LatinDateDesc <- paste(daycount, "Idibvs", LatinMonth[month.now], sep=" ")
}
if (day.now > Ides[month.now]) {
daycount <- as.roman(as.numeric(lubridate::days_in_month(currentTime)) - day.now + 1)
if (month.now < 12) {
LatinDateDesc <- paste(daycount, "Calendas", LatinMonth[month.now+1], sep=" ")
}
if (month.now == 12) {
LatinDateDesc <- paste(daycount, "Calendas", LatinMonth[1], sep=" ")
}
}
# special day eve
Pridie <- FALSE
if (day.now == (Nones[month.now] - 1)) {
LatinDateDesc <- paste("Pridie Nonas", LatinMonth[month.now], sep=" ")
Pridie <- TRUE
}
if (day.now == (Ides[month.now] - 1)) {
LatinDateDesc <- paste("Pridie Idibvs", LatinMonth[month.now], sep=" ")
Pridie <- TRUE
}
if (day.now == as.numeric(lubridate::days_in_month(currentTime))) {
if (month.now < 12) {
LatinDateDesc <- paste("Pridie Calendas", LatinMonth[month.now + 1], sep=" ")
Pridie <- TRUE
}
if (month.now == 12) {
LatinDateDesc <- paste("Pridie Calendas", LatinMonth[1], sep=" ")
Pridie <- TRUE
}
}
# Latin date as text
if (Pridie == F) {
LDate1 <- paste("Est", Ldow, "ante diem", LatinDateDesc, sep=" ")
}
if (day.now == 1 | Pridie == T | day.now == Nones[month.now] | day.now == Ides[month.now]) {
LDate1 <- paste("Est", Ldow, LatinDateDesc, sep=" ")
}
LDate2 <- paste(as.roman(year.now + 753), "Ab Vrbe condita", sep=" ") # from the establishment of Rome 753 BC
# Romanise for Gregorian date and 24-hour clock
year.rom <- utils::as.roman(year.now)
month.rom <- utils::as.roman(month.now)
day.rom <- utils::as.roman(day.now)
hour.rom <- utils::as.roman(hour.now)
min.rom <- utils::as.roman(min.now)
if (as.numeric(hour.now) == 0) {
hour.rom <- sprintf("%02d",0)
}
if (as.numeric(min.now) == 0) {
min.rom <- sprintf("%02d",0)
}
# set working directory to script's location (from https://gist.github.com/jasonsychau)
stub <- function() {}
thisPath <- function() {
cmdArgs <- commandArgs(trailingOnly = FALSE)
if (length(grep("^-f$", cmdArgs)) > 0) {
# R console option
normalizePath(dirname(cmdArgs[grep("^-f", cmdArgs) + 1]))[1]
} else if (length(grep("^--file=", cmdArgs)) > 0) {
# Rscript/R console option
scriptPath <- normalizePath(dirname(sub("^--file=", "", cmdArgs[grep("^--file=", cmdArgs)])))[1]
} else if (Sys.getenv("RSTUDIO") == "1") {
# RStudio
dirname(rstudioapi::getSourceEditorContext()$path)
} else if (is.null(attr(stub, "srcref")) == FALSE) {
# 'source'd via R console
dirname(normalizePath(attr(attr(stub, "srcref"), "srcfile")$filename))
} else {
stop("Cannot find file path")
}
}
setwd(thisPath())
# time as numbers in Latin
load("RomNumNam.RData")
LatinHr <- ifelse(as.numeric(hour.now) == 0, "media nocte", romNumName$LatinNumName[which(romNumName$Num == as.numeric(hour.now))])
LatinMn <- romNumName$LatinNumName[which(romNumName$Num == as.numeric(min.now))]
# feriae (Roman festivals)
load("feriae.RData")
feriae.sub <- which(feriae$month == month.now & feriae$day == day.now)
if (exists("feriae.sub")==T) {
dies.feriae <- feriae$holiday[feriae.sub]
}
if (exists("feriae.sub")==F | length(dies.feriae)==0) {
dies.feriae <- "nvllvs"
}
# plot Gregorian date in Roman numerals, Latin date in Latin, and time in Roman numerals (and Latin text)
par(xaxt="n", yaxt="n", pty="s")
plot(0:10,0:10,pch=NULL,col=NULL,xlab="",ylab="")
text(x=5, y=9, labels=paste(day.rom, ".", month.rom, ".", year.rom, sep=""), adj=0.5, cex=2.1, vfont=c("serif", "bold"))
text(x=5, y=8, labels=LDate1, adj=0.5, cex=0.65, vfont=c("serif", "EUC"))
text(x=5, y=7.5, labels=LDate2, adj=0.5, cex=0.65, vfont=c("serif", "EUC"))
text(x=5, y=7, labels=paste("feriatvm : ", dies.feriae, sep=""), adj=0.5, cex=0.65, vfont=c("serif", "EUC"))
text(x=5, y=5.8, labels=paste(hour.rom, ":", min.rom, sep=""), adj=0.5, cex=1.6, vfont=c("serif", "EUC"))
text(x=5, y=5.2, labels=paste(LatinHr, LatinMn, sep=" "), adj=0.5, cex=0.6, vfont=c("serif", "EUC"))
text(x=5, y=-0.1, labels="nvlla dies vmqvam memori vos eximet aevo", adj=0.5, cex=0.6, vfont=c("serif", "EUC"))
plotClockRoman(hour=as.numeric(hour.now), minute=as.numeric(min.now), x0 = 5, y0 = 2.5, r = 2)