# Geometric Line Designs in R

When I was in elementary school, I remember making geometric line designs using a ruler and graph paper. My magnum opus in the Logo programming language for kids was making the turtle draw one. I did the same in R, but this time around I wasn't limited to black and white pixelated lines on an old Apple IIe:

With a frame:

Then a bit more complex with an isometric cube:

And colored all fancy-like:

The R code to make them is below, though it's a bit thrown together.

## Technical Notes

Here's the code to make the last hexagon one:

# Function to fill in an angle with straight lines, making a curve. draw.angle = function (angle, numpoints) { # Get points between the end points of the two segments xpts1 = seq(angle$x[1], angle$x[2], length.out=numpoints) ypts1 = seq(angle$y[1], angle$y[2], length.out=numpoints) xpts2 = seq(angle$x[3], angle$x[2], length.out=numpoints) ypts2 = seq(angle$y[3], angle$y[2], length.out=numpoints) for (p in 1:(numpoints-1)) { x0 = xpts1[p] y0 = ypts1[p] x1 = xpts2[numpoints - p] y1 = ypts2[numpoints - p] color = decide.color(numpoints, p) segments(x0=x0, y0=y0, x1=x1, y1=y1, col = color) } } draw.hex = function (x) { angle = data.frame(x=c(hexagon_pts$x[x[1]], hexagon_pts$x[x[2]], hexagon_pts$x[x[3]]), y=c(hexagon_pts$y[x[1]], hexagon_pts$y[x[2]], hexagon_pts$y[x[3]])) draw.angle(angle, 30) } decide.color = function (numpoints, p1) { # Overwrite this to change color. pal = colorRampPalette(c("red", "orange", "blue"), space = "rgb")(numpoints) color = pal[max(p1, numpoints - p1)] return (color) } # Make empty pot par(bg="black") plot(1, xlab="", ylab='', xaxt='n', yaxt='n', type='n', xlim=c(-1,1), ylim=c(-1,1)) # Points of an isometric cube (a hexagon, plus the origin) hexagon_pts = data.frame(x=c(0, sqrt(3)/2, sqrt(3)/2, 0, -sqrt(3)/2, -sqrt(3)/2, 0), y=c(1, 1/2, -1/2, -1, -1/2, 1/2, 0)) # Matrix of angles to fill in with lines angles = matrix(data=c( 2,3,4, 4,5,6, 6,1,2, 1,2,7, 7,2,3, 3,4,7, 7,4,5, 5,6,7, 7,6,1, 2,7,4, 4,7,6, 6,7,2), nrow=12, byrow=TRUE) apply(angles, 1, draw.hex)