# New User visualization

**URL:** <https://psychtoolbox.discourse.group/t/new-user-visualization/4759>\
**Category:** Programming Help\
**Created:** [December 20, 2022, 8:48pm UTC](https://psychtoolbox.discourse.group/t/new-user-visualization/4759 "2022-12-20T20:48:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jTneurd90](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jTneurd90](https://psychtoolbox.discourse.group/u/jTneurd90)\
**Post date:** [December 20, 2022, 8:48pm UTC](https://psychtoolbox.discourse.group/t/new-user-visualization/4759/1 "2022-12-20T20:48:22Z")

</div>

Im just getting started on trying to things going. I have run into issues after spending 2 full days on one thing.  
Very simply, I am getting an error on Screen function (see below).

The goal of this section of code, is to create a floating white screen with a grey dot (different sizes )on the right and left side of the screen. As far as the screen spatial features, I don’t think I am having any issue. I used the information from the demo, and 2 Youtubes which do not detail the differences between the arguments and and how to make the drawDot function apply to the creation of circles. Pls help

```auto
Screen('Preference', 'SkipSyncTests', 1);
screens = Screen('Screens'); % calls all screens and stores in "screens' variable
screenNumber = min(screens);
whitecol = [255 255 255];
startXpix = 120;
startYpix = 50;

% Dimensions in pixels of our window in the X (left-right) and Y (up down)
% dimensions
dimX = 400;
dimY = 250;

[outWindow, rect]=Screen('OpenWindow',screenNumber,whitecol,...
[startXpix startYpix startXpix + dimX startYpix + dimY]);

Screen('Flip', outWindow)

greycol = 150;
penwidth = 5;
centerx=(rect(3)/2);
centery=(rect(4)/2);
Screen('BlendFunction', outWindow, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

Screen('DrawDots', Outwindow, [centerx centery], 50, greycol, 2)
Screen('Flip', outWindow)

```

---

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [December 21, 2022, 2:10am UTC](https://psychtoolbox.discourse.group/t/new-user-visualization/4759/2 "2022-12-21T02:10:04Z")

</div>

Well you have a typo with `outWindow` and `Outwindow` which will stop MATLAB as variables are case sensitive. But you are also misunderstanding `DrawDots`:

```auto
[...] = Screen('DrawDots', windowPtr, xy [,size] [,color] [,center] [,dot_type][, lenient]);

 "xy" is a two-row vector containing the x and y coordinates of the dot centers, relative to "center" (default center is [0 0]).

```

The screen **center** is passed in the `center` parameter. `xy` is the dot position _relative_ to this center. Here is some working code, that also uses PTB functions like `RectCenter` and the future-proof 0-1 colour range:

```matlab
Screen('Preference', 'SkipSyncTests', 2);
PsychDefaultSetup(2)
ptb.ScreenID = min(Screen('Screens'));
ptb.bgColour = [1 1 1];
ptb.rect = [120 50 520 300];
PsychImaging('PrepareConfiguration');
[ptb.win, ptb.winRect] = PsychImaging('OpenWindow', ptb.ScreenID, ptb.bgColour, ptb.rect);
[ptb.xcenter, ptb.ycenter] = RectCenter(ptb.winRect);
ptb.ifi = Screen('GetFlipInterval', ptb.win);
ptb.fps = 1 / ptb.ifi;
Screen('BlendFunction', ptb.win, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

ptb.white = WhiteIndex(ptb.win);
ptb.black = BlackIndex(ptb.win);
ptb.grey = white/2;
dotSize = 50;

% Screen('DrawDots', windowPtr, xy [,size] [,color] [,center] [,dot_type][, lenient]);
Screen('DrawDots', ptb.win, [0 0], dotSize, ptb.grey, [ptb.xcenter, ptb.ycenter]);
Screen('Flip', ptb.win);

WaitSecs(1);
sca;

```

---

<div class="post-metadata">

**Author:** ![jTneurd90](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jTneurd90](https://psychtoolbox.discourse.group/u/jTneurd90)\
**Post date:** [December 26, 2022, 7:19pm UTC](https://psychtoolbox.discourse.group/t/new-user-visualization/4759/3 "2022-12-26T19:19:35Z")

</div>

Hi, thank you for your response. This code was helpful and I understand everything except the ptb.ifi and ptb.fps which is not a problem, I looked it up. I still ran into an error and it seemed to be related to the color indexing. However I just specified the color code I needed.

---

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [December 27, 2022, 2:30am UTC](https://psychtoolbox.discourse.group/t/new-user-visualization/4759/4 "2022-12-27T02:30:14Z")

</div>

> [@jTneurd90](#):
>
> I still ran into an error and it seemed to be related to the color indexing

When you use the recommended `PsychDefaultSetup(2)`, colour is specified as RGB with a 0 to 1 range. Pure red is [1 0 0], white is [1 1 1] etc. You can also specify alpha as blending has been enabled, so [1 0 0 0.5] is a half-opaque red, and overlaying two dots should blend their colours together:

```matlab
dotXY = [-10 0;10 0]';
dotColours = [1 0 0 0.5;0 1 0 0.5]';
Screen('DrawDots', ptb.win, dotXY, dotSize, dotColours, [ptb.xcenter, ptb.ycenter],2);
Screen('Flip', ptb.win);

```
