Abstract expressionism

According to the ideas of abstract expressionism, perhaps math objects like shapes, dots and curves can be plotted in a pseudo-random fashion to create unique plots.

Plotting sine curves

First, plot simple sine curve

curve(sin(x),from = 0, to = 2*pi)

What if this curve could start at a randomly generated point (assume square 1x1 canvas)?

# initiate empty plot
plot(1, type="n", xlab="", ylab="", xlim=c(0, 1), ylim=c(0, 1))

ggplot() + geom_blank()

plot(0, type = 'n', axes = FALSE, ann = FALSE)

# box("aquamarine3")

# call new plot
# plot.new()
# par(new = TRUE)
plot(NULL, xlab="", ylab="", xaxt="n", yaxt="n",
     xlim=c(0, 1), ylim=c(0, 1))
# add to a previous plot with lines
t <- seq(0,0.2,0.001)
y <- sin(t*(pi/0.2))*0.2
points(t,y,type = "l")

# move plot by random
t1 <- t+runif(length(t))
y1 <- sin(t1*(2*pi))
plot(NULL, xlab="", ylab="", xaxt="n", yaxt="n",
     xlim=c(0, 1), ylim=c(0, 1))
points(t1,y1,type = "p")

Not quite right. it evaluates \(sin()\) at points shifted to the right by random uniform \((0,1)\). One period on the \((0,1)\) window. Also, even though window is given as \((0,1)\), some negative points (outside of range) are also plotted.

# move plot by random
t1 <- t+rep(runif(1)*0.8,length(t))
y1 <- sin(t1*(2*pi/0.2))*0.2 + rep(runif(1)*0.8,length(t))
plot(NULL, xlab="", ylab="", xaxt="n", yaxt="n",
     xlim=c(0, 1), ylim=c(0, 1))
points(t1,y1,type = "l")

Now, try to write a loop.

plot(NULL, xlab="", ylab="", xaxt="n", yaxt="n",
      xlim=c(0, 1), ylim=c(0, 1),asp=1)
for (i in 1:100) {
  set.seed(i)
  r <- runif(1)
  s <- runif(1)
  # shift to span outside of the boundary as well
  points(t+rep((r*1.2)-0.2,length(t)),sin(t1*(2*pi/0.2))*0.2 + rep((s*1.2)-0.2,length(t)),type="l")
}

Since it is scaled correctly (possibly) to fill the whole image equally, try turning the function.

plot(NULL, xlab="", ylab="", xaxt="n", yaxt="n",
     xlim=c(-1, 1), ylim=c(-1, 1),asp=1)
# add to a previous plot with lines
t <- seq(-0.2,0.2,0.001)
# lower the amplitude from 0.2 to 0.1
y <- sin(t*(pi/0.2))*0.1
points(t,y,type = "l")
t1 <- t*cos(pi/2)-y*sin(pi/2)
y1 <- t*sin(pi/2)+y*cos(pi/2)
points(t1,y1,type = "l")

Now, after rotation shift randomly from the origin.

t <- seq(-0.2,0.2,0.001)
y <- sin(t*(pi/0.2))*0.2
t1 <- t*cos(pi/2)-y*sin(pi/2)
y1 <- t*sin(pi/2)+y*cos(pi/2)
shift <- rep((runif(1)*(2*sqrt(2)+0.4))-sqrt(2)-0.2,length(t1))
t2 <- t1+ shift
y2 <- y1 + shift
plot(NULL, xlab="", ylab="", xaxt="n", yaxt="n",
     xlim=c(-1, 1), ylim=c(-1, 1), asp=1)
points(t2,y2,type = "l")

plot(NULL, xlab="", ylab="", xaxt="n", yaxt="n",
      xlim=c(-1, 1), ylim=c(1, 1))
for (i in 1:1000) {
  set.seed(i)
  r <- runif(1)
  s <- runif(1)
  a <- runif(1)*2
t <- seq(-0.2,0.2,0.001)
y <- sin(t*(pi/0.2))*0.2
t1 <- t*cos(a*pi)-y*sin(a*pi)
y1 <- t*sin(a*pi)+y*cos(a*pi)
shift.t <- rep((r*(2*sqrt(2)+0.4))-sqrt(2)-0.2,length(t1))
shift.y <- rep((s*(2*sqrt(2)+0.4))-sqrt(2)-0.2,length(t1))
t2 <- t1+ shift.t
y2 <- y1 + shift.y

points(t2,y2,type = "l")
}

Add colour.

# svg("greenland_map.svg",width=500,height=500)
plot(NULL, xlab="", ylab="", xaxt="n", yaxt="n",
      xlim=c(-1, 1), ylim=c(-1, 1))
