-
Notifications
You must be signed in to change notification settings - Fork 5
/
IAPS_Survey
305 lines (285 loc) · 11.5 KB
/
IAPS_Survey
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
% % IAPS PATTERN EXPRESSION POST SCAN SURVEY %
% % WagerLab: Luke & Marianne 2014 %
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
%%TO DO:
% fix log
% clear all;close all;sca;
%% paths
% addpath(genpath('/Applications/Psychtoolbox'));
% addpath(genpath('/Users/maus/CANLabRepos'));
imagedir='/Users/maus/Documents/MATLAB/images';
bmdir='/Users/maus/Documents/MATLAB/bodymap';
addpath(imagedir);
addpath(bmdir);
%% images for loading
bmdata=imread('bodymap.jpg');
im_list=filenames(sprintf('%s/*',imagedir));
% image list
for i=1:length(im_list)
[path, tag, ext] = fileparts(char(im_list(i)));
images{i}=sprintf('%s%s',tag);
end
randomim=randperm(length(images));
for i=1:length(images)
imageorder(i)=images(randomim(i));
end
imageorder=imageorder';
%% sub info
subid=input('Subject ID: ');
fname=sprintf('IAPSsurvey_%d',subid);
datafilename = strcat('IAPS_survey_',num2str(subid),'.txt'); % name of data file to write to
% check for existing result file to prevent accidentally overwriting
if fopen(datafilename, 'rt')~=-1
fclose('all');
error('Data file already exists! Choose a different subject number.');
else
datafilepointer = fopen(datafilename,'wt'); % open ASCII file for writing
end
if fopen(fname, 'rt')~=-1
fclose('all');
error('Data file already exists! Choose a different subject number.');
end
%% screen settings
% PsychDefaultSetup(2);
screenNumber = max(Screen('Screens'));
%colors
backgroundColor = 0; %black
textColor = 87; %grey
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, black);
% Get the size of the on screen window in pixels
[screenXpixels, screenYpixels] = Screen('WindowSize', window);
% Get the centre coordinate of the window in pixels
[xCenter, yCenter] = RectCenter(windowRect);
ifi = Screen('GetFlipInterval', window);
% Set up alpha-blending for smooth (anti-aliased) lines
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
% Screen('TextFont',window, 'Courier New');
Screen('TextSize',window, 30);
% Screen('TextStyle',window, 1+2);
%%% configure
dspl.screenWidth = windowRect(3);
dspl.screenHeight = windowRect(4);
dspl.xcenter = dspl.screenWidth/2;
dspl.ycenter = dspl.screenHeight/2;
dspl.oscale(1).width = 964;
dspl.oscale(1).height = 252;
dspl.oscale(1).w = Screen('OpenOffscreenWindow',0);
% paint black
Screen('FillRect',dspl.oscale(1).w,0); %needed?
% add scale image
VASscale = imread('bartoshuk_scale.bmp'); % MAKE VAR
VAStex = Screen('MakeTexture',window,VASscale);
% Make a base Rect of 200 by 200 pixels
baseMark = [0 0 20 20];
vbl = Screen('Flip', window);
waitframes = 1;
% Keyboard setup
KbName('UnifyKeyNames');
%% initialize mex func
KbCheck;
WaitSecs(0.1);
GetSecs;
priorityLevel=MaxPriority(window);
Priority(priorityLevel);
%% text questions
Q1='How much does this image make you think of contamination or disease?';
Q2='How physically threatened do you feel?';
Q3='How intentional were the actions taking in the image?';
Q4='How pleasant is this image?'; %or unpleasant?
Q5='How immoral are the events depicted in is this image?';
Q6='Rate how much empathy you felt for the people or animals in this image.';
Q7='Did you get a sense of a story unfolding in this image?';
Q8='With the mouse, mark on this body map where, if at all, you feel the emotions evoked by this image.';
QList=[1:8];
QStrList={Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8};
instruc='Please answer the following questions about the images you saw, as accurately as possible. Click to submit answers on the slider. To start, hit the space bar.';
endexper='Thank you. You have completed the experiment.';
%% scales
% S1='Not At All Very Much';
dspl.oscale(1).rect = [...
[dspl.xcenter dspl.ycenter]-[0.5*dspl.oscale(1).width 0.5*dspl.oscale(1).height] ...
[dspl.xcenter dspl.ycenter]+[0.5*dspl.oscale(1).width 0.5*dspl.oscale(1).height]];
% shiftdown = ceil(dspl.screenHeight*0);
% dspl.oscale(1).rect = dspl.oscale(1).rect + [0 shiftdown 0 shiftdown];
% add title
% Screen('TextSize',dspl.oscale(1).w,50);
% DrawFormattedText(dspl.oscale(1).w,...
% 'OVERALL INTENSITY RATING',...
% 'center',dspl.ycenter-270,255);
% determine cursor parameters for all scales
cursor.xmin = dspl.oscale.rect(1) + 123;
cursor.width = 700;
cursor.xmax = cursor.xmin + cursor.width;
cursor.size = 8;
cursor.center = cursor.xmin + ceil(cursor.width/2);
cursor.y = dspl.oscale.rect(4) - 41;
cursor.labels = cursor.xmin + [10 42 120 249 379];
%%%%%%%%%%%%%%%%%% TASK %%%%%%%%%%%%%%%%%%
%% instructions
try
DrawFormattedText(window,instruc,'center','center',textColor,50);
Screen('Flip',window)
while 1
[keyIsDown,startTime,keyCode] = KbCheck;
if keyCode(KbName('space'))==1
break
end
end
surlog=[];
% qresp=0;
bmap={};
%% task
for i=1:length(imageorder);
%load, resize, and place image
imdata=imread(sprintf('%s%s',char(imageorder(i)),'.jpg'));
tex=Screen('MakeTexture', window, imdata);
[s1, s2, s3] = size(imdata);aspectRatio = s2 / s1;
heightScalers = linspace(1, 0.2, 10);
imageHeights = screenYpixels .* heightScalers;
imageWidths = imageHeights .* aspectRatio;
currImage=str2num(cell2mat(imageorder(i)));
% Number of images
%numImages = numel(heightScalers);
theRect = [0 0 imageWidths(7) imageHeights(7)];
dstRects=CenterRectOnPointd(theRect, screenXpixels/2, screenYpixels/3.5);
[s1, s2, s3] = size(bmdata);aspectRatio = s2 / s1;
heightScalers = linspace(1, 0.2, 10);
imageHeights = screenYpixels .* heightScalers;
imageWidths = imageHeights .* aspectRatio;
bRect = [0 0 imageWidths(5) imageHeights(5)];
bmRects=CenterRectOnPointd(bRect, 1100, screenYpixels/3);
% Screen('DrawTextures', window, tex, [], dstRects);
%rand gen order of ques and store in array ques(i)
randQ=randperm(length(QList));
for x=1:length(QList)
QOrder(x)=QList(randQ(x));
end
for j=1:length(QOrder);
qtext=char(QStrList(QOrder(j)));
[nx, ny, textbounds]=DrawFormattedText(window,qtext,'center',700,textColor,50);
Screen('DrawTextures', window, tex, [], dstRects);
if QOrder(j)==8;
%display bodymap
bmtex=Screen('MakeTexture', window, bmdata);
Screen('DrawTextures', window, bmtex, [], bmRects);
%mouseaction
% Move the cursor to the center of the screen (over image)
% theX = windowRect(RectRight)/2;
% theY = windowRect(RectBottom)/2;
theX=1300;theY=300;
SetMouse(theX,theY);
Screen(window,'DrawText','Click to start. Hit space to finish.',50,50,255);
Screen('Flip', window, 0, 1);
while (1)
[x,y,buttons] = GetMouse(window);
if buttons(1)
break;
end
end
[theX,theY] = GetMouse(window);
thePoints = [theX theY];
% Screen(window,'DrawLine',120,theX,theY,theX,theY,5.5);
Screen('DrawLine',window,[63 183 209 81],theX,theY,theX,theY,7); %doesnt change prop
Screen('Flip', window, 0, 1);
newPt=0;
while (1)
[keyIsDown,startTime,keyCode] = KbCheck;
if keyCode(KbName('space'))==1
break
else keepDraw=1;
end
while keepDraw
[x,y,buttons] = GetMouse(window);
if ~buttons(1)
newPt=5;
break;
else
thePoints = [thePoints ; x y]; %#ok<AGROW>
[numPoints, two]=size(thePoints);
% Only draw the most recent line segment: This is possible,
% because...
if ~newPt
Screen('DrawLine',window,[63 183 209 81],thePoints(numPoints-1,1),thePoints(numPoints-1,2),thePoints(numPoints,1),thePoints(numPoints,2),10);
else
[theX,theY] = GetMouse(window);
Screen('DrawLine',window,[63 183 209 81],theX,theY,theX,theY,10);
% ...we ask Flip to not clear the framebuffer after flipping:
newPt=0;
end
Screen('Flip', window, 0, 1);
theX = x; theY = y;
end
end
end
%save thePoints
bmap{i}=thePoints;
Screen('Flip', window);
else %VAS scale
% display scale
Screen('DrawTextures',window,VAStex,[],dspl.oscale(1).rect);
Screen('DrawTextures', window, tex, [], dstRects); %try textures
% where to start the mouse MAKE RAND
cursor.x = cursor.xmin;
theX=dspl.xcenter;theY=dspl.ycenter;
SetMouse(theX,theY);
centeredMarksc=CenterRectOnPointd(baseMark, cursor.x, cursor.y);
Screen('Flip', window, 0, 1);
getRating=1;
while getRating
[x,y,buttons] = GetMouse(window);
% [clicks]=GetClicks(window);
if buttons(1)
getRating=0;
break;
end
cursor.x = x;
% check bounds
if cursor.x > cursor.xmax
cursor.x = cursor.xmax;
elseif cursor.x < cursor.xmin
cursor.x = cursor.xmin;
end
centeredMark = CenterRectOnPointd(baseMark, cursor.x, cursor.y);
DrawFormattedText(window,qtext,'center',700,textColor,50);
Screen('DrawTextures',window,VAStex,[],dspl.oscale(1).rect);
Screen('DrawTextures', window, tex, [], dstRects); %try textures
Screen('FillRect', window, [128 128 128], centeredMark);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
end
qX=cursor.x;
qresp=(cursor.x-cursor.xmin)/7;
[r,c]=size(surlog);
surlog(r+1,:)=[subid, startTime,currImage,QOrder(j),qX,qresp,vbl]
WaitSecs(.25)
end
% pause(1);
end
end
save(fname,'surlog','bmap');
catch
Screen('CloseAll');
fclose('all');
Priority(0);
psychrethrow(psychlasterror);
end
%%%%%%%%%%%%%%%%%%%%%
%% END SCREEN
%%%%%%%%%%%%%%%%%%%%%
DrawFormattedText(window,endexper,'center','center',textColor);
Screen('Flip',window)
while 1
[keyIsDown,secs,keyCode] = KbCheck;
if keyCode(KbName('space'))==1
break
end
end
%%%%%%%%%%%%%%%%%%%%%
%% CLEAN UP
%%%%%%%%%%%%%%%%%%%%%
Screen('CloseAll');
fclose('all');
Priority(0);
sca;