# How to create texture inside disk?

**URL:** <https://psychtoolbox.discourse.group/t/how-to-create-texture-inside-disk/3560>\
**Category:** Programming Help\
**Created:** [December 3, 2020, 5:48pm UTC](https://psychtoolbox.discourse.group/t/how-to-create-texture-inside-disk/3560 "2020-12-03T17:48:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cecile](https://avatars.discourse-cdn.com/v4/letter/c/ea666f/32.png) [@cecile](https://psychtoolbox.discourse.group/u/cecile)\
**Post date:** [December 3, 2020, 5:48pm UTC](https://psychtoolbox.discourse.group/t/how-to-create-texture-inside-disk/3560/1 "2020-12-03T17:48:29Z")

</div>

Hello everyone,  
(PTB3 on OS X Catalina)  
My goal is to make circular textures rotate given specific registered input.  
The main problem I have is that, while I know how to create discs(inside given dstRect), and to create spiral textures (inside given dstRect), I cannot manage to make the **texture inside the disc**.  
please help me get out of this massive stalling, would be very appreciated!

Below some lines from my script:

[win, winRect] = PsychImaging(‘OpenWindow’, screenid, 0.5);

[width, height] = RectSize(winRect);

Screen(‘BlendFunction’, win, ‘GL\_SRC\_ALPHA’, ‘GL\_ONE\_MINUS\_SRC\_ALPHA’);

smoothMethod = 1;  
disctexture = CreateProceduralSmoothedDisc(win, virtualSize, virtualSize, [0 0 0 0], radius, sigma, …  
useAlpha, smoothMethod);

texrect = Screen(‘Rect’, disctexture);  
ndiscs =2

dstRects = nan(4, 2); %4 x number of images  
for i = 1:ndiscs  
theRect = [0 0 imageWidths imageHeights];  
dstRects(:, i) = CenterRectOnPointd(theRect, xPos(i), yPos);  
end

[xCenter, yCenter] = RectCenter(windowRect);  
dim = 100;  
dim2 = ceil(dim \* sqrt(2));  
[x, y] = meshgrid(-dim2:1:dim2, -dim2:1:dim2);  
[th, r] = cart2pol(x, y);  
wheel = grey + inc .\* cos(pi \* th);  
spiralTexture = Screen(‘MakeTexture’, window, wheel);  
rotAngles = rand(1, ndiscs) \* 360;  
colours = zeros(3,2)  
colours(:,1) = [0; 0; 1]; colours(:,2)= [0;1;0];  
myAlphas = [1 1];

Screen(‘DrawTextures’, window, spiralTexture, [],…  
dstRects, rotAngles, [], [], colorMod(:, 1:2));  
Screen(‘DrawTextures’, win, disctexture, [], dstRects, rotAngles, [], [], []);

---

<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 17, 2020, 11:23pm UTC](https://psychtoolbox.discourse.group/t/how-to-create-texture-inside-disk/3560/2 "2020-12-17T23:23:18Z")

</div>

> [@cecile](#):
>
> ```matlab
> smoothMethod = 1;
> disctexture = CreateProceduralSmoothedDisc(win, virtualSize, virtualSize, [0 0 0 0], radius, sigma, …
> useAlpha, smoothMethod);
> 
> ```

You should use `smoothMethod = 2` as this inverts the disc so the middle is transparent and the surround is opaque, see `ProceduralSmoothedDiscMaskDemo` for an example…

> % ‘method’ whether to use cosine (0) or smoothstep (1) functions. If you  
> % pass (2) then the smoothstep will be inverted, so you can use it as a  
> % mask (see ProceduralSmoothedDiscMaskDemo.m for example).