for (i in 1:200) {
  set.seed(i)
  r <- runif(1)
  s <- runif(1)
  a <- runif(1)*2
t <- seq(-0.2,0.2,0.001)
y <- sin(t*(pi/0.2))*0.1
t1 <- t*cos(a*pi)-y*sin(a*pi)
y1 <- t*sin(a*pi)+y*cos(a*pi)
shift.t <- rep((r*(2*sqrt(2)+0.4))-sqrt(2)-0.2,length(t1))
shift.y <- rep((s*(2*sqrt(2)+0.2))-sqrt(2)-0.1,length(t1))
t2 <- t1+ shift.t
y2 <- y1 + shift.y
basquiat <- function() { sample(c("#C11432","#009ADA","#66A64F","#FDD10A","#070707"),1)
}
points(t2,y2,type = "l",col=basquiat(),lwd=2)
} 

Try with ggplot2.

  r <- runif(1)
  s <- runif(1)
  a <- 1
t <- seq(-0.2,0.2,0.001)
y <- sin(t*(pi/0.2))*0.1
t1 <- t*cos(a*pi)-y*sin(a*pi)
y1 <- t*sin(a*pi)+y*cos(a*pi)
shift.t <- rep((r*(2*sqrt(2)+0.4))-sqrt(2)-0.2,length(t))
shift.y <- rep((s*(2*sqrt(2)+0.2))-sqrt(2)-0.1,length(t))
t2 <- t1+ shift.t
y2 <- y1 + shift.y
df <- data.frame(t2,y2,t1,y1,t,y)
ggplot()  + xlim(c(-1,1)) + ylim(c(-1,1)) +  geom_point(data=df,aes(x=t1,y=y1),col=basquiat()) + coord_fixed()

Try with a loop.

g <- ggplot() + xlim(c(-1,1)) + ylim(c(-1,1)) + theme_void()+ coord_fixed()
for (i in 1:20) {
  set.seed(i)
    r <- runif(1)
  s <- runif(1)
  a <- runif(1)*2
t <- seq(-0.2,0.2,0.001)
y <- sin(t*(pi/0.2))*0.1
t1 <- t*cos(a*pi)-y*sin(a*pi)
y1 <- t*sin(a*pi)+y*cos(a*pi)
shift.t <- rep((r*(2*sqrt(2)+0.4))-sqrt(2)-0.2,length(t))
shift.y <- rep((s*(2*sqrt(2)+0.2))-sqrt(2)-0.1,length(t))
t2 <- t1+ shift.t
y2 <- y1 + shift.y
df <- data.frame(t2,y2)
g <- g+ geom_point(data=df,aes(x=t2,y=y2),col=basquiat())
}
g
## Warning: Removed 260 rows containing missing values (`geom_point()`).
## Warning: Removed 242 rows containing missing values (`geom_point()`).
## Warning: Removed 401 rows containing missing values (`geom_point()`).
## Warning: Removed 181 rows containing missing values (`geom_point()`).
## Warning: Removed 401 rows containing missing values (`geom_point()`).
## Removed 401 rows containing missing values (`geom_point()`).
## Warning: Removed 55 rows containing missing values (`geom_point()`).
## Warning: Removed 401 rows containing missing values (`geom_point()`).
## Removed 401 rows containing missing values (`geom_point()`).
## Removed 401 rows containing missing values (`geom_point()`).
## Warning: Removed 21 rows containing missing values (`geom_point()`).
## Warning: Removed 401 rows containing missing values (`geom_point()`).
## Warning: Removed 233 rows containing missing values (`geom_point()`).
## Warning: Removed 401 rows containing missing values (`geom_point()`).
## Removed 401 rows containing missing values (`geom_point()`).

Too slow, try plotting at once.

# initiate empty dataframe
columns = c("X","Y","colour") 
df = data.frame(matrix(nrow = 0, ncol = length(columns))) 
colnames(df) = columns
for (i in 1:5000) {
  set.seed(i)
    r <- runif(1)
  s <- runif(1)
  a <- runif(1)*2
t <- seq(-0.2,0.2,0.001)
y <- sin(t*(pi/0.2))*0.1
t1 <- t*cos(a*pi)-y*sin(a*pi)
y1 <- t*sin(a*pi)+y*cos(a*pi)
shift.t <- rep((r*(2*sqrt(2)+0.4))-sqrt(2)-0.2,length(t))
shift.y <- rep((s*(2*sqrt(2)+0.2))-sqrt(2)-0.1,length(t))
t2 <- t1+ shift.t
y2 <- y1 + shift.y
df[(((i-1)*401)+1):(401*i),1] <- t2
df[(((i-1)*401)+1):(401*i),2] <- y2
df[(((i-1)*401)+1):(401*i),3] <-rep(basquiat(),401)

}
g <- ggplot(data=df,aes(x=X,y=Y,colour=colour)) + xlim(c(-1,1)) + ylim(c(-1,1)) + theme_void()+ coord_fixed() + geom_point()+ 
  scale_colour_identity()
g
## Warning: Removed 1181148 rows containing missing values (`geom_point()`).

# ggsave(filename = "v5.png",plot = g)