There is geometry in the humming of the strings, there is music in the spacing of the spheres (Pythagoras)

Spring is here and I will be on holiday next week. I cannot be more happy! It is time to celebrate so I have drawn another fractal. It is called the *Pythagorean Tree*:

Here you have the code. See you soon:

library("grid")
l=0.15 #Length of the square
grid.newpage()
gr <- rectGrob(width=l, height=l, name="gr") #Basic Square
pts <- data.frame(level=1, x=0.5, y=0.1, alfa=0) #Centers of the squares
for (i in 2:10) #10=Deep of the fractal. Feel free to change it
{
df<-pts[pts$level==i-1,]
for (j in 1:nrow(df))
{
pts <- rbind(pts,
c(i,
df[j,]$x-2*l*((1/sqrt(2))^(i-1))*sin(df[j,]$alfa+pi/4)-0.5*l*((1/sqrt(2))^(i-2))*sin(df[j,]$alfa+pi/4-3*pi/4),
df[j,]$y+2*l*((1/sqrt(2))^(i-1))*cos(df[j,]$alfa+pi/4)+0.5*l*((1/sqrt(2))^(i-2))*cos(df[j,]$alfa+pi/4-3*pi/4),
df[j,]$alfa+pi/4))
pts <- rbind(pts,
c(i,
df[j,]$x-2*l*((1/sqrt(2))^(i-1))*sin(df[j,]$alfa-pi/4)-0.5*l*((1/sqrt(2))^(i-2))*sin(df[j,]$alfa-pi/4+3*pi/4),
df[j,]$y+2*l*((1/sqrt(2))^(i-1))*cos(df[j,]$alfa-pi/4)+0.5*l*((1/sqrt(2))^(i-2))*cos(df[j,]$alfa-pi/4+3*pi/4),
df[j,]$alfa-pi/4))
}
}
for (i in 1:nrow(pts))
{
grid.draw(editGrob(gr, vp=viewport(x=pts[i,]$x, y=pts[i,]$y, w=((1/sqrt(2))^(pts[i,]$level-1)), h=((1/sqrt(2))^(pts[i,]$level-1)), angle=pts[i,]$alfa*180/pi),
gp=gpar(col=0, lty="solid", fill=rgb(139*(nrow(pts)-i)/(nrow(pts)-1),
(186*i+69*nrow(pts)-255)/(nrow(pts)-1),
19*(nrow(pts)-i)/(nrow(pts)-1),
alpha= (-110*i+200*nrow(pts)-90)/(nrow(pts)-1), max=255))))
}

### Like this:

Like Loading...

*Related*

Hi – nice code. I wrote a version of this Pythag tree which allows the user to specify the triangle’s base angle (i.e. something other than the pi/4 of the standard tree). This produces some interesting variations.

Thanks! Did you write it also in R? I have seen that versions of the tree and are very nice. I did something similar with another fractal in this previous post: https://aschinchon.wordpress.com/2014/03/13/the-lonely-acacia-is-rocked-by-the-wind-of-the-african-night/

Here, apart of non-symmetric angles to split, I also include here some ramdom noise to every branch.

Yep, it’s in R, but at the moment is on a machine far away š that I can’t access remotely. LMK if you’d like me to send the code over.

Yes, sure! thanks

Nice! I appreciate your effort.

In which language can I implement this?

in R

Reblogged this on deseRt scrolls and commented:

Wonderful blog to follow