clear %n is the number of different transformations you want to use. %It has to match the number of entries %in the data vectors c,u,v, and th. n=4 c=[.92 .92 .92 .92]; u=[.7 .8 -.6 -.5]; v=[.5 -.5 .5 -.4] th=[pi/9 pi/11 pi/12 pi/13]; for p=1:n D=[c(p) 0 0; 0 c(p) 0; 0 0 1]; R=[cos(th(p)) -sin(th(p)) 0; sin(th(p)) cos(th(p)) 0; 0 0 1]; T=[1 0 u(p); 0 1 v(p); 0 0 1]; A=D*T*R; box=[0 1 1 0 0; 0 0 1 1 0; 1 1 1 1 1]; for i=1:50 for j=1:4 line([box(1,j) box(1,j+1)],[box(2,j) box(2,j+1)],'color','blue') end box=A*box; end end axis equal