%%%%%%%%%%%%%%%%%%%%% Interactive Tesselation with Mouse %%%%%%%%%%%%%%%%%%% % % QMTESS % Usage: QMTESS(s,t,u,v,h,e,Qu0) % % Inputs: s,t,u,v - real numbers with 1/s + 1/t + 1/u + 1/v < 2 % see QSCHWARTZ for the interpretation of s,t,u,v % h - sidelength % e - optional erasure parameter, see below % Qu0 - initial quadrilateral % % Output: word - the sequence of reflections created by the interactive % tesellation % Qu - final quadrilateral % 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,Qu] = qmtess(s,t,u,v,h,e,Qu0); % initializations I = sqrt(-1); word = []; if (nargin < 6) e ='BF'; end; erase = [sum(e == 'B') sum(e == 'F')]; if (nargin >= 7) Qu = Qu0; else Qu = qschwartz1(s,t,u,v,h); end; % plotting colours vc1 = 'r'; vc2 = 'y'; vc3 = 'g'; vc4 = 'b'; cc = 'w'; ec = 'k'; quadcol = 'w'; % graphics and menu setup quadtype = [inttostr(s) '-' inttostr(t) '-' inttostr(u)' '-' inttostr(v)]; Q = abs('Q'); Qerase = 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([ quadtype ' 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, 'Q: Quit'); plotpoly(Qu,quadcol); plotvertq(Qu,vc1,vc2,vc3,vc4); plotcent(Qu, 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(Qu,ec); S = Qu(1); T = Qu(2); U = Qu(3); V = Qu(4); wa = sameside([S T U],z); wb = sameside([T U V],z); wc = sameside([U V S],z); wd = sameside([V S T],z); k = 0; if (wa < k) side = 'a'; k = wa; end; if (wb < k) side = 'b'; k = wb; end; if (wc < k) side = 'c'; k = wc; end; if (wd < k) side = 'd'; k = wd; end; if k < 0 Qu2 = polyrefl(Qu,side); if (btn == right) side = upcase(side); end; if (btn == left) plotpoly(Qu2,quadcol); plotvertq(Qu2,vc1,vc2,vc3,vc4); end; Qu = Qu2; word = [word side]; end; plotcent(Qu,cc); end; if (btn == Qerase) % plotpoly(Qu,ec); end; end; if erase(2) clf; end;