【问题标题】:Reproducing "Computer composition with lines" in R在 R 中重现“带有线条的计算机组合”
【发布时间】:2023-03-15 22:19:01
【问题描述】:

伙计们,

我正在尝试使用 ggplot 在 R 中重现 A. Michael Noll 的著名计算机艺术作品“带有线条的计算机组合”。

这里是原文:https://collections.vam.ac.uk/item/O1193787/computer-composition-with-lines-photograph-noll-a-michael/

我做到了可以创建一个随机的黑色或白色像素圆圈,但我很难创建类似于 Noll 使用的图案。

我可以轻松地创建一个由 1 和 0 组成的矩阵,然后切掉圆外的部分。但是模式(我试过uniform、beta、normal...)肯定和白噪声太相似了,而原作的随机性是有结构的。

library(tidyverse)

# this generates the matrix
genData <- function(N) {

  # a N*N matrix of ones and zero according to a rounded beta draw
  df <- tibble(x = rep(seq(1,N), N),
         y = rep(seq(1,N), each = N),
         z = round(rbeta(N*N, 2, 1)))

  # centering on zero and cutting away all points outside of a circle
  df %>% 
    mutate(x = x-(N/2 + 1), y = y-(N/2 + 1)) %>% 
    filter(x^2 + y^2 < (N/2)^2)
}

#this plots the data
plotData <- function(df, color = "black"){
  df %>% 
    ggplot(aes(x,y, fill = as.factor(z)))+
    geom_tile()+
    scale_fill_manual(values = c(color, "white"))+
    coord_equal()+
    theme_void()+
    theme(legend.position = "none")
}

#executing
genData(100) %>% 
  plotData()

结果:

我想问题归结为我可以在这里使用哪个随机过程?我没有在网上找到任何线索。

【问题讨论】:

    标签: r ggplot2 random


    【解决方案1】:

    我认为这会让你更接近一点。我还通过使用geom_segment 缩短了代码,它允许从泊松分布中得出长度。

    它包含一些使顶部的行更短的逻辑。

    如果你用不同的随机种子尝试这个,你可能会找到你满意的东西:

    draw_picture <- function(seed = 1, density = 1, length = 2, 
                             col = "black", bg = "gray90")
    {
      set.seed(seed)
      
      x <- sample(100, 600 * density, TRUE) - 50
      y <- sample(100, 600 * density, TRUE) - 50
      ss <- which(sqrt(x^2 + y^2) < 50)
      x <- x[ss]
      y <- y[ss]
      orient <- sample(2, length(x), TRUE)
      
      lambda <- abs(ifelse(y > 0, length - 2/3 * length * abs(atan(y/x)), length))
      lens <- rpois(length(x), lambda) + 1
      end_x <- (orient %% 2) * lens + x
      end_y <- (orient - 1) * lens + y
      df <- data.frame(x, y, end_x, end_y)
      
      ggplot(df, aes(x, y)) +
        geom_segment(aes(xend = end_x, yend = end_y), color = col, size = 2) +
        coord_equal() +
        theme_void() +
        theme(panel.background = element_rect(fill = bg, color = NA))
    }
    

    所以你可以这样做:

    draw_picture(8)
    

    或者用参数自定义:

    draw_picture(2020, density = 0.9, length = 5, col = "#567AFF", bg = "#2345A0")
    

    【讨论】:

    • 太棒了。谢谢,肯定越来越近了。我没有想过使用 geom_segment,我正在考虑某种生活规则的游戏规则,以便片段“出现”。我想剩下的(据我所知很难)是在顶部有点状的人工制品,而在底部有更多的部分。随机过程必须以某种方式取决于位置,但我不知道如何。谢谢!
    • @PaoloCrosetto 这也是可能的,尽管我不确定这是否也只是随机的。等我回到电脑前再看看。
    • 你不能让length 成为xy 的函数吗?例如与75,75的距离
    • @PaoloCroset 来查看我的更新。这距离更近了一点。
    猜你喜欢
    • 2016-03-22
    • 2015-04-22
    • 2022-01-13
    • 2021-09-09
    • 2014-11-10
    • 2016-10-22
    • 2016-12-29
    • 2015-03-21
    相关资源
    最近更新 更多