%  FunkyScreen.m
%
%  opens a window using psychtoolbox,
%  makes the window do some funky things
%
%  written for Psychtoolbox 3 on the PC by IF 3/2007
%%
screenNum=1;
flipSpd=13; %  a flip every 13 frames

[wPtr,rect]=Screen('OpenWindow',screenNum);
monitorFlipInterval=Screen('GetFlipInterval', wPtr);
black=BlackIndex(wPtr);
white=WhiteIndex(wPtr);
% blank the Screen and wait a second
Screen('FillRect',wPtr,black);
Screen(wPtr, 'Flip');
WaitSecs(2);
Screen('CloseAll');
%%
% make a rectangle in the middle of the screen flip colors and size
[wPtr,rect]=Screen('OpenWindow',screenNum);
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr, 'Flip'); % collect the time for the first flip with vbl
for i=1:20
    Screen('FillRect',wPtr,[0 0 255], [100 150 200 250]);
    vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
    % flip 13 frames after vbl
    Screen('FillRect',wPtr,[255 0 0], [100 150 400 450]);
    vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
end

% blank the screen and wait a while
Screen('FillRect',wPtr,black);
Screen(wPtr, 'Flip');
WaitSecs(2);
Screen('CloseAll');

%%
% make circles flip colors & size
[wPtr,rect]=Screen('OpenWindow',screenNum);
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr, 'Flip');
for i=1:20
    Screen('FillOval',wPtr,[0 180 255], [ 500 500 600 600]);
    vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
    Screen('FillOval',wPtr,[0 255 0], [ 400 400 900 700]);
    vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
end

% blank the Screen and wait a second
Screen('FillRect',wPtr,black);
Screen(wPtr, 'Flip');
WaitSecs(2);
Screen('CloseAll');

%%
% make lines that flip colors size  & position
[wPtr,rect]=Screen('OpenWindow',screenNum);
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr, 'Flip');
for i=1:20
    Screen('DrawLine',wPtr,[0 255 255], 500, 200, 700 ,600, 5);
    vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
    Screen('DrawLine',wPtr,[255 255 0], 100, 600, 600 ,100, 5);
    vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
end

% blank the Screen and wait a second
Screen('FillRect',wPtr,black);
Screen(wPtr, 'Flip');
WaitSecs(2);
Screen('CloseAll');



%%
[wPtr,rect]=Screen('OpenWindow',screenNum);
Screen('FillRect',wPtr,black);
Screen(wPtr, 'Flip');
image2D=255*rand(100, 100);
textureIndex=Screen('MakeTexture', wPtr, image2D);
Screen('DrawTexture', wPtr, textureIndex);
Screen(wPtr, 'Flip');
WaitSecs(5);
Screen('CloseAll');

%%
[wPtr,rect]=Screen('OpenWindow',screenNum);
Screen('FillRect',wPtr,black);
Screen(wPtr, 'Flip');
KbName('UnifyKeyNames'); % Unify Max OS X, OS 9
[sec keyCode]=KbPressWait; % wait for the key press
keyCode=find(keyCode~=0);
Screen('TextSize', wPtr , 150);
Screen('DrawText', wPtr, num2str(keyCode), 200, 20, [255 50 255]);
Screen(wPtr, 'Flip');
WaitSecs(2);
Screen('CloseAll');
%%
% combine the stimuli
[wPtr,rect]=Screen('OpenWindow',screenNum);
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr, 'Flip');
for i=1:20
    Screen('FillRect',wPtr,[0 0 255], [100 150 200 250]);
    Screen('DrawLine',wPtr,[0 255 255], 500, 200, 700 ,600, 5);
    Screen('FillOval',wPtr,[0 180 255], [ 500 500 600 600]);
    Screen('TextSize', wPtr , 150);
    Screen('DrawText', wPtr, 'FUNKY!!', 200, 20, [255 50 255]);
    vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));

    Screen('FillRect',wPtr,black);
    vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
end

% blank the screen and wait a second
Screen('FillRect',wPtr,black);
Screen(wPtr, 'Flip');
WaitSecs(2);
Screen('CloseAll');
%%





