美文网首页
数字雨/字母雨的R实现 -《黑客帝国》效果图

数字雨/字母雨的R实现 -《黑客帝国》效果图

作者: 北欧森林 | 来源:发表于2020-12-29 06:43 被阅读0次

科幻迷们一定对《黑客帝国》里的数字雨效果印象深刻。我想,既然R这么强大,一定有实现的方法。果不其然,被我搜到了实现方法(准确来说这里是字母雨):

代码如下:

nx = 100
ny = 80
x = sample(x = 1:nx, size = 90, replace = TRUE)
y = seq(-1, -ny, length = 90)
op = par(bg = "black", mar = c(0, 0.2, 0, 0.2))
plot(1:nx, seq(-1, -nx), type = "n", xlim = c(1, nx), ylim =c(-ny+10, 1))
for (i in seq_along(x))
{
  aux = sample(1:ny, 1)
  points(rep(x[i], aux), y[1:aux], pch = sample(letters, aux, replace =TRUE), 
         col = hsv(0.35, 1, 1,runif(aux, 0.3)), cex = runif(aux, 0.3))
}
legend("bottomright", legend = "@NordicForrest", bty ="n", text.col = "gray70")

效果如图:

LetterRain-1.png

相关文章

网友评论

      本文标题:数字雨/字母雨的R实现 -《黑客帝国》效果图

      本文链接:https://www.haomeiwen.com/subject/rqsjnktx.html