try
    % general opening operations
    whichscreen = max(Screen('Screens'));
    [w, rect] = Screen('OpenWindow', whichscreen);
    % get the flip interval
    slack = Screen('GetFlipInterval', w)/2;
    % draw the fixation dot in the backgound
    Screen('FillOval', w, 0, CenterRect([0, 0, 10, 10], rect));
    % present the fixation
    fixation_onset = Screen('Flip', w); % get the onsettime of the fixation
    % draw the first stimulus in the backgound
    Screen('FillRect', w, [255, 0, 0], CenterRect([0, 0, 50, 50], rect));
    % present the first stimulus 0.5 seconds after the onset of the fixation
    firststimulus_onset = Screen('Flip', w, fixation_onset + 0.5 - slack);
    % keep the stimulus on screen for 0.75 seconds
    firststimulus_offset=Screen('Flip',w,firststimulus_onset + 0.75 -slack);
    % draw the second stimulus in the backgound
    Screen('FillRect', w, [0, 255, 0], CenterRect([0, 0, 50, 50], rect));
    % draw the second stimulus 1 second after the offset
    % of the first stimulus
    secondstimulus_onset=Screen('Flip',w,firststimulus_offset+1.0-slack);
    % keep the second stimulus on for 0.6 second
    secondstimulus_offset=Screen('Flip',w,secondstimulus_onset+0.6-slack);
    Screen('CloseAll'); % close all
catch
    Screen('Close',w)
    rethrow(lasterror)
end