几行代码,一个逼真的圣诞树,圣诞快乐
Posted qq_21478261
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了几行代码,一个逼真的圣诞树,圣诞快乐相关的知识,希望对你有一定的参考价值。
圣诞快乐~
上代码
library(tidyverse)
library(rlang)
source("R/grow_tree.R")
# step1、插上树枝
angle_fun1 <- function(angle) angle + c(-0.1 * pi, 0.1 * pi)
length_fun1 <- function(length) 0.85 * length
surv_fun1 <- function() 0.9
set.seed(12345)
tree1 <- grow_tree(n_iter = 10, angle_fun = angle_fun1(angle), length_fun = length_fun1(length),
surv_fun = surv_fun1(), verbose = FALSE)
# step2、生出树叶
angle_fun2 <- function(angle, generation)
w <- 1 - 1/generation
a0 <- rnorm(1, 0.12 * w * pi, 0.05 * w * pi)
angle + sample(c(-a0, a0))
length_fun2 <- function(length) rnorm(2, 0.9, 0.05) * length
surv_fun2 <- function(generation, n_iter) c(0.75 - (n_iter - generation[1])/(2 *
n_iter), 0.95)
set.seed(999)
tree2 <- grow_tree(n_iter = 25, angle_fun2(angle, generation), length_fun2(length),
surv_fun2(generation, 25), verbose = FALSE)
# step3、结上果子
tree2_clean <- clean_tree(tree2)
set.seed(13579)
baubles <- filter(tree2_clean, generation == 25, pos == 0) %>%
sample_n(30)
p1 + geom_point(data = baubles, aes(x = x, y = y), fill = "#AA1243", col = 1, pch = 21,
size = 5) + geom_point(data = baubles, aes(x = x, y = y), col = "white", alpha = 0.3,
size = 1, position = position_nudge(x = -0.08, y = 0.08))
以上是关于几行代码,一个逼真的圣诞树,圣诞快乐的主要内容,如果未能解决你的问题,请参考以下文章
话题今冬本来就裁员,阿里Antd圣诞彩蛋几行代码变“炸弹”!
Unity中几行代码画一颗圣诞树(Debug.log永远的神)