MovieDemo (PsychDemos in PsychToolBox)
50行ほど(+%コメント)の画面制御の基本サンプル
------------------
The movie was shown twice, running over by 8 frames in the first and 3
frames in the second showing. The first showing may have been jerky, due
to interruptions. The second showing used Rush, at priority 0.5, to
minimize interruptions, to make the movie run smoothly. See
MovieTearDemo and Rush.
-------------------
% Open a window
screenNumber=0;
pixelSize=8;
[window,windowRect]=Screen(screenNumber,'OpenWindow',[],[],pixelSize);
n=300;
% n=min(windowRect(RectBottom),2*round((Bytes*2-1e6)^0.33/2)); % make movie as big as memory will allow.
rect=[0 0 n n];
rect2=AlignRect(rect,windowRect,RectRight,RectBottom);
waitSecs(1); % Give display a moment to recover from the change of pixelSize
% Make a movie by drawing disks into 1+n/2 offscreen windows.
black=BlackIndex(window);
for i=1:(1+n/2)
w(i)=Screen(window,'OpenOffscreenWindow',[],rect);
w(n+2-i)=w(i);
r=[0 0 2 2]*(i-1);
Screen(w(i),'FillOval',black,r);
end
% Show the movie, first forwards, then backwards.
Screen(window,'TextSize',24);
Screen(window,'DrawText','Showing movie at priority 0 ...',10,30);
HideCursor;
for i=1:length(w)
Screen(window,'WaitBlanking');
s(i)=GetSecs;
Screen('CopyWindow',w(i),window,rect,rect2);
end
s=diff(s);
frames1=sum(s)*FrameRate(screenNumber)-length(s);
% Show the movie again, now using Rush to minimize interruptions.
loop={
'for i=1:length(w);'
'Screen(window,''WaitBlanking'');'
's(i)=GetSecs;'
'Screen(''CopyWindow'',w(i),window,rect,rect2);'
'end;'
};
priorityLevel=MaxPriority(screenNumber,'WaitBlanking');
Screen(window,'FillRect');
Screen(window,'DrawText',sprintf('Showing movie at priority %g ...?n',priorityLevel),10,30);
i=0;Screen('Screens'); % Make sure all Rushed variables and functions are in memory.
Rush(loop,priorityLevel);
s=diff(s);
frames2=sum(s)*FrameRate(screenNumber)-length(s);
ShowCursor;
% Close the on- and off-screen windows
Screen('CloseAll');
if round(frames1)==0 & round(frames2)==0
s=sprintf('Success! The movie was shown twice. Both showings were frame-accurate.');
else
s=sprintf('The movie was shown twice, running over by %.0f frames in the first and %.0f frames in the second showing.',frames1,frames2);
end
s=sprintf('%s The first showing may have been jerky, due to interruptions. The second showing used Rush, at priority %g, to minimize interruptions, to make the movie run smoothly. See MovieTearDemo and Rush.',s,priorityLevel);
fprintf('%s?n',WrapString(s));
50行ほど(+%コメント)の画面制御の基本サンプル
------------------
The movie was shown twice, running over by 8 frames in the first and 3
frames in the second showing. The first showing may have been jerky, due
to interruptions. The second showing used Rush, at priority 0.5, to
minimize interruptions, to make the movie run smoothly. See
MovieTearDemo and Rush.
-------------------
% Open a window
screenNumber=0;
pixelSize=8;
[window,windowRect]=Screen(screenNumber,'OpenWindow',[],[],pixelSize);
n=300;
% n=min(windowRect(RectBottom),2*round((Bytes*2-1e6)^0.33/2)); % make movie as big as memory will allow.
rect=[0 0 n n];
rect2=AlignRect(rect,windowRect,RectRight,RectBottom);
waitSecs(1); % Give display a moment to recover from the change of pixelSize
% Make a movie by drawing disks into 1+n/2 offscreen windows.
black=BlackIndex(window);
for i=1:(1+n/2)
w(i)=Screen(window,'OpenOffscreenWindow',[],rect);
w(n+2-i)=w(i);
r=[0 0 2 2]*(i-1);
Screen(w(i),'FillOval',black,r);
end
% Show the movie, first forwards, then backwards.
Screen(window,'TextSize',24);
Screen(window,'DrawText','Showing movie at priority 0 ...',10,30);
HideCursor;
for i=1:length(w)
Screen(window,'WaitBlanking');
s(i)=GetSecs;
Screen('CopyWindow',w(i),window,rect,rect2);
end
s=diff(s);
frames1=sum(s)*FrameRate(screenNumber)-length(s);
% Show the movie again, now using Rush to minimize interruptions.
loop={
'for i=1:length(w);'
'Screen(window,''WaitBlanking'');'
's(i)=GetSecs;'
'Screen(''CopyWindow'',w(i),window,rect,rect2);'
'end;'
};
priorityLevel=MaxPriority(screenNumber,'WaitBlanking');
Screen(window,'FillRect');
Screen(window,'DrawText',sprintf('Showing movie at priority %g ...?n',priorityLevel),10,30);
i=0;Screen('Screens'); % Make sure all Rushed variables and functions are in memory.
Rush(loop,priorityLevel);
s=diff(s);
frames2=sum(s)*FrameRate(screenNumber)-length(s);
ShowCursor;
% Close the on- and off-screen windows
Screen('CloseAll');
if round(frames1)==0 & round(frames2)==0
s=sprintf('Success! The movie was shown twice. Both showings were frame-accurate.');
else
s=sprintf('The movie was shown twice, running over by %.0f frames in the first and %.0f frames in the second showing.',frames1,frames2);
end
s=sprintf('%s The first showing may have been jerky, due to interruptions. The second showing used Rush, at priority %g, to minimize interruptions, to make the movie run smoothly. See MovieTearDemo and Rush.',s,priorityLevel);
fprintf('%s?n',WrapString(s));