Writing text in Flickering Square

Hi everyone.

I have created a flickering square using Psychtoolbox-3 toolbox in MATLAB. I want to write a text in that square. How can I do that? Is it possible? Any help could be appreciated.

Below is my code for flickering square.


clear all
clc
screenNum=0;
flipSpd=0;
[wPtr,rect]=Screen('OpenWindow',screenNum);             % wPtr - designate the window, rect - screen size
monitorFlipInterval=Screen('GetFlipInterval', wPtr);    % Refresh time [s]
frame_rate = 1/monitorFlipInterval;                     % Frame rate [Hz]
%%%%%%%%%%%%%%%% Setteing Frequencies of the Square %%%%%%%%%%%%%%%%%%%%%
p=10;
P = frame_rate/(2*p);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
color_black = [255 255 255];        % Defining black color
color_white = [0 0 0];              % Defining white colot 

CenX = rect(3)/2;                   % Center of width
CenY = rect(4)/2;                   % Center of height

Dis = 200;
SqS = 200;
X=100;     
Y1=300; Y2=200; Y3=100;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Position of the square %%%%%%%%%%%%%%%%%%%%%
pos1=[CenX-X CenY-Y1 CenX-X+Dis CenY-Y1+SqS];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
black=BlackIndex(wPtr);             % Find the color lookup table values (black)
white=WhiteIndex(wPtr);             % Find the color lookup table values (white)

%% -----------------------------------------------------------------------
Screen('FillRect',wPtr,black);      % Fills a rectangle the size of the screen to be black
Screen(wPtr, 'Flip');               % Flip the screen from offscreen to onscreen
HideCursor;
tic
while toc<1;
end
Screen('FillRect',wPtr,black);      % Blacks the screen
vbl=Screen(wPtr, 'Flip');           % Collect the time for the first flip with vbl
tic

for i=1:600 % "time of run"
    % Generate the flickering squares

      if mod(i,p)==0
        Screen('FillRect',wPtr,color_black, pos1);
    else
        Screen('FillRect',wPtr,color_white, pos1);
      end
Screen(wPtr, 'Flip');
end

toc
Screen('FillRect',wPtr,black);      % Blacks the screen
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
Screen('CloseAll');




Have a look at DrawFormattedTextDemo, or just Screen('DrawText')

On Sun, Sep 18, 2016 at 5:01 PM, uetmathematics@... [PSYCHTOOLBOX] <PSYCHTOOLBOX@yahoogroups.com> wrote:


Hi everyone.

I have created a flickering square using Psychtoolbox-3 toolbox in MATLAB. I want to write a text in that square. How can I do that? Is it possible? Any help could be appreciated.

Below is my code for flickering square.


clear all
clc
screenNum=0;
flipSpd=0;
[wPtr,rect]=Screen(' OpenWindow',screenNum);             % wPtr - designate the window, rect - screen size
monitorFlipInterval=Screen(' GetFlipInterval', wPtr);    % Refresh time [s]
frame_rate = 1/monitorFlipInterval;                     % Frame rate [Hz]
%%%%%%%%%%%%%%%% Setteing Frequencies of the Square %%%%%%%%%%%%%%%%%%%%%
p=10;
P = frame_rate/(2*p);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%
color_black = [255 255 255];        % Defining black color
color_white = [0 0 0];              % Defining white colot 

CenX = rect(3)/2;                   % Center of width
CenY = rect(4)/2;                   % Center of height

Dis = 200;
SqS = 200;
X=100;     
Y1=300; Y2=200; Y3=100;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Position of the square %%%%%%%%%%%%%%%%%%%%%
pos1=[CenX-X CenY-Y1 CenX-X+Dis CenY-Y1+SqS];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%
black=BlackIndex(wPtr);             % Find the color lookup table values (black)
white=WhiteIndex(wPtr);             % Find the color lookup table values (white)

%% ------------------------------ ------------------------------ -----------
Screen('FillRect',wPtr,black);      % Fills a rectangle the size of the screen to be black
Screen(wPtr, 'Flip');               % Flip the screen from offscreen to onscreen
HideCursor;
tic
while toc<1;
end
Screen('FillRect',wPtr,black);      % Blacks the screen
vbl=Screen(wPtr, 'Flip');           % Collect the time for the first flip with vbl
tic

for i=1:600 % "time of run"
    % Generate the flickering squares

      if mod(i,p)==0
        Screen('FillRect',wPtr,color_ black, pos1);
    else
        Screen('FillRect',wPtr,color_ white, pos1);
      end
Screen(wPtr, 'Flip');
end

toc
Screen('FillRect',wPtr,black);      % Blacks the screen
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterv al));
Screen('CloseAll');