-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakeBox.m
82 lines (63 loc) · 2.54 KB
/
makeBox.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
rootdir = pwd; % root directory - used to inform directory mappings
addpath(genpath(fullfile(rootdir, 'lib'))); % add tools folder to path
p.screen_distance = 156.5; % cbu mri = 1565mm
p.screen_width = q69.84; % cbu mri = 698.4mm
p.resolution = [1920,1080]; % cbu mri = [1920,1080] (but not actual I think)
p.window_size = [0 0 1200 800]; % size of window when ~p.fullscreen_enabled
p.fullscreen_enabled = 1;
% stimulus settings
boxStim = imread('box.png');
boxSize = 100;
thisPPU = p.resolution(1)/p.screen_width;
boxResize = thisPPU*boxSize/(150/2.54);
newBox = imresize(boxStim,[boxResize,boxResize]);
% convert this to angle with screen distance of jsPsych (50)
% not quite sure about this, but can do current ppi*stimHeightPixels/150 to
% --- screen stuff --- %
Screen('Preference', 'SkipSyncTests', 1);
% get the screen numbers
p.screens = Screen('Screens'); % funny difference pc to other oses, but doesn't matter in cbu fMRI
% draw to the external screen if available
p.screen_num = max(p.screens);
p.black = BlackIndex(p.screen_num); % essentially [0 0 0]
p.white = WhiteIndex(p.screen_num);
p.grey = p.white / 2; % essentially [255/2 255/2 255/2]
p.bg_colour = p.grey;
p.text_colour = p.black; % colour of instructional text
p.text_size = 40; % size of text
try
%----------%
% commence %
%----------%
% open screen
if p.fullscreen_enabled % zero out p.window_size if p.fullscreen_enabled = 1
p.window_size=[];
end
[p.win,p.rect] = Screen('OpenWindow',p.screen_num,p.bg_colour,p.window_size);
Screen('BlendFunction',p.win,GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); % allows transparency in .png images
Screen('TextSize', p.win, p.text_size); % set the text size
[p.xCenter, p.yCenter] = RectCenter(p.rect); % get the center
HideCursor;
ListenChar(2);
WaitSecs(0.5); % warm up
baseRect = [0 0 boxResize boxResize];
centeredRect = CenterRectOnPointd(baseRect, p.xCenter, p.yCenter);
rectColor = [1 0 0];
%Screen('FillRect', p.win, rectColor, centeredRect);
t.stim_tex = Screen('MakeTexture', p.win, newBox);
Screen('DrawTexture', p.win, t.stim_tex); % draws the cue
% then display cue
t.cue_onset = Screen('Flip', p.win); % pull the time of the screen flip from the flip function while flipping
KbWait();
% close screen
ShowCursor;
clear ans; % clear extraneous stuff
Screen('Close',p.win);
ListenChar(0);
fprintf('done running %s\n', mfilename);
catch err
ShowCursor;
ListenChar(0);
Screen('CloseAll');
rethrow(err);
end