RandomMondrian

RandomMondrian - else Generate a random point in the...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
% Eric Young % CS 100M Project function RandomMondrian(a,b,L,W,Level) % function draws, recursively, a pattern of rectangles of variable colors % and sizes based on a number of different parameters: pHalt, bWidth, % MyColors, and Lmax. Lmax = 4; % subdivision process called off when Lmax reached % Let probability of getting heads = pHalt pHalt = .08; % probability of getting 'heads' MyColors = [1.0 0.0 0.0;0.0 1.0 0.0;0.0 0.0 1.0;1.0 1.0 0.0;1.0 0.0. .. 1.0;0.0 1.0 1.0;0.04 0.3 0.6;0.8 0.3 0.2]; % Color options array bWidth = 2; % line width parameter [rows cols] = size(MyColors); r = rand; if (Level >= Lmax)|| (r <= pHalt) % If you get heads or you're at Lmax % Recursion limit reached! Display rectangle fill([a a+L a+L a a],[b b b+W b+W b],MyColors((ceil(rows*rand)),1:3)) plot([a a+L a+L a a],[b b b+W b+W b],'LineWidth',bWidth,'Color',[0.0 0.0 0.0])
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: else % Generate a random point in the rectangle--a basis for the subdivision of % the rectangle into four smaller rectangles c = a + rand*(L); % c and d are random x and y coordinates of pt d = b + rand*(W); maxWidth = b + (7/8)*(W); minWidth = b + (3/8)*(W); maxLength = a + (3/4)*(L); minLength = a + (1/4)*(L); while ((d > maxWidth)||(d < minWidth))||((c > maxLength)||(c < minLength)) % Generate a new coordinate since last coordinate was 'bad' In other % words, last coordinate was not within specified bounds. . c = a + rand*(L); d = b + rand*(W); end % RECURSION - call the fcn again four times, one for each of the four new % rectangles. . RandomMondrian(a,d,c-a,b+W-d,Level+1) RandomMondrian(c,d,a+L-c,b+W-d,Level+1) RandomMondrian(a,b,c-a,d-b,Level+1) RandomMondrian(c,b,a+L-c,d-b,Level+1) end...
View Full Document

This note was uploaded on 09/12/2009 for the course CS 100 taught by Professor Fan/vanloan during the Fall '07 term at Cornell.

Page1 / 3

RandomMondrian - else Generate a random point in the...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online