# # ################################################################################ # # The Lissajous Curve(s): http://en.wikipedia.org/wiki/Lissajous_curve a <- 5 # Change this, but always bigger than "b". b <- 2 # Change this, but always smaller than "a". N <- 10 A <- 3 # Narrow or Wide. B <- 3 # Tall or Short. delta <- ((N - 1)/N) * (pi/2) n <- 1000 t <- seq(1,n, by = 1) x <- A * sin((a*t[1]) + delta) y <- B * sin(b*t[1]) plot(x,y, col = "red", xlim = c(-3,3), ylim = c(-3,3)) for(i in 1:n){ new.x <- A * sin((a*t[i]) + delta) new.y <- B * sin(b*t[i]) par(new = T) plot(new.x,new.y, col = "blue", xlim = c(-3,3), ylim = c(-3,3)) Sys.sleep(.01) if(i == n){print("DONE")} } # Alternative forms: http://www.2dcurves.com/higher/higherli.html # x <- sin(t) # y <- sin((a*t) + b) ################################################################################ # Butterfly curve (transcendental) # http://en.wikipedia.org/wiki/Butterfly_curve_%28transcendental%29 n <- 850 e <- 2.718281828 t <- seq(1:n) x <- 0; y <- 0 plot(x, y, xlim = c(-4,4), ylim = c(-4,4), col = "red", pch = 1, xlab = "X", ylab = "Y") for(i in 1:n){ new.x <- sin(t[i]) * ((e^(cos(t[i]))) - 2*cos(4*t[i])) new.y <- cos(t[i]) * ((e^(cos(t[i]))) - 2*cos(4*t[i])) par(new = T) plot(new.x, new.y, xlim = c(-4,4), ylim = c(-4,4), col = "darkblue", pch = 1, xlab = "X", ylab = "Y") Sys.sleep(.01) if(i == n){print("DONE")} } ################################ # Somewhat the reverse of what was just done above. n <- 850 e <- 2.718281828 t <- seq(1:n) x <- 0; y <- 0 plot(x, y, xlim = c(-4,4), ylim = c(-4,4), col = "red", pch = 1, xlab = "X", ylab = "Y") for(i in 1:n){ new.x <- sin(t[i]) * ((e^(cos(t[i]))) - 2*cos(4*t[i]) - ((sin(5))*(t/12))) new.y <- cos(t[i]) * ((e^(cos(t[i]))) - 2*cos(4*t[i]) - ((sin(5))*(t/12))) par(new = T) plot(new.x, new.y, xlim = c(-4,4), ylim = c(-4,4), col = "darkblue", pch = ".", xlab = "X", ylab = "Y") Sys.sleep(.01) if(i == n){print("DONE")} } ################################ # Another slight variation. n <- 850 e <- 2.718281828 t <- seq(1:n) x <- 0; y <- 0 plot(x, y, xlim = c(-4,4), ylim = c(-4,4), col = "red", pch = 1, xlab = "X", ylab = "Y") for(i in 1:n){ new.x <- sin(t[i]) * ((e^(cos(t[i]))) - 2*cos(4*t[i]) + ((sin(5))*(t/12))) new.y <- cos(t[i]) * ((e^(cos(t[i]))) - 2*cos(4*t[i]) + ((sin(5))*(t/12))) par(new = T) plot(new.x, new.y, xlim = c(-4,4), ylim = c(-4,4), col = "darkblue", pch = ".", xlab = "X", ylab = "Y") Sys.sleep(.01) if(i == n){print("DONE")} } ################################ # Multi-colored, with some variation from applying weights. n <- 7000 e <- 2.718281828 t <- seq(1:n) v <- c(2,3,4) my.col <- c("blue","lightblue","lightgreen","darkgreen","darkblue") x <- 0; y <- 0 plot(x, y, xlim = c(-5,5), ylim = c(-6,6), col = "red", pch = 1, xlab = "X", ylab = "Y") for(i in 1:n){ w <- sample(v, 1) new.x <- sin(t[i]) * ((e^(cos(t[i]))) - w*cos(4*t[i])) new.y <- cos(t[i]) * ((e^(cos(t[i]))) - w*cos(4*t[i])) par(new = T) plot(new.x, new.y, xlim = c(-5,5), ylim = c(-6,6), col = sample(my.col, 1), pch = 1, xlab = "X", ylab = "Y") if(i == n){print("DONE")} } ################################ # Another slight variation. n <- 7000 e <- 2.718281828 t <- seq(1:n) v <- c(2,3,4) x <- 0; y <- 0 plot(x, y, xlim = c(-4,4), ylim = c(-4,4), col = "red", pch = 1, xlab = "X", ylab = "Y") for(i in 1:n){ m <- sample(v, 1) new.x <- sin(t[i]) * ((e^(cos(t[i]))) - 2*cos(m*t[i])) new.y <- cos(t[i]) * ((e^(cos(t[i]))) - 2*cos(m*t[i])) par(new = T) plot(new.x, new.y, xlim = c(-4,4), ylim = c(-4,4), col = "blue", pch = ".", xlab = "X", ylab = "Y") if(i == n){print("DONE")} } ################################ # Alternative... n <- 800 e <- 2.718281828 t <- seq(1:n) x <- 0; y <- 0 plot(x, y, xlim = c(-4,4), ylim = c(-4,4), col = "red", pch = 1, xlab = "X", ylab = "Y") for(i in 1:n){ new.x <- sin(t[i]) * ((e^(cos(t[i]))) - 2*cos(4*t[i]) - ((sin(1)^5)*(t/12))) new.y <- cos(t[i]) * ((e^(cos(t[i]))) - 2*cos(4*t[i]) - ((sin(1)^5)*(t/12))) par(new = T) plot(new.x, new.y, xlim = c(-4,4), ylim = c(-4,4), col = "darkblue", pch = ".", xlab = "X", ylab = "Y") Sys.sleep(.05) if(i == n){print("DONE")} } ################################ # From: http://paulbourke.net/geometry/butterfly/ # x = cos(u) (ecos(u) - 2 cos(4 u) - sin(u / 12)5.0) --> Here, 'u' is theta, or 't' below. # y = sin(u) (ecos(u) - 2 cos(4 u) - sin(u / 12)5.0) n <- 3000 x.vec <- as.vector(0) y.vec <- as.vector(0) e <- 2.718281828 t <- seq(1,n) for(i in 1:n){ x <- cos(t[i]) * ((e^(cos(t[i]))) - (2*cos(4*t[i])) - (sin(t[i]/12)^5)) y <- sin(t[i]) * ((e^(cos(t[i]))) - (2*cos(4*t[i])) - (sin(t[i]/12)^5)) x.vec[i] <- y y.vec[i] <- x } plot(x.vec,y.vec, col = "darkgreen") ################################ ################################ # And finally, this is what the Butterfly is supposed to look like. # Note: this takes a minute or so. n <- 15000 e <- 2.718281828 t <- seq(1:n) my.col <- c("blue","lightblue","lightgreen","darkgreen","darkblue") x <- 0; y <- 0 plot(x, y, xlim = c(-4,4), ylim = c(-3,4), col = "red", pch = 1, xlab = "X", ylab = "Y") for(i in 1:n){ new.x <- cos(t[i]) * ((e^(cos(t[i]))) - (2*cos(4*t[i])) - (sin(t[i]/12)^5)) new.y <- sin(t[i]) * ((e^(cos(t[i]))) - (2*cos(4*t[i])) - (sin(t[i]/12)^5)) par(new = T) plot(new.y, new.x, xlim = c(-4,4), ylim = c(-3,4), col = sample(my.col, 1), pch = ".", xlab = "X", ylab = "Y") if(i == n){print("DONE")} } # Larger points; more pronounced. n <- 15000 e <- 2.718281828 t <- seq(1:n) my.col <- c("blue","lightblue","lightgreen","darkgreen","darkblue") x <- 0; y <- 0 plot(x, y, xlim = c(-4,4), ylim = c(-3,4), col = "red", pch = 1, xlab = "X", ylab = "Y") for(i in 1:n){ new.x <- cos(t[i]) * ((e^(cos(t[i]))) - (2*cos(4*t[i])) - (sin(t[i]/12)^5)) new.y <- sin(t[i]) * ((e^(cos(t[i]))) - (2*cos(4*t[i])) - (sin(t[i]/12)^5)) par(new = T) plot(new.y, new.x, xlim = c(-4,4), ylim = c(-3,4), col = sample(my.col, 1), pch = 1, xlab = "X", ylab = "Y") if(i == n){print("DONE")} } ################################################################################ # Torus: # http://en.wikipedia.org/wiki/Parametric_equation # See the "Parametric Surfaces" section. # Torus with major radius R and minor radius r may be defined parametrically as # x = cos(t)*(R + (r*cos(u))) # y = sin(t)*(R + (r*cos(u))) # z = r*sin(u) # where the two parameters t and u both vary between 0 and 2*pi. # Example 1: Not a Torus, but still interesting. library(scatterplot3d) n <- 63 x.fun <- function(t,R,r){x <- cos(t)*(R + (r*cos(u))); return(x)} y.fun <- function(t,R,r){y <- sin(t)*(R + (r*cos(u))); return(y)} z.fun <- function(r,u){z <- rep(r*sin(u),n); return(z)} R <- 2 r <- 1/2 t <- seq(0, 2*pi, by = 0.1) u <- seq(0, 2*pi, by = 0.1) x <- 0; y <- 0; z <- 0 scatterplot3d(x, y, z, highlight.3d = TRUE, xlab = "x", ylab = "y", zlab = "z", type = "p", col.axis = "blue", angle = 55, col.grid = "lightblue", scale.y = 0.7, pch = 1, xlim = c(-3, 3), ylim = c(-3, 3), zlim = c(-3, 3)) for(i in 1:n){ new.x <- x.fun(t[i], R, r) new.y <- y.fun(t[i], R, r) new.z <- z.fun(r, u[i]) par(new = T) scatterplot3d(new.x, new.y, new.z, highlight.3d = TRUE, xlab = "x", ylab = "y", zlab = "z", type = "p", col.axis = "blue", angle = 55, col.grid = "lightblue", scale.y = 0.7, pch = ".", xlim = c(-3, 3), ylim = c(-3, 3), zlim = c(-3, 3)) Sys.sleep(.25) if(i == n){print("DONE")} } ################################ # Example 2: Torus. library(scatterplot3d) n <- 10000 x.fun <- function(t,R,r){x <- cos(t)*(R + (r*cos(u))); return(x)} y.fun <- function(t,R,r){y <- sin(t)*(R + (r*cos(u))); return(y)} z.fun <- function(r,u){z <- r*sin(u); return(z)} R <- 2 r <- 1/2 TT <- seq(0, 2*pi, by = 0.1) U <- seq(0, 2*pi, by = 0.1) x <- 0; y <- 0; z <- 0 scatterplot3d(x, y, z, highlight.3d = TRUE, xlab = "x", ylab = "y", zlab = "z", type = "p", col.axis = "blue", angle = 55, col.grid = "lightblue", scale.y = 0.7, pch = 1, xlim = c(-3, 3), ylim = c(-3, 3), zlim = c(-3, 3)) for(i in 1:n){ t <- sample(TT, 1) u <- sample(U, 1) new.x <- x.fun(t, R, r) new.y <- y.fun(t, R, r) new.z <- z.fun(r, u) par(new = T) scatterplot3d(new.x, new.y, new.z, highlight.3d = TRUE, xlab = "x", ylab = "y", zlab = "z", type = "p", col.axis = "blue", angle = 55, col.grid = "lightblue", scale.y = 0.7, pch = ".", xlim = c(-3, 3), ylim = c(-3, 3), zlim = c(-3, 3)) if(i == n){print("DONE")} } ################################################################################ <<< ##################### Mr. Fibbles' random wibbles. ############################# >>> ################################################################################ # "Can you get to a phone?" library(RColorBrewer) my.col <- brewer.pal(09, "Greens") my.col <- my.col[9:2] n <- 50 x <- seq(1, n, by = 1) y <- seq(1, n, by = 1) grid <- matrix(sample(c(letters,seq(1:9)), n^2, replace = T), nrow = n, ncol = n) grid.n <- nrow(grid) * ncol(grid) par(bg = "#002200") plot(x, y, xlab = " ", ylab = " ", main = "The Matrix", col.main = my.col[8], xlim = c(1,n), ylim = c(1,n), col = "#003300") for(j in 1:10){ new.x <- 1 new.y <- n + 1 for(i in 1:grid.n){ new.y <- new.y - 1 if(new.y == 0){new.y <- n; new.x <- new.x + 1; if(j > 1){new.x <- sample(n, 1)}} par(new = T) plot(new.x, new.y, xlab = " ", ylab = " ", main = "The Matrix", col.main = my.col[8], xlim = c(1,n), ylim = c(1,n),col = sample(my.col, 1), pch = grid[new.x,new.y]) } rm(i, new.x, new.y) } # End; Dec. 2, 2011.