%RGBEXAMP last updated 8/31/98 % A demonstration of colors as a linear combination of % RED, GREEN, and BLUE using their intensities as % coefficients. Sliders control the selection of the % intensitiy of each color. After moving the sliders to % the desired intensity click the APPLY button to see % the color formed and a display of the linear combination. % % Requires MATLAB 5.0 or higher. % % By: David R. Hill, Math Dept, Temple University, % Philadelphia, Pa. 19122 Email: dhill001@temple.edu %initial values for sliders rcoeff=.5; gcoeff=.5; bcoeff=.5; %STRINGS cont='Press ENTER to continue.'; lc0='COLOR'; lc1=['= ' num2str(rcoeff) ' [1 0 0]']; lc2=['+ ' num2str(gcoeff) ' [0 1 0]']; lc3=['+ ' num2str(bcoeff) ' [0 0 1]']; directs='Use your mouse to position the sliders, then click APPLY.'; %callback for the help button helps='set(gcf,''visible'',''off'');clc,help rgbexamp,disp(cont),'; helps=[helps 'pause,set(gcf,''visible'',''on'');']; %callback for the apply button doapply=['axes(axfig);x=[0 1 1 0 0];y=[0 0 1 1 0];']; doapply=[doapply 'patch(x,y,[rcoeff gcoeff bcoeff]);']; doapply=[doapply 'delete(lnlc1),delete(lnlc2),delete(lnlc3),']; doapply =[doapply 'lc1=[''= '' num2str(rcoeff) '' [1 0 0]''];']; doapply =[doapply 'lc2=[''+ '' num2str(gcoeff) '' [0 1 0]''];']; doapply =[doapply 'lc3=[''+ '' num2str(bcoeff) '' [0 0 1]''];']; doapply=[doapply 'subplot(axcomb);']; doapply=[doapply 'lnlc0=text(-.1,.9,lc0,''color'',[rcoeff gcoeff bcoeff],''fontsize'',16,']; doapply=[doapply ' ''fontweight'',''bold'');']; doapply=[doapply 'lnlc1=text(.25,.9,lc1,''color'',''red'',''fontsize'',16,']; doapply=[doapply ' ''fontweight'',''bold'');']; doapply=[doapply 'lnlc2=text(.25,.65,lc2,''color'',''green'',''fontsize'',16,']; doapply=[doapply ' ''fontweight'',''bold'');']; doapply=[doapply 'lnlc3=text(.25,.40,lc3,''color'',''blue'',''fontsize'',16,']; doapply=[doapply ' ''fontweight'',''bold'');']; %callback for the done button done='close(gcf),return'; % %COLOR settings bkgr='white'; %background color darkgray = [.8 .8 .8];%Really a light gray % %Setting figure to full screen hfig=figure('units','normal','position',[0 0 1 1],'color',bkgr); %axis for showing header axtitle= subplot('position',[.3 .85 .3 .1]); axis([0 1 0 1]);axis(axis);hold on axis('off'); head=text(0,0,'RGB COLOR Example','color','magenta',... 'erasemode','none','fontweight','bold','fontsize',22,'erasemode','none'); %axis for showing vanity axvan= subplot('position',[.85 .05 .09 .05]); axis([0 1 0 1]);axis(axis);hold on axis('off'); text(0,0,'by D.R.Hill','color','black','fontsize',12,... 'fontweight','bold','fontangle','oblique','erasemode','none') %INTENSITY SLIDERS axslider= subplot('position',[0 .59 .6 .2]); axis([0 1 0 1]);axis(axis);hold on axis('off'); %RED rlabel = uicontrol('style','text','units','normal','pos',[.01 .7 .15 .04], ... 'string',['RED Intensity '],... 'fontsize',12,'fontweight','bold',... 'fore','red','back','white'); rslider = uicontrol('style','slider','units','normal','pos',[.2 .7 .25 .035], ... 'min',0,'max',1,'val',rcoeff, ... 'call',['rcoeff = get(rslider,''value'');',... 'set(rvalue,''string'', num2str(get(rslider,''value'')))']); rvalue=uicontrol('style','text','units','normal','pos',[.5 .7 .08 .04], ... 'string',num2str(get(rslider,'value')),... 'fontsize',12,'fontweight','bold',... 'fore','red','back','white'); %GREEN glabel = uicontrol('style','text','units','normal','pos',[.01 .65 .18 .04], ... 'string',['GREEN Intensity '],... 'fontsize',12,'fontweight','bold',... 'fore','green','back','white'); gslider = uicontrol('style','slider','units','normal','pos',[.2 .65 .25 .035], ... 'min',0,'max',1,'val',gcoeff, ... 'call',['gcoeff = get(gslider,''value'');',... 'set(gvalue,''string'', num2str(get(gslider,''value'')))']); gvalue=uicontrol('style','text','units','normal','pos',[.5 .65 .08 .04], ... 'string',num2str(get(gslider,'value')),... 'fontsize',12,'fontweight','bold',... 'fore','green','back','white'); %blue blabel = uicontrol('style','text','units','normal','pos',[.01 .6 .18 .04], ... 'string',['BLUE Intensity '],... 'fontsize',12,'fontweight','bold',... 'fore','blue','back','white'); bslider = uicontrol('style','slider','units','normal','pos',[.2 .6 .25 .035], ... 'min',0,'max',1,'val',bcoeff, ... 'call',['bcoeff = get(bslider,''value'');',... 'set(bvalue,''string'', num2str(get(bslider,''value'')))']); bvalue=uicontrol('style','text','units','normal','pos',[.5 .6 .08 .04], ... 'string',num2str(get(bslider,'value')),... 'fontsize',12,'fontweight','bold',... 'fore','blue','back','white'); %Value label + max & min values vlabel = uicontrol('style','text','units','normal','pos',[.49 .74 .1 .04], ... 'string',['VALUE'],... 'fontsize',12,'fontweight','bold',... 'fore','black','back','white'); minlabel = uicontrol('style','text','units','normal','pos',[.2 .74 .02 .04], ... 'string',['0'],... 'fontsize',12,'fontweight','bold',... 'fore','black','back','white'); maxlabel = uicontrol('style','text','units','normal','pos',[.43 .74 .02 .04], ... 'string',['1'],... 'fontsize',12,'fontweight','bold',... 'fore','black','back','white'); %direction line dirline=uicontrol('style','text','units','normal','pos',[0 .55 .65 .04], ... 'string',directs,... 'fontsize',12,'fontweight','bold',... 'fore','black','back','white'); %FRAME for INTENSITY sliders %sldfrm=uicontrol('style','frame','units','normal',... % 'position',[0 .59 .6 .2],'backgroundcolor','w'); %PUSH Buttons applyit = uicontrol('style','push','units','normal','pos',[.8 .7 .1 .05], ... 'fontsize',14,'fontweight','bold',... 'string','APPLY','call',doapply); helph = uicontrol('style','push','units','normal','pos',[.8 .63 .1 .05], ... 'fontsize',14,'fontweight','bold',... 'string','Help','call',helps); quitit = uicontrol('style','push','units','normal','pos',[.8 .56 .1 .05], ... 'fontsize',14,'fontweight','bold',... 'string','Quit','call',done); %axis for showing application of intensities axfig= subplot('position',[.05 .05 .4 .4]); axis(axis);hold on,axis('off');axis('square'); x=[0 1 1 0 0];y=[0 0 1 1 0]; patch(x,y,[rcoeff gcoeff bcoeff]) %axis for showing linear combination axcomb=subplot('position',[.5 .2 .4 .2]); axis(axis);hold on;axis('off'); title('As a linear combination:','fontsize',14,... 'fontweight','bold') lnlc0=text(-.1,.9,lc0,'color',[rcoeff gcoeff bcoeff],'fontsize',16,... 'fontweight','bold'); lnlc1=text(.25,.9,lc1,'color','red','fontsize',16,... 'fontweight','bold'); lnlc2=text(.25,.65,lc2,'color','green','fontsize',16,... 'fontweight','bold'); lnlc3=text(.25,.40,lc3,'color','blue','fontsize',16,... 'fontweight','bold');