#=======================================================# # Copyright (c) 2018. Yu-Cheng Ku. All Rights Reserved. # # The Xiang-Ji Studio # # Written by Yu-Cheng Ku # #=======================================================# win.graph(width = 13.2 * 0.54, height = 7) sky = rgb(40, 59, 138,, max = 255) ground = "lightgoldenrod4" par(mai = rep(0, 4), bg = sky) plot(c(0,0), type="n", xlim=c(-3, 2.4), ylim=c(0, 5)) ## The sky n_scale = 20 for(i in 1:n_scale) { range_u = 3.8 + i * (5.5-2)/n_scale lines(rbind(c(-9,range_u),c(5,range_u)), col = rgb(40, 59, 138-5*i, max = 255), lwd = 30) } ## 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] points(mstars, col = "grey95", cex=.2, pch=".") points(mstars2, col = "grey95", cex=.3, pch=-as.hexmode(9733)) ## The ground x.ground = c(-4,4,4,-4) y.ground = c(2,2,-1,-1) polygon(x.ground, y.ground, col = ground) x.ground2 = c(-4,4,4,-4) y.ground2 = c(2,2,1.6,1.6) polygon(x.ground2, y.ground2, col = "#86783F", border = "#86783F") x.ground3 = c(-4,4,4,-4) y.ground3 = c(2,2,1.82,1.82) polygon(x.ground3, y.ground3, col = "#817237", border = "#817237") # Dust here ndusts = 50 #Number of dusts to draw mdusts = matrix(runif(6 * ndusts), ncol=2) mdusts[,1] = 10 * mdusts[,1] - 6 mdusts[,2] = 2 * mdusts[,2] points(mdusts, col = "#62541D", cex = 1.2, pch="-", lwd = 2) ## Back wall ## x.bw = c(-4,4,4,-4) y.bw = c(2,2,2.85,2.85) polygon(x.bw, y.bw, col = "grey42") ############### ## the wall ## ############### x.f = c(-4, 2, 2, -4) y.f = c(3.2, 2.8, 1.2, 0.6) polygon(x.f, y.f, col = "ivory4") lines(rbind(c(1.8,2),c(0.4,1.95)), lwd = 2, col = "grey51") lines(rbind(c(1,1.6),c(-1.5,1.46)), lwd = 4, col = "grey52") ############ # The tree # ############ ## Jittered L-system Fractal Tree ## By Antonio Sanchez Chinchon ## https://aschinchon.wordpress.com/2014/03/13/the-lonely-acacia-is-rocked-by-the-wind-of-the-african-night/ depth = 5 b_angle = 29 #Between branches division L = 0.88 #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)) { X = rbind(X, branches[i,c(2,4)]) Y = rbind(Y, branches[i,c(3,5)]+0.8) } ######################################################## ## Tree shadow -- Stretch and shift the original tree ## ######################################################## h_stretch = 1.01 v_stretch = 1.03 h_shift = 0.925 v_shift = 0.4 Z1 = cbind(X[,1], Y[,1]) Z2 = cbind(X[,2], Y[,2]) Z11 = cbind(h_stretch * X[,1] - h_shift, v_stretch * Y[,1] - v_shift) Z22 = cbind(h_stretch * X[,2] - h_shift, v_stretch * Y[,2] - v_shift) Q1 = cbind(Z11[,1], Z22[,1]) Q2 = cbind(Z11[,2], Z22[,2]) ## Tree Branch Shadow ## for(i in 1:nrow(Q1)) { lines(Q1[i,], Q2[i,], lwd = 15, col = "grey40") } Lev1 = cbind(rnorm(nrow(Z1), 0, sd = 0.07), rnorm(nrow(Z2), 0, sd = 0.07)) Lev2 = cbind(rnorm(nrow(Z1), 0, sd = 0.07), rnorm(nrow(Z2), 0, sd = 0.07)) Lev3 = cbind(rnorm(nrow(Z1), 0, sd = 0.08), rnorm(nrow(Z2), 0, sd = 0.08)) Lev4 = cbind(rnorm(nrow(Z1), 0, sd = 0.09), rnorm(nrow(Z2), 0, sd = 0.09)) Lev5 = cbind(rnorm(nrow(Z1), 0, sd = 0.1), rnorm(nrow(Z2), 0, sd = 0.1)) FLR1 = cbind(rnorm(nrow(Z1), 0, sd = 0.08), rnorm(nrow(Z2), 0, sd = 0.08)) L1 = Z1 + Lev1 L2 = Z2 + Lev1 L3 = Z1 + Lev2 L4 = Z2 + Lev2 L5 = Z1 + Lev3 L6 = Z2 + Lev3 L7 = Z1 + Lev4 L8 = Z2 + Lev4 L9 = Z1 + Lev5 L10= Z2 + Lev5 F1 = Z1 + FLR1 F2 = Z2 + FLR1 L1_r = cbind(h_stretch * L1[,1] - h_shift, v_stretch * L1[,2] - v_shift) L2_r = cbind(h_stretch * L2[,1] - h_shift, v_stretch * L2[,2] - v_shift) L3_r = cbind(h_stretch * L3[,1] - h_shift, v_stretch * L3[,2] - v_shift) L4_r = cbind(h_stretch * L4[,1] - h_shift, v_stretch * L4[,2] - v_shift) L5_r = cbind(h_stretch * L5[,1] - h_shift, v_stretch * L5[,2] - v_shift) L6_r = cbind(h_stretch * L6[,1] - h_shift, v_stretch * L6[,2] - v_shift) L7_r = cbind(h_stretch * L7[,1] - h_shift, v_stretch * L7[,2] - v_shift) L8_r = cbind(h_stretch * L8[,1] - h_shift, v_stretch * L8[,2] - v_shift) L9_r = cbind(h_stretch * L9[,1] - h_shift, v_stretch * L9[,2] - v_shift) L10_r= cbind(h_stretch * L10[,1] - h_shift,v_stretch * L10[,2] - v_shift) F1_r = cbind(h_stretch * F1[,1] - h_shift, v_stretch * F1[,2] - v_shift) F2_r = cbind(h_stretch * F2[,1] - h_shift, v_stretch * F2[,2] - v_shift) L1_r = L1_r[-c(1:6),] L2_r = L2_r[-c(1:6),] L3_r = L3_r[-c(1:6),] L4_r = L4_r[-c(1:6),] L5_r = L5_r[-c(1:6),] L6_r = L6_r[-c(1:6),] L7_r = L7_r[-c(1:6),] L8_r = L8_r[-c(1:6),] L9_r = L9_r[-c(1:6),] L10_r = L10_r[-c(1:6),] F1_r = F1_r[-c(1:6),] F2_r = F2_r[-c(1:6),] ## Leave Shadow leave.shadow = "grey40" for(i in 1:nrow(Q1)) { points(L1_r, pch = "'", col = leave.shadow, cex = 5.5) points(L2_r, pch = "'", col = leave.shadow, cex = 5.5) points(L3_r, pch = "'", col = leave.shadow, cex = 5.5) points(L4_r, pch = "'", col = leave.shadow, cex = 5.5) points(L5_r, pch = "'", col = leave.shadow, cex = 5.5) points(L6_r, pch = "'", col = leave.shadow, cex = 5.5) points(L7_r, pch = "'", col = leave.shadow, cex = 5.5) points(L8_r, pch = "'", col = leave.shadow, cex = 5.5) points(L9_r, pch = "'", col = leave.shadow, cex = 5.5) points(L10_r,pch = "'", col = leave.shadow, cex = 5.5) points(F1_r, pch = "'", col = leave.shadow, cex = 5.5) points(F2_r, pch = "'", col = leave.shadow, cex = 5.5) } ## The eaves x.fu = c(-4, 2, 2.3, -4) y.fu = c(3.5, 3, 2.7, 2.9) polygon(x.fu, y.fu, col = "#874944") ## give the thickness x.fu2 = c(-4, 2.3, 2.3, -4) y.fu2 = c(2.9, 2.7, 2.67, 2.85) polygon(x.fu2, y.fu2, col = "#7A3530") ## Eaves shadows lines(rbind(c(-3.64, 3.45),c(-2.94, 2.91)), lwd = 7, col = "#7A3530") lines(rbind(c(-3.3, 3.45),c(-2.6, 2.9)), lwd = 7, col = "#7A3530") lines(rbind(c(-2.91, 3.38),c(-2.21, 2.84)), lwd = 7, col = "#7A3530") lines(rbind(c(-2.59, 3.35),c(-1.85, 2.8)), lwd = 7, col = "#7A3530") lines(rbind(c(-2.31, 3.32),c(-1.55, 2.8)), lwd = 7, col = "#7A3530") lines(rbind(c(-0.5, 3.2),c(-0.02, 2.8)), lwd = 5, col = "#7A3530") lines(rbind(c(-0.25, 3.2),c(0.22, 2.8)), lwd = 5, col = "#7A3530") lines(rbind(c(0.01, 3.15),c(0.45, 2.8)), lwd = 5, col = "#7A3530") lines(rbind(c(0.52, 3.1),c(0.89, 2.77)), lwd = 5, col = "#7A3530") lines(rbind(c(0.72, 3.07),c(1.08, 2.77)), lwd = 5, col = "#7A3530") lines(rbind(c(1.76, 2.98),c(2, 2.73)), lwd = 4, col = "#7A3530") lines(rbind(c(1.91, 2.98),c(2.15, 2.73)), lwd = 4, col = "#7A3530") ## Eaves shadow eaves.shadow = "#682621" for(i in 1:nrow(Q1)) { points(L1_r[which(L1_r[,2] > 2.83),], pch = "'", col = eaves.shadow, cex = 6 points(L2_r[which(L2_r[,2] > 2.83),], pch = "'", col = eaves.shadow, cex = 6) points(L3_r[which(L3_r[,2] > 2.83),], pch = ",", col = eaves.shadow, cex = 6) points(L4_r[which(L4_r[,2] > 2.83),], pch = "'", col = eaves.shadow, cex = 6) points(L5_r[which(L5_r[,2] > 2.83),], pch = "'", col = eaves.shadow, cex = 6) points(L6_r[which(L6_r[,2] > 2.83),], pch = "'", col = eaves.shadow, cex = 6) points(L7_r[which(L7_r[,2] > 2.83),], pch = "'", col = eaves.shadow, cex = 6) points(L8_r[which(L8_r[,2] > 2.83),], pch = "'", col = eaves.shadow, cex = 6) points(L9_r[which(L9_r[,2] > 2.83),], pch = "'", col = eaves.shadow, cex = 6) points(L10_r[which(L10_r[,2] > 2.83),], pch = "'", col = eaves.shadow, cex = 6) points(F1_r[which(F1_r[,2] > 2.83),], pch = "'", col = eaves.shadow, cex = 6) points(F2_r[which(F2_r[,2] > 2.83),], pch = "'", col = eaves.shadow, cex = 6) } # Lighter Eave shadow x.shade = c(-4, 2, 2, -4) y.shade = c(2.85, 2.67, 2.56, 2.68) polygon(x.shade, y.shade, col = "gray37", border = "gray37") # Darker Eave shadow x.shade = c(-4, 2, 2, -4) y.shade = c(2.85, 2.67, 2.62, 2.77) polygon(x.shade, y.shade, col = "gray25", border = "gray25") ## Fill the sky ## x.sky = c(-4, 2, 2, -4) y.sky = c(3.5, 3, 4, 4) polygon(x.sky, y.sky, col = rgb(40, 59, 138, max = 255), border = rgb(40, 59, 138,, max = 255)) ## Fill the ground ## x.grass = c(-4, 0, 0, -4) y.grass = c(0.6, 0.6 + (0-(-4)) * 0.1, 0.22, 0.22) polygon(x.grass, y.grass, col = ground, border = ground) lines(rbind(c(-4, 0.5), c(0, 0.5)), col = ground, lwd = 30) lines(rbind(c(2,1.2), c(-4,0.6))) ## Tree shadow ## lines(rbind(c(0,0.78),c(-0.92,0.91)), col = "#65530C", lwd = 11) points(-0.92,0.94, pch = ".", col = "grey40", cex = 12) ## Re-frame the thickness of the eave polygon(x.fu2, y.fu2, col = NA) ###################### ## Tree and flowers ## ###################### ## Tree Branches for (i in 1:nrow(branches)) { color = 4 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]))) } ## Tree Trunk Shadow lines(rbind(c(-0.025, 0.76), c(-0.025, 1.75)), col = "#684127", lwd = 5) ## Leaves ## points(L1[-c(1:6),], pch = "^", col = "forestgreen", cex = 4.5) points(L2[-c(1:6),], pch = "'", col = "darkgreen", cex = 4) points(L3[-c(1:6),], pch = "^", col = "olivedrab", cex = 3.5) points(L4[-c(1:6),], pch = "'", col = "green4", cex = 4) points(L5[-c(1:6),], pch = "^", col = "seagreen4", cex = 4.5) points(L6[-c(1:6),], pch = "'", col = "springgreen4", cex = 4) points(L7[-c(1:6),], pch = "'", col = "yellowgreen", cex = 4.5) points(L8[-c(1:6),], pch = "'", col = "chartreuse4", cex = 4) points(L9[-c(1:6),], pch = "'", col = "darkolivegreen", cex = 4.5) points(L10[-c(1:6),], pch = "'", col = "chartreuse4", cex = 4.5) ## Flowers ## points(F1[-c(1:6),], pch = "*", col = "mistyrose2", cex = 2) points(F2[-c(1:6),], pch = 16, col = "seashell2", cex = 1) points(F2[-c(1:6),], pch = 8, col = "seashell2", cex = 1) ## Stone shadow and flower shadow lines(rbind(c(0.96,0.67),c(0.5,0.73)), col = "#796618", lwd = 17) lines(rbind(c(0.96,0.67),c(0.6,0.71)), col = "#65530C", lwd = 9) lines(rbind(c(1.15,0.58),c(0.65,0.61)), col = "#796618", lwd = 4) ## petals npetals = 20 #Number of petal to draw mpetals = matrix(runif(2*npetals), ncol=2) mpetals[,1] = 2.5 * mpetals[,1] - 2.2 mpetals[,2] = 0.5 * mpetals[,2] + 0.3 points(mpetals, col = "lightgoldenrodyellow", cex = 1.2, pch="'", lwd = 2) mpetals = matrix(runif(2*npetals), ncol=2) mpetals[,1] = 2.8 * mpetals[,1] - 1.8 mpetals[,2] = 0.5 * mpetals[,2] + 0.3 points(mpetals, col = "lightgoldenrodyellow", cex = 1.1, pch="-", lwd = 2) points(-0.92,0.9, col = "lightgoldenrodyellow", cex = 1.1, pch="-", lwd = 2) points(-0.85,0.94, col = "lightgoldenrodyellow", cex = 1.1, pch="-", lwd = 2) ## The stone x.stone = c(0.72, 0.98, 1.17, 1.14, 1.02, 0.99, 0.92, 0.8) y.stone = c(0.7, 0.62, 0.68, 0.88, 0.96, 0.96, 0.88, 0.85) polygon(x.stone, y.stone, col = "grey60") x.stone1 = c(0.72, 0.98, 0.98, 0.8) y.stone1 = c(0.7, 0.62, 0.79, 0.85) polygon(x.stone1, y.stone1, col = "grey43", border = "grey43") x.stone2 = c(0.98, 0.8, 0.92, 0.97) y.stone2 = c(0.79, 0.85, 0.88, 0.85) polygon(x.stone2, y.stone2, col = "grey48", border = "grey48") x.stone3 = c(0.92, 0.96, 1.14, 1.02, 0.99) y.stone3 = c(0.88, 0.84, 0.88, 0.96, 0.96) polygon(x.stone3, y.stone3, col = "grey55", border = "grey55") polygon(x.stone, y.stone, col = NA) ## small flower xC = seq(1.135, 1.15, l=30) yC = function(t){-(12)*(t+0.03)^2 + 17.3} lines(xC, yC(xC), lwd=2, col = "darkgreen") xL = seq(1.06, 1.15, l=30) yL = function(t){-(0.85)*(t+0.05)^2 + 1.8} lines(xL, yL(xL), lwd=2, col = "darkgreen") xR = seq(1.16, 1.31, l=30) yR = function(t){-(30)*(t-1.27)^2 + 0.93} lines(xR, yR(xR), lwd=2, col = "darkgreen") xR2 = seq(1.16, 1.31, l=30) yR2 = function(t){-(5)*(t-1.4)^2 + 0.88} lines(xR2, yR2(xR2), lwd=2, col = "darkgreen") points(1.135, yC(1.135), pch = "*", col = "goldenrod1", cex = 2) ## Signature text(2, 0.15, "by Yu-Cheng Ku", col = "tomato4") #text(2, 0.06, "Apr. 28, 2018", col = "tomato4")