# Writing text in Flickering Square

**URL:** <https://psychtoolbox.discourse.group/t/writing-text-in-flickering-square/172>\
**Category:** Uncategorized\
**Created:** [September 18, 2016, 3:01pm UTC](https://psychtoolbox.discourse.group/t/writing-text-in-flickering-square/172 "2016-09-18T15:01:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [September 18, 2016, 3:01pm UTC](https://psychtoolbox.discourse.group/t/writing-text-in-flickering-square/172/1 "2016-09-18T15:01:43Z")

</div>

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');
```

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [September 18, 2016, 7:58pm UTC](https://psychtoolbox.discourse.group/t/writing-text-in-flickering-square/172/2 "2016-09-18T19:58:01Z")

</div>

Have a look at [DrawFormattedTextDemo](http://docs.psychtoolbox.org/DrawFormattedTextDemo), or just Screen('DrawText')

  

> On Sun, Sep 18, 2016 at 5:01 PM, [uetmathematics@...](mailto:uetmathematics@...) [PSYCHTOOLBOX] \<[PSYCHTOOLBOX@yahoogroups.com](mailto: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');
> > ```
