美文网首页R - tips
参数化——蝴蝶

参数化——蝴蝶

作者: 董八七 | 来源:发表于2018-03-30 16:28 被阅读4次

    参照Using Mathematical Formulas to Draw Butterflies

    buter <- matrix(NA,40000,3)
    for (k in 1:40000) {
      buter[k,1] = (6/5) * (cos(141 * pi * k/40000))^9 * (1 - (1/2) * 
        (sin(pi * k/40000))^3) * (1 - (1/4) * (cos(2 * pi * k/40000))^30 * 
        (1 + (2/3) * (cos(30 * pi * k/40000))^20) - (sin(2 * 
        pi * k/40000))^10 * (sin(6 * pi * k/40000))^10 * ((1/5) + 
        (4/5) * (cos(24 * pi * k/40000))^20))
      
      buter[k,2] = cos(2 * pi * k/40000) * (cos(141 * pi * k/40000))^2 * 
        (1 + (1/4) * (cos(pi * k/40000))^24 * (cos(3 * pi * k/40000))^24 * 
          (cos(19 * pi * k/40000))^24)
      
      buter[k,3] = (1/100) + (1/40) * ((cos(2820 * pi * k/40000))^6 + 
        (sin(141 * pi * k/40000))^2) * (1 - (cos(pi * k/40000))^16 * 
        (cos(3 * pi * k/40000))^16 * (cos(12 * pi * k/40000))^16)
    }
    buter <- buter %>% as.data.frame %>% setNames(c("X","Y","R"))
    g <- ggplot(buter, aes(X,Y))
    g+geom_count(size=buter$R)+theme_bw()
    
    butterfly.png

    相关文章

      网友评论

        本文标题:参数化——蝴蝶

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