感谢大家的支持和厚望,特此献上一段:
<br />
CreepingText <- function(s, time = 500, dist = 0.02, elapse = 0.01, margin = 0.03, col = rainbow(nchar(s)), cex = 1.0, ...) {<br />
<br />
if (is.na(s) || ! is.character(s) || length(s) != 1 || nchar(s) <= 0) return(NULL);<br />
<br />
chs <- unlist(strsplit(s, ""));<br />
pos <- t(matrix(c(<br />
seq(margin, length = length(chs), by = dist * cex),<br />
rep(0.5, length(chs))), length(chs), 2));<br />
<br />
theta <- pi;<br />
lastTime <- Sys.time();<br />
colorOrder <- 1:length(chs);<br />
<br />
refresh.screen <- function() {<br />
plot(0, type="n", xlab="", ylab="", axes = FALSE, xlim = c(0, 1), ylim = c(0, 1));<br />
rect(0, 0, 1, 1);<br />
text(pos[1,], pos[2,], chs, col = col[colorOrder], cex = cex, ...);<br />
}<br />
<br />
walk <- function() {<br />
pos <<- cbind(pos[,1] + rnorm(1, dist * cex, dist * cex / 3) * c(cos(theta), sin(theta)), pos[,-length(chs)]);<br />
colorOrder <<- colorOrder[c(length(chs), 1:(length(chs) - 1))];<br />
if (pos[1,1] < margin ) { pos[1,1] <<- margin; theta <<- (pi / 2 - theta); }<br />
if (pos[1,1] > 1 - margin) { pos[1,1] <<- 1 - margin; theta <<- (pi / 2 - theta); }<br />
if (pos[2,1] < margin ) { pos[2,1] <<- margin; theta <<- (-theta); }<br />
if (pos[2,1] > 1 - margin) { pos[2,1] <<- 1 - margin; theta <<- (-theta); }<br />
}<br />
<br />
refresh.screen();<br />
<br />
for (t in 1:time) {<br />
theta <- theta + runif(1, min = -pi / 10, max = pi / 10);<br />
walk();<br />
refresh.screen();<br />
Sys.sleep(.1);<br />
}<br />
}<br />
<br />
CreepingText("Thank you very much!", cex = 2);<br />