function W = Graphics(V,C,Ex,k)

figure; hold on;

CreateTransformations; 

% Example in text
if Ex == 1
	k = 4;
	Ax = [-k,k,-k,k];
 	V = [1 2 1 0; 0 1 2 1]
 	C = [1 1 0 1; 1 1 1 1; 0 1 1 1; 1 1 1 1]
	% 	V = TranslateByVector(V,[1,0]);
	%	C = CyclicAdjancyMatrix(V);
	PlotWireFrame(V,C,Ax,'.r');
	W = V;

 % Exercise 5
 elseif Ex == 2
	k = 5;
	Ax = [-k,k,-k,k];

	V = [-1 1 -1 1; 1 -1 -1 1]
	C = [1 1 0 1; 1 1 1 0; 0 1 1 1; 1 0 1 1]
	% 	V = TranslateByVector(V,[1,0]);
	%	C = CyclicAdjancyMatrix(V);
	PlotWireFrame(V,C,Ax,'.r');
	W = V;

elseif Ex == 3 
	Ax = [0, 20, -5, 15];

% J
	V = [2 5 5 6 6 3 3 4 4 3 3 2 2; 
		 0 0 4 4 5 5 4 4 1 1 2 2 0];
	% Deform V
	 V = V + -.1 + .2*rand(size(V));
	V = TranslateByVector(V,[1,0]);
	C = CyclicAdjancyMatrix(V);
	J = PlotWireFrame(V,C,Ax,'.r');

% O
	V = [0 3 3 0 0;
		 0 0 5 5 0];
	% Deform V
	 V = V + -.1 + .2*rand(size(V));
	
	V = TranslateByVector(V,[8,0]);
	C = CyclicAdjancyMatrix(V);
	O1 = PlotWireFrame(V,C,Ax,'.k');
	
% small O
	V = [1 2 2 1 1;
		 1 1 4 4 1];
	% Deform V
	 V = V + -.1 + .2*rand(size(V));
	V = TranslateByVector(V,[8,0]);
	C = CyclicAdjancyMatrix(V);
	O2 = PlotWireFrame(V,C,Ax,'.k');

% S
	V = [0 3 3 1 1 3 3 0 0 2 2 0 0;
	     0 0 3 3 4 4 5 5 2 2 1 1 0];
	% Deform V
	 V = V + -.1 + .2*rand(size(V));
	V = TranslateByVector(V,[12,0]);
	C = CyclicAdjancyMatrix(V);
	S = PlotWireFrame(V,C,Ax,'.b');
% H
	V = [0 1 1 2 2 3 3 2 2 1 1 0 0;
	     0 0 2 2 0 0 5 5 3 3 5 5 0];
	% Deform V
	% V = V + -.1 + .2*rand(size(V));
	V = TranslateByVector(V,[16,0]);
	C = CyclicAdjancyMatrix(V);
	H = PlotWireFrame(V,C,Ax,'.g');


	W = [J O1 O2 S H];
	else

	Ax = [-k,k,-k,k];
	H = PlotWireFrame(V,C,Ax,'.g');

	end % E
end

function X = PlotWireFrame(V,C,Ax,TheColor);

	if size(C,2) ~= size(V,2);
		disp('Dimension mismatch of C and V')
		return
	end
	
	axis(Ax)

	X = [];
	for i = 1:size(C,2) 
	
		% all vertices adjacent to i
		jx = find(C(i,:)); 
		ix = [];
		for j = 1:length(jx)
			ix = [ix i jx(j)];
		end
		A{i} = V(:,ix);
		WireFrame(A{i},TheColor,Ax);
		X = [X A{i}];
	
	
	end
end % plotwireframe

function C = CyclicAdjancyMatrix(V)
	C = zeros(size(V,2));
	for i = 1:size(V,2); 
			C(i,i) = 1;
			if i < size(V,2)
				C(i,i+1) = 1;
				C(i+1,i) = 1;
			end
			if i == size(V,2)
					C(1,i) = 1;
					C(i,1) = 1;
			end
	end
end % cyclic	
