在 R 中重现“带有线条的计算机组合”

Pao*_*tto 12 random r ggplot2

各位,

我正在尝试使用 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()
Run Code Online (Sandbox Code Playgroud)

结果是:

在此处输入图片说明

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

All*_*ron 10

我认为这会让你更接近一点。我还通过使用 缩短了代码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))
}
Run Code Online (Sandbox Code Playgroud)

所以你可以这样做:

draw_picture(8)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

或者使用参数自定义它:

draw_picture(8)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明