% m9_colorquiz.m - an RGB colour quiz, just for fun clf rgb = (randi(3,[1,3])-1)/2; % pick 3 random nos. 0, 1/2, or 1 x = [0 1 1 0 0]; y = [0 0 1 1 0]; subplot(3,5,1:5) fill(x,y,rgb) % draw a colour patch to be matched axis off for i = 6:15 % the player gets 10 tries disp(' ') disp('how much red?') % input the guess r/g/b values r = input(' (0, .5 or 1) '); g = input('how much green? '); b = input('how much blue? '); subplot(3,5,i) fill(x,y,[r g b]) % draw the guess as a smaller patch axis off if rgb == [r g b] % if correct, celebrate and stop subplot(3,5,1:5), hold on text(.22,.5,'You win !!','color',[1 .9 .9],'fontsize',44) break end end