## R for aRt examples ## SECTION 1 ## FROM: https://www.r-graph-gallery.com/132-sunshine-dataart par(mar=c(0,0,0,0)) # all four margins are set to zero; default margin is 1 inch pie(abs(rnorm(100)), radius=10, border="transparent", xlim=c(0,5)) # abs(rnorm(100)) returns absolute positive values of 100 random numbers in normal distribution # radius = 10 indicates the radius of the circle of the pie chart as 10 (normally 1, which generates a circular pie) # border = transparent results in no borders are drawn between slices of the pie # xlim=c(0,5) limits the piechart to the values 0 to 5 ## * * * * * * * * * * * * * * * * * ## SECTION 2 ## FROM: http://www.r-graph-gallery.com/57-rays-abstract-painting/ ## generate pairs of x-y values theta = seq(0, pi, length = 300) x = cos(theta) y = sin(theta) ## set graphical parameters op = par(bg = "black", mar = rep(0.5, 4)) ## plot plot(x, y, type = 'n') segments(rep(0, 299), rep(0, 299), x[1:299] * runif(299, 0.7), y[1:299] * runif(299, 0.7), col = hsv(runif(299, 0.45, 0.55), 1, 1, runif(299, 0.5)), lwd = 5*runif(299)) ## signature legend("topleft", legend = "19 Nisan 2019", bty = "n", text.col = "gray70") ## * * * * * * * * * * * * * * * * * ## SECTION 3 ## https://fronkonstin.com/2016/03/01/a-silky-drawing-and-a-tiny-experiment ## The code below is the corrected one from the same page library(magrittr) library(ggplot2) opt = theme(legend.position = "none", panel.background = element_rect(fill="violetred4"), axis.ticks = element_blank(), panel.grid = element_blank(), axis.title = element_blank(), axis.text = element_blank()) W = seq(from=-10, to=10, by = 0.05) D8 = data.frame(expand.grid(x=W, y=W)) ggplot(data=D8, aes(x=(x+3*sin(y)), y=(y+3*cos(x)))) + geom_point(alpha=.1, shape=20, size=1, color="white") + opt ## * * * * * * * * * * * * * * * * * ## SECTION 4 ## https://fronkonstin.com/2014/10/01/complex-domain-coloring/ require(ggplot2) f = function(x) (1+1i)*log(sin((x^3-1)/x)) z=as.vector(outer(seq(-5, 5, by =.01),1i*seq(-5, 5, by =.01),'+')) z=data.frame(x=Re(z), y=Im(z), h=(Arg(f(z))<0)*1+Arg(f(z))/(2*pi), s=(1+sin(2*pi*log(1+Mod(f(z)))))/2, v=(1+cos(2*pi*log(1+Mod(f(z)))))/2) z=z[is.finite(apply(z,1,sum)),] opt=theme(legend.position="none", panel.background = element_blank(), panel.grid = element_blank(), axis.ticks=element_blank(), axis.title=element_blank(), axis.text =element_blank()) ggplot(data=z, aes(x=x, y=y)) + geom_tile(fill=hsv(z$h,z$s,z$v))+ opt ## * * * * * * * * * * * * * * * * * ## SECTION 5 ## title: "Reproducible psychedelic art with R: a tribute to spatstat" ## author: "Petr Keil" ## installing the "spatstat" package ## install.packages("spatstat") ## Loading the `spatstat` library library(spatstat) ## Defining the 2:3 window W23 <- as.owin(list(xrange=c(0,3), yrange=c(0,2))) ## Figure 1 (http://www.petrkeil.com/?p=2707) ## Generate the patterns: set.seed(1612) # The exponent Lambda <- 5 # Lay down the longest lines main.lines <- psp(runif(3),runif(3),runif(3),runif(3), window=W23) # Sample points proportionally to the distance to the lines dist.from.line <- distmap(main.lines) # exponential transformation of the distance dist.from.line.exp <- Lambda*exp(-Lambda*dist.from.line) samp.pois <- rpoispp(dist.from.line.exp*15) # Project to the lines using project2segment(b, a) Xproj <- project2segment(samp.pois, main.lines)$Xproj sub.lines <- psp(samp.pois$x, samp.pois$y, Xproj$x, Xproj$y, window=W23) # Connect with the lines all.lines <- append.psp(main.lines, sub.lines) dist.from.all.lines <- distmap(all.lines, dimyx=c(1200, 800)) # FIGURE 1: par(mai=c(0,0,0,0)) dist.from.all.lines.exp <- exp(-Lambda*dist.from.all.lines) plot(dist.from.all.lines.exp, legend=FALSE, main="", box=FALSE, ribbon=FALSE) contour(dist.from.all.lines.exp, add=TRUE, col="white") contour(dist.from.all.lines, col="black", add=TRUE, lwd=4, levels=0.2) contour(dist.from.all.lines, col="black", add=TRUE, lwd=2, levels=0.3) contour(dist.from.all.lines, col="black", add=TRUE, lwd=2) plot(sub.lines, add=T, lty=2, col="black", lwd=1) plot(main.lines, add=T, col="black", lwd=4) # FIGURE 2: # Generate the pattern: set.seed(16211) rc <- rpoispp(function(x,y){50 * exp(-3*(max(y)-y))}, 100, win=W23) rcdist <- distmap(rc, dimyx=c(1200, 800)) rc2 <- rpoispp(1/rcdist*50) rcd <- dirichlet(rc2) # To see the art on the screen, do not use the first and last lines of the following block. par(mai=c(0,0,0,0)) plot(rcdist, legend=FALSE, main="", frame=FALSE, box=FALSE, ribbon=FALSE) plot(rcd, add=T) plot(rc, add=T, col="black", pch=19, cex=2.5) plot(rjitter(rc, 0.01), add=T, col="white", pch=19, cex=0.4) contour(rcdist, add=T, col="white") ## * * * * * * * * * * * * * * * * * ## SECTION 6 ## FROM: http://www.r-graph-gallery.com/55-double-heart-abstract-painting # generate pairs of x-y values theta = seq(-2 * pi, 2 * pi, length = 300) x = cos(theta) y = x + sin(theta) # set graphical parameters op = par(bg = "black", mar = rep(0.1, 4)) # For white background: op = par(bg = "white", mar = rep(0.1, 4)) # generate pairs of x-y values theta = seq(-2 * pi, 2 * pi, length = 300) x = cos(theta) y = x + sin(theta) # set graphical parameters op = par(bg = "black", mar = rep(0.1, 4)) # plot plot(x, y, type = "n", xlim = c(-8, 8), ylim = c(-1.5, 1.5)) for (i in seq(-2*pi, 2*pi, length = 100)) { lines(i*x, y, col = hsv(runif(1, 0.85, 0.95), 1, 1, runif(1, 0.2, 0.5)), lwd = sample(seq(.5, 3, length = 10), 1)) } # signature legend("bottomright", legend = "19 Nisan 2019", bty = "n", text.col = "gray70")