#=======================================================# # Copyright (c) 2018. Yu-Cheng Ku. All Rights Reserved. # # A Short-Song Ballad # # Written by Yu-Cheng Ku # #=======================================================# win.graph(width = 13.2, height = 7.7) par(mai = rep(0, 4), bg = "midnightblue") plot(c(0,0), type="n", xlim=c(-7, 3), ylim=c(0, 5)) n_scale = 20 for(i in 1:n_scale) { range_u = 1 + i * (5-(0.2))/n_scale lines(rbind(c(-9,range_u),c(5,range_u)), col = rgb(60-3*i, 6, 95, max = 255), lwd = 35) } ## Stars here nstars = 80 #Number of stars to draw mstars = matrix(runif(2*nstars), ncol=2) mstars[,1] = 10 * mstars[,1] - 7 mstars[,2] = 5 * mstars[,2] mstars2 = matrix(runif( round(2*0.4*nstars) ), ncol=2) mstars2[,1] = 10 * mstars2[,1] - 7 mstars2[,2] = 5 * mstars2[,2] mstars3 = matrix(runif( round(2*0.1*nstars) ), ncol=2) mstars3[,1] = 10 * mstars3[,1] - 7 mstars3[,2] = 5 * mstars3[,2] points(mstars, col = "grey95", cex=.2, pch=".") points(mstars2, col = "grey95", cex=.3, pch=-as.hexmode(9733)) points(mstars3, col = "grey95", cex=.45, pch=-as.hexmode(9733)) ## Mountain m2.x = c(-5, 1.8, 2.3, 5) m2.y = c(1.1, 1.9, 1.9, 1.1) polygon(m2.x, m2.y, col = "#200C3D") m1.x = c(-9, -4, -3.5, 2) m1.y = c(1.23, 2.2, 2.2, 1) polygon(m1.x, m1.y, col = "#100125") ############ # The moon # ############ scale = 1.25 # The shape points(x = -4.8, y = 3.9, cex = 25, pch = 16, col = "lightgoldenrod1") ########## # Ground # ########## # right end.p1 = seq(-3, 4, by=0.1) lines(end.p1, rep(0.52, length(end.p1)) - 0.001 * c(1:length(end.p1)), col = rgb(13, 57, 30, max = 255), lwd=200) # left end.p2 = seq(-9, -3, by=0.1) lines(end.p2, rep(0.45, length(end.p2)) + 0.0011 * c(1:length(end.p2)), col = rgb(13, 57, 30, max = 255), lwd=200) ############### # Tree shadow # ############### p = rnorm(400, mean = 0, sd = 0.5/2) for (j in 1:9) { p = c(p, rnorm(2000, mean = 0, sd = sqrt(j)/2)) } p = p/5 t = 4 * (1/length(p)) * c(1:length(p)) shadow = cbind(t, p) angle2 = 12 * pi/180 rotate = matrix(c(cos(angle2), sin(angle2), -sin(angle2), cos(angle2)), 2, 2) shadow = shadow %*% rotate shadow[,1] = shadow[,1] - 0.03 shadow[,2] = shadow[,2]/2 + 0.77 points(shadow, pch = ".", col = rgb(0, 27, 0, max = 255)) ############ # The tree # ############ ## Jittered L-system Fractal Tree ## By Antonio Sanchez Chinchon ## https://fronkonstin.com/tag/fractals/ depth = 9 b_angle = 42 #Between branches division L = 0.85 #Decreasing rate of branches by depth branches = rbind(c(1,0,0,abs(jitter(0)),1,jitter(5, amount = 5)), data.frame()) colnames(branches) = c("depth", "x1", "y1", "x2", "y2", "inertia") for(i in 1:depth) { df = branches[branches$depth==i,] for(j in 1:nrow(df)) { branches = rbind(branches, c(df[j,1]+1, df[j,4], df[j,5], df[j,4]+L^(2*i+1)*sin(pi*(df[j,6]+b_angle)/180), df[j,5]+L^(2*i+1)*cos(pi*(df[j,6]+b_angle)/180), df[j,6]+b_angle-jitter(5))) branches = rbind(branches, c(df[j,1]+1, df[j,4], df[j,5], df[j,4]+L^(2*i+1)*sin(pi*(df[j,6]-b_angle)/180), df[j,5]+L^(2*i+1)*cos(pi*(df[j,6]-b_angle)/180), df[j,6]-b_angle-jitter(5))) } } nodes = rbind(as.matrix(branches[,2:3]), as.matrix(branches[,4:5])) X = Y = NULL for (i in 1:nrow(branches)) { color = 4 if(i >= 2) { color = as.character(sample(seq(from=1, to=3, by=1), 1)) } lines( x = branches[i,c(2,4)], y = branches[i,c(3,5)]+0.8, col = paste("sienna", color, sep = ""), lwd = (65/(1+3*branches[i,1]))) X = rbind(X, branches[i,c(2,4)]) Y = rbind(Y, branches[i,c(3,5)]+0.8) } ############# # The River # ############# ## Logistic Equation Chaos ## by Mario dos Reis. -- October 2003 ## http://people.cryst.bbk.ac.uk/~fdosr01/Rfractals/code/logistic.R lg = function(x, r) r * x * (1 - x) gen = 75 # number of initial generations r.min = 3.2 r.max = 6 p = 1.1 div = 5000 # plot resolution along the x axis R = NULL X = NULL for(r in seq(r.min, r.max, by = r.max/div)) { x.init = .005 for(i in seq(0, gen)) { x.next = lg(x.init, r) x.init = x.next if(i > 40) { R = c(R, r) X = c(X, x.init) } } } out = cbind((R-3.2)*20, 0.5*X) angle = 2 * pi/180 rotate = matrix(c(cos(angle), sin(angle), -sin(angle), cos(angle)), 2, 2) out1 = out %*% rotate + 0.2 out1[,1] = out1[,1] - 15 out1[,2] = out1[,2] * 2.8 - 0.05 out2 = out1 out2[,1] = out2[,1] + 2 out2[,2] = out2[,2] - 0.2 # River starts points(out1, pch = "~", col = "darkblue") points(out2, pch = "~", col = "darkblue") # Randomly select some points to put on waves points(out1[sample(20000:nrow(out1), 0.1 * nrow(out1)),], pch = "~", col = "lightblue", cex = 1.1) points(out1[sample(1:50000, 0.05 * 50000),], pch = "~", col = "lightblue1", cex = 1.2) points(out1[sample(1:45000, 0.05 * 45000),], pch = "~", col = "white", cex = 1.1) points(out2[sample(15000:nrow(out2), 0.08 * nrow(out2)),], pch = "-", col = "lightblue2", cex = 1.1) points(out2[sample(12000:nrow(out2), 0.02 * nrow(out2)),], pch = "~", col = rgb(250, 250, 71, max=255), cex = 1) points(out2[sample(1:40000, 0.1 * 40000),], pch = "~", col = "lightblue3", cex = 1.1) ######### # Cloud # ######### cl.x = rnorm(10000, mean = 0, sd = 2.5/9) cl.x = cl.x - 4.2 cl.y = rnorm(10000, mean = 0, sd = 0.7/9) cl.y = cl.y + 3.7 cloud = cbind(cl.x, cl.y) points(cloud, pch = ".", col = "gray85", cex = 1.1) cl.xs = rnorm(3000, mean = 0, sd = 1.6/9) cl.xs = cl.xs - 3.95 cl.ys = rnorm(3000, mean = 0, sd = 0.4/9) cl.ys = cl.ys + 3.65 clouds = cbind(cl.xs, cl.ys) points(clouds, pch = ".", col = "gray65", cex = 1) ## Bird1 points(-4.3, 4, pch = -as.hexmode(1003), col="grey40", cex=2.4) points(-4.3, 3.93, pch = 16, col="lightgoldenrod1", cex=2.6) ## Bird2 points(-4.5, 4.08, pch = -as.hexmode(1003), col="grey40", cex=2.1) points(-4.5, 4.01, pch = 16, col="lightgoldenrod1", cex=2.3) ## Bird3 points(-4.35, 4.16, pch = -as.hexmode(1003), col="grey40", cex=1.8) points(-4.35, 4.11, pch = 16, col="lightgoldenrod1", cex=1.5) # Signature text(x= -6.8, y = -0.05, label="by Yu-Cheng Ku", col = "grey60", cex = 1) #text(x=-6.55, y=0, label="Sep 21, 2016 ", col = "grey60", cex = 1)