• Remix
  • Share
  • New Entry

  • ME

  • /
  • Pythagorean treehouse - noir remix

on 15 Nov 2023
  • 23
  • 24
  • 0
  • 0
  • 996
drawframe(1);
function drawframe(f)
% Remix of Ned Gulley's pythagorean treehouse to alter colorscheme and add
% additional branches
theta = interp1([0 48],[0 pi/2],f);
clf
hgt = hgtransform(Parent=gca);
c = 0.9;
maxdepth = 8;
pythag_seg(hgt,c,theta,maxdepth);
x = c*[0 0 1 1];
y = c*[0 1 1 0];
cmap = gray(maxdepth+1);
p = patch(x,y,cmap(1,:));
axis equal
axis([-4 5 0 7.5])
axis off
set(gcf,Color='k')
end
function pythag_seg(hgtp,c,theta,maxdepth,depth)
if nargin < 5
depth = 1;
end
depth = depth + 1;
if depth > maxdepth
return
end
hgtc1 = hgtransform(Parent=hgtp);
hgtc2 = hgtransform(Parent=hgtp);
x = c*[0 0 1 1];
y = c*[0 1 1 0];
cmap = gray(maxdepth+1);
color = cmap(depth+1,:);
patch(x,y,color,EdgeColor='black',Parent=hgtc1);
patch(x,y,color,EdgeColor='black',Parent=hgtc2);
a = c*cos(theta);
b = c*sin(theta);
Txy = makehgtform('translate',0,c,0);
Rz = makehgtform('zrotate',theta);
S = makehgtform('scale',a/c);
set(hgtc1,Matrix=Txy*Rz*S);
Txy = makehgtform('translate',a*cos(theta),c+a*sin(theta),0);
Rz = makehgtform('zrotate',theta-pi/2);
S = makehgtform('scale',b/c);
set(hgtc2,Matrix=Txy*Rz*S);
pythag_seg(hgtc1,c,theta,maxdepth,depth)
pythag_seg(hgtc2,c,theta,maxdepth,depth)
end
Animation
Remix Tree