yihui / MSG

Modern Statistical Graphics (《现代统计图形》的附加包)

Home Page:https://bookdown.org/xiangyun/msg/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

递归树

yihui opened this issue · comments

http://cos.name/cn/topic/105708

drawTree <- function(x1, y1, angle, n, lwd, len, col) {
    if (n >= 1) {
        x2 <- x1 + cos(angle) * len[n] * 10
        y2 <- y1 + sin(angle) * len[n] * 10
        lines(c(x1, x2), c(y1, y2), lwd = lwd[n], col = col[n])
        drawTree(x2, y2, angle - pi/9, n - 1, lwd, len, col)
        drawTree(x2, y2, angle + pi/9, n - 1, lwd, len, col)
    }
}
par(mar = c(0, 0, 0, 0))
plot(0, xlim = c(-260, 260), ylim = c(0, 450), type = "n", axes = F)
drawTree(0, 0, angle = pi/2, n = 9, lwd = 1:9, len = 1:9,
        col = rev(terrain.colors(16)[1:9]))

主动承认是我的马甲。。。

切,马甲好玩吗?

不太好玩,帮同学申请小间时候有用~

你们居然在这里版聊 太有害身心健康了