DrawTriangle

# DrawTriangle - b =(y(1 y(2/2(y(2 y(3/2(y(3 y(1/2 Color the...

This preview shows page 1. Sign up to view the full content.

function DrawTriangle(x,y,level) % x and y are length 3-arrays that define the vertices of a triangle. % Draws recursively colored triangles; % level is an integer that specifies the level of the recursion % if level ==5 % Recursion limit reached. Display triangle as yellow. fill(x,y,'y') else % Draw the triangle. .. plot([x x(1)],[y y(1)],'k') % Determine the midpoints. .. a = [(x(1)+x(2))/2 (x(2)+x(3))/2 (x(3)+x(1))/2];
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: b = [(y(1)+y(2))/2 (y(2)+y(3))/2 (y(3)+y(1))/2]; % Color the interior triangle. .. pause fill(a,b,'m') pause % Apply the process to the three "corner" triangles. .. DrawTriangle([x(1) a(1) a(3)],[y(1) b(1) b(3)],level+1) pause DrawTriangle([x(2) a(2) a(1)],[y(2) b(2) b(1)],level+1) pause DrawTriangle([x(3) a(3) a(2)],[y(3) b(3) b(2)],level+1) pause end...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online