%%%%%%%%%%%%%%%%%%%%% Intractive Tesselation with Mouse %%%%%%%%%%%%%%%%%%% % % MTESS % Usage: MTESS(p,q,r,e,T0,) % % Inputs: p,q,r - real numbers with 1/p +1/q +1/r < 1 % see SCHWARTZ for the interpretation of p,q,r % e - optional erasure parameter, see below % T0 - initial triangle % % Output: word - the sequence of reflections created by the interactive % tesellation % T - final triangle % e is a string composed of the following options % 'B' erase at beginning start with new boundary circle % 'b' do not erase at beginning % 'F' clear graphics at end % 'f' do not clear graphics at end % default is 'BF' function [word,T] = mtess(p,q,r,e,T0); % initializations I = sqrt(-1); word = []; if (nargin < 4) e ='BF'; end; erase = [sum(e == 'B') sum(e == 'F')]; if (nargin >= 5) T = T0; else T = schwartz(p,q,r); end; % plotting colours vc1 = 'r'; vc2 = 'y'; vc3 = 'g'; cc = 'w'; ec = 'k'; tricol = 'w'; % graphics and menu setup tritype = [inttostr(p) '-' inttostr(q) '-' inttostr(r)]; Q = 27; Terase = abs('E'); left = 1; right = 3; mbx = -1.5; mby = .8; lx = mbx; ly = mby-.15; rx = mbx; ry = ly -.25; kx = mbx; ky = ry -.3; ex = mbx; ey = ky-.15; qx = mbx; qy = ey-.15; % screen drawing if erase(1) boundary([ tritype ' Tiling'],'','w'); end; text(mbx,mby, 'Mouse Buttons'); text(lx,ly, 'Left:'); text(lx,ly-.1, ' reflect & draw'); text(rx,ry, 'Right:'); text(rx,ry-.1, ' reflect only'); text(kx,ky-.1, 'Keys'); text(ex,ey-.1, 'E: Erase'); text(qx,qy-.1, 'Esc: Quit'); plottri(T,tricol); plotvert(T,vc1,vc2,vc3); plotcent(T, cc); % main loop btn = 0; while (btn ~= Q) [x,y,btn] = ginputsab(1); btn = rem(rem(btn,256)+256,256); btn = abs(upcase(setstr(btn))); z = x+y*I; if (abs(z) < 1.5)&(sum(btn == [left right])) % check if mouse button pressed plotcent(T,ec); A = T(1); B = T(2); C = T(3); wa = sameside([B C A],z); wb = sameside([C A B],z); wc = sameside([A B C],z); h = 0; if (wa < h) side = 'a'; h = wa; end; if (wb < h) side = 'b'; h = wb; end; if (wc < h) side = 'c'; h = wc; end; if h < 0 T2 = trirefl(T,side); if (btn == right) side = upcase(side); end; if (btn == left) plottri(T2,tricol); plotvert(T2,vc1,vc2,vc3); end; T = T2; word = [word side]; end; plotcent(T,cc); end; if (btn == Terase) plottri(T,ec); end; end; if erase(2) clf; end;