%Creates a Minkowski graph %set the position and size of the control and plot figures set(0,'Units','pixels') ss=get(0,'screensize'); pos1 = [(ss(3)-ss(1))*.02,... (ss(4)-ss(2))*.3,... (ss(3)-ss(1))*.45,... (ss(4)-ss(2))*.45]; pos2 = [(ss(3)-ss(1))*.5,... (ss(4)-ss(2))*.3,... (ss(3)-ss(1))*.45,... (ss(4)-ss(2))*.45]; this=figure('Position',pos1); thePlot=figure('Position',pos2); set(this,'DoubleBuffer','on'); %set initial values c=3*10^8; lightLineToggle=1;%light line is on velocity=.6; range=10; skip=2; %draw the grid with the initial values and then switch back to the control figure drawGridCallback(thePlot,velocity,range,skip,lightLineToggle,c); figure(this); %toggle the light line on and off lightLineToggleCallback=['lightLineToggle=~lightLineToggle;,'... 'drawGridCallback(thePlot,velocity,range,skip,lightLineToggle,c);']; uicontrol('Style','togglebutton','Position',[20 20 100 20],'String','Toggle Light Line','Callback',lightLineToggleCallback); %the velocity slider is between .01 and 1 (velocity/c) velocitySliderCallback=['velocity=get(velocitySlider,''Value'');,'... 'set(velocityEdit,''String'', velocity);,'... 'drawGridCallback(thePlot,velocity,range,skip,lightLineToggle,c);']; velocitySlider=uicontrol('Style','slider','Position',[20 100 20 150],'Min',.01,'SliderStep',[0.01 1],'Callback',velocitySliderCallback); %the velocity edit box will only allow values between .01 and 1 (velocity/c) velocityEditCallback=['velocity=str2num(get(velocityEdit,''String''));,'... 'if(length(velocity)==0) velocity=.6; end;,'... 'if(velocity<.01) velocity=.01; elseif(velocity>1) velocity=1; end;,'... 'set(velocitySlider,''Value'',velocity);,'... 'set(velocityEdit,''String'', velocity);,'... 'drawGridCallback(thePlot,velocity,range,skip,lightLineToggle,c);']; velocityEdit=uicontrol('Style','edit','Position',[20 260 80 20],'Callback',velocityEditCallback); uicontrol('Style','text','Position',[20 290 80 20],'String','Velocity/c'); %the range slider only allows integer ranges greater than 1 %skip is forced to be at least 5% of the range (or we get too many lines) rangeSliderCallback=['range=floor(get(rangeSlider,''Value''));,'... 'set(rangeEdit,''String'', range);,'... 'if(range*.05>skip) skip=floor(.05*range); end;,'... 'set(unitSkip,''String'',skip);,'... 'drawGridCallback(thePlot,velocity,range,skip,lightLineToggle,c);']; rangeSlider=uicontrol('Style','slider','Position',[120 100 20 150],'Min',1,'Max',100,'SliderStep',[.01 1],'Callback',rangeSliderCallback); uicontrol('Style','text','Position',[120 290 80 20],'String','ct-x max'); %the range edit box only allows integer ranges greater than 1 %skip is forced to be at least 5% of the range (or we get too many lines) rangeEditCallback=['range=floor(str2num(get(rangeEdit,''String'')));,'... 'if(length(range)==0) range=10; end;,'... 'if(range<1) range=10; end;,'... 'if(range>100) set(rangeSlider,''Value'',100); else set(rangeSlider,''Value'',range); end;,'... 'if(range*.05>skip) skip=floor(.05*range); end;,'... 'set(rangeEdit,''String'', range);,'... 'set(unitSkip,''String'',skip);,'... 'drawGridCallback(thePlot,velocity,range,skip,lightLineToggle,c);']; rangeEdit=uicontrol('Style','edit','Position',[120 260 80 20],'Callback',rangeEditCallback); uicontrol('Style','text','Position',[220 290 80 20],'String','unit skip'); %the skip edit box only allows skip to be integers greater than 5% of range unitSkipCallback=['skip=floor(str2num(get(unitSkip,''String'')));,'... 'if(length(skip)==0) skip=floor(.05*range); end;,'... 'if(skip<.05*range) skip=floor(.05*range); end;,'... 'set(unitSkip,''String'', skip);,'... 'drawGridCallback(thePlot,velocity,range,skip,lightLineToggle,c);']; unitSkip=uicontrol('Style','edit','Position',[220 260 80 20],'Callback',unitSkipCallback); %close both figures closeCallback=['close(this);, close(thePlot);']; uicontrol('Style','pushbutton', 'Position',[400 20 30 30],'String','Close','Callback',closeCallback); %set the initial values set(velocitySlider,'Value',velocity); set(velocityEdit,'String',velocity); set(rangeEdit,'String',range); set(rangeSlider,'Value',range); set(unitSkip,'String',skip);