yihui/MSG — Issue #14: 递归树
Author: yihui
Created: 2011-11-24 03:04:46+00:00
State: open
Labels: TODO

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

```r
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)
}
}
COL <- rev(terrain.colors(16)[1:9])
par(mar = c(0, 0, 0, 0), ask = TRUE)
for (i in 1:9) {
plot(0, xlim = c(-260, 260), ylim = c(0, 450), type = "n", axes = F)
drawTree(0, 0, angle = pi/2, n = i, lwd = (10 - i):9, len = (10 - i):9,
col = COL[(10 - i):9])
}
```