Motivated by my last experiments I decided to look a bit more into generating images with R. One of my favorite musicians Max Cooper released another absolutely gorgeous music video (https://www.youtube.com/watch?v=O7bKq03bAsg). Check it out, the animation is fantastic. I was intrigued by the simple basic structure. It was just a rectangle divided by rectangles divided by rectangles. Something I can absolutely do with my R skills. So, I tried. The pictures are a result of that.
My tactic was to create a data frame just starting with the first rectangle, defined by start and end coordinates then just splitting them. I filled them randomly with colors. Honestly quite simple. Doing this and other experiments, I got a lot better making code run faster in R. Of course there is still a lot of space to improve. The code in my last post for example was super inefficient and I made a lot of basic mistakes (I improved it and now it runs a lot faster).
Here is the code if anyone is interested:
#data is one line of the total dataset, i is the number of the loop.
#because I don't want super long rectangles, I always first check which is the longe side.
#create the divider which is a value which defines the proportions of the two new rectangles
#ifelse is necessary to change if it is a vertical split or not.
#here the new x.a1 and new y.a1 is created. (naming was a bit stupid I admit)
data[2,1]=ifelse(yaxsplit==T, data[1,1] , data[1,1]+(data[1,3]-data[1,1])*divider)
data[2,2]=ifelse(yaxsplit==T, data[1,2]+(data[1,4]-data[1,2])*divider, data[1,2])
#Points stay stay the same no mater the orientation.
#x.z1 and y.z1 are created
#are the same like in the first created recangle (x.a and y.a)
#y.z2 and y.z2
data[3,3]=ifelse(yaxsplit==T, data[1,3] , data[1,1] )
data[3,4]=ifelse(yaxsplit==T, data[1,2] , data[1,4])
#add level (for potential animations)
#add a color. one of the rectangles keeps the color of the bigger rectangle, not necessary
#this changes which one of the rectangles is saved first. this should change it up and make sure there aren't more splits on one side.
# a list of color palettes
#how many splits should be done?
#create empty dataframe
#fill first row
#precreate random vector used for proportions and colors.
random=sample(1:4,loops,replace = T)
#filling up dateframe with simple loop and splitter functions
#this skips every few rows, so there stay a few bigger rectangles.
#this is just for me to choose one palettes in the list
alpha=9,show.legend = F,fill=pallist[[farbe]][df$color],col=pallist[[farbe]])+