Skip to content

Instantly share code, notes, and snippets.

@iandol
Created September 5, 2017 08:48
Show Gist options
  • Save iandol/ba19b1b291e9b90630e21b83b0dfc9ff to your computer and use it in GitHub Desktop.
Save iandol/ba19b1b291e9b90630e21b83b0dfc9ff to your computer and use it in GitHub Desktop.
function ProceduralGaussBlob(ngabors, nlines)
PsychDefaultSetup(2);
if nargin < 1 || isempty(ngabors)
ngabors = 200;
end
screenid = max(Screen('Screens'));
Screen('Preference', 'SkipSyncTests', 1)
PsychImaging('PrepareConfiguration');
PsychImaging('AddTask', 'General', 'FloatingPoint32BitIfPossible');
[win, winRect] = PsychImaging('OpenWindow', screenid, 0.5);
[w, h] = RectSize(winRect);
if nargin < 1 || isempty(nlines)
nlines = 2*w;
end
ifi = Screen('GetFlipInterval', win);
%%% drow Linemasks %%%
LineAngle = 45*pi/180;
LineLength = 2*w;
for i = 1:nlines
XCenter = (-nlines/2+i)*sin(LineAngle);
YCenter = (-nlines/2+i)*cos(LineAngle);
X(2*i-1) = XCenter-LineLength/2*cos(LineAngle);
X(2*i) = XCenter+LineLength/2*cos(LineAngle);
Y(2*i-1) = YCenter+LineLength/2*sin(LineAngle);
Y(2*i) = YCenter-LineLength/2*sin(LineAngle);
end
XYMatrix = [X+w/2; Y+h/2];
color = ones(1,nlines).*rand(1,nlines);
for i = 1:nlines
ColorLines(2*i-1) = color(i);
ColorLines(2*i) = color(i);
end
ColorMatrix = repmat(ColorLines,3,1);
%%% drow GaussBolbs %%%
half_size = 32;
tw = 2*half_size+1;
th = 2*half_size+1;
sc = 10.0;
contrast = 10;
aspectratio = 1.0;
blobpars = repmat([contrast, sc, aspectratio, 1]', 1, ngabors);
blobpars(1,:) = blobpars(1,:).*((rand(1,ngabors)-0.5)*2);
blobtex = CreateProceduralGaussBlob(win, tw * 2, th * 2);
scale = 0.5;
texrect = Screen('Rect', blobtex)*scale;
inrect = repmat(texrect', 1, ngabors);
dstRects = zeros(4, ngabors);
for i=1:ngabors
dstRects(:, i) = CenterRectOnPoint(texrect, rand * w, rand * h)';
end
vbl = Screen('Flip', win);
while ~KbCheck(-1)
Screen('BlendFunction', win, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
%Screen('DrawLines', win, XYMatrix, [], ColorMatrix, [], 2, []);
Screen('BlendFunction', win, GL_ONE, GL_ONE);
Screen('DrawTextures', win, blobtex, [], dstRects, [], [], [], [], [], kPsychDontDoRotation, blobpars);
Screen('DrawingFinished', win);
[x, y] = RectCenterd(dstRects);
x = mod(x + 2, w);
y = mod(y - 2, h);
dstRects = CenterRectOnPointd(inrect .* ones(4,ngabors), x, y);
vbl = Screen('Flip', win, vbl + 0.5 * ifi);
end
vbl = Screen('Flip', win);
sca;
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment