This file is indexed.

/usr/share/opensesame/examples/joystick_demonstration.opensesame is in opensesame 0.27.4-2.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
306
# Generated by OpenSesame 0.26 (Earnest Einstein)
# Fri Jun 01 09:41:30 2012 (nt)
# 
set foreground "white"
set subject_parity "even"
set description "Demonstrates the basic functionallities of the joystick plugin"
set title "joystick_demonstration"
set compensation "0"
set coordinates "relative"
set height "768"
set mouse_backend "legacy"
set width "1024"
set sampler_backend "legacy"
set keyboard_backend "legacy"
set background "black"
set subject_nr "0"
set canvas_backend "legacy"
set start "experiment"
set synth_backend "legacy"

define feedback feebdack
	set duration "300"
	set reset_variables "yes"
	set description "Displays stimuli"
	set start_response_interval "no"
	draw textline 0 0 "Hit!" center=1 color=green font_family=mono font_size=36 show_if="[correct]=1"
	draw textline 0 0 "Miss!" center=1 color=red font_family=mono font_size=36 show_if="[correct]=0"

define loop _loop
	set repeat "1"
	set description "Repeatedly runs another item"
	set skip "0"
	set offset "no"
	set item "_sequence"
	set column_order "cradius;cypos;cxpos"
	set cycles "4"
	set order "sequential"
	setcycle 0 cradius "25"
	setcycle 0 cypos "-256"
	setcycle 0 cxpos "0"
	setcycle 1 cradius "25"
	setcycle 1 cypos "256"
	setcycle 1 cxpos "0"
	setcycle 2 cradius "25"
	setcycle 2 cypos "0"
	setcycle 2 cxpos "-256"
	setcycle 3 cradius "25"
	setcycle 3 cypos "0"
	setcycle 3 cxpos "256"
	run _sequence

define sketchpad target
	set duration "0"
	set description "Displays which button to press"
	set start_response_interval "no"
	draw textline 0 0 "[correct_response]" center=1 color=red font_family=mono font_size=36 show_if="always"
	draw textline 0 -64 "Please press" center=1 color=white font_family=mono font_size=18 show_if="always"
	draw textline 0 64 "on the joystick" center=1 color=white font_family=mono font_size=18 show_if="always"

define sequence sequence
	run target "always"
	run joystick "always"
	run logger "always"
	run feedback "always"

define joystick joystick
	set correct_response "[correct_response]"
	set _dummy "no"
	set allowed_responses "1;2;3;4;5"
	set description "Collects input from a joystick or gamepad"
	set timeout "infinite"

define sequence _sequence
	run basic_screen "always"
	run inline_script_getinput "always"
	run feebdack "always"

define sketchpad welcome
	set duration "keypress"
	set start_response_interval "no"
	set description "Displays stimuli"
	draw textline 0 -100 "Joystick demonstration" center=1 color=white font_family=serif font_size=32 show_if="always"
	draw textline 0 0 "Press any key (on the keyboard) to continue" center=1 color=white font_family=serif font_size=16 show_if="always"

define inline_script inline_script_get_axes
	___run__
	from openexp.canvas import canvas
	
	# opensesame-0.25
	exp = self.experiment # uncomment if you're using a version below 0.26
	
	# constants
	DRADIUS = 5 # dot radius
	RUNTIME = 5000 # ms
	
	# variables
	dpos = [self.get("width")/2, self.get("height")/2] # sets dot position to screen center
	
	# create canvas object
	my_canvas = canvas(exp)
	
	# draw canvas
	my_canvas.fixdot(x=dpos[0],y=dpos[1],color='red') # draw dot at starting position
	my_canvas.show() # canvas goes online
	
	# collect response and draw to screen
	running = True
	oldpos = [0,0]
	t0 = self.time() # get timestamp
	while running:
		# get a response
		position, time = self.experiment.joystick.get_joyaxes(timeout=10)
		# a low timeout means a low refresh rate for the joystick,
		# which makes for smoother movement
		
		# check time
		if time - t0 > RUNTIME:
			running = False
		
		# use position to calculate new dot-coordinates
		if position: # if not, there has been a timeout
			dpos[0] += 10 * position[0]
			dpos[1] += 10 * position[1]
			oldpos[0] = position[0]
			oldpos[1] = position[1]
		else: # in case of a timeout
			dpos[0] += 10 * oldpos[0]
			dpos[1] += 10 * oldpos[1]
			# we keep track of the previous position of
			# the axes, since no joystick movement does
			# not necessarily mean a user does not want
			# to move the dot: when it is held steadily
			# but forward, no new movement will be detected
			# but the user does want to move the dot
			# forward!
		
		# adjust canvas 
		my_canvas.clear() # clear previous dot
		my_canvas.fixdot(x=dpos[0],y=dpos[1],color='red') # draw dot at new position
		
		# show canvas
		my_canvas.show()
	__end__
	set _prepare ""
	set description "Executes Python code"

define inline_script inline_script_getinput
	___run__
	import numpy
	from openexp.canvas import canvas
	
	# opensesame-0.25
	exp = self.experiment # uncomment if you're using a version below 0.26
	
	# constants
	DRADIUS = 5 # dot radius
	CRADIUS = self.get("cradius") # circle radius
	BASICCANVAS = 'basic_screen'
	JB = [1] # list of allowed joystick buttons
	
	# variables
	dpos = [self.get("width")/2, self.get("height")/2] # sets dot position to screen center
	cpos = [self.get("cxpos")+(self.get("width")/2), self.get("cypos")+(self.get("height")/2)]
	# cxpos is defined in _loop, as a value between minus [width]/2, since in sketchpads
	# (0,0) is the center of the screen, whereas in inline_script canvas-functions (0,0)
	# is the top left; this explains the weird formula
	
	# create canvas object
	my_canvas = canvas(exp)
	
	# draw canvas
	my_canvas.copy(exp.items[BASICCANVAS].canvas) # copy basic canvas
	my_canvas.fixdot(x=dpos[0],y=dpos[1],color='red') # draw dot at starting position
	my_canvas.show() # canvas goes online
	
	# collect response and draw to screen
	running = True
	oldpos = [0,0]
	while running:
		# get a response
		event, value, time = self.experiment.joystick.get_joyinput(joybuttonlist=JB,timeout=10)
		# a low timeout means a low refresh rate for the joystick,
		# which makes for smoother movement
		
		# use position to calculate new dot-coordinates
		if event == "joybuttonpress":
			a = dpos[0] - cpos[0] # distance between x-coordinates of dot and circle
			b = dpos[1] - cpos[1] # distance between y-coordinates of dot and circle
			if numpy.sqrt((a**2)+(b**2)) < CRADIUS: # Pythagoras
				self.experiment.set("correct", 1)
			else:
				self.experiment.set("correct", 0)
			running = False
		elif event == "joyaxismotion":
			dpos[0] += 10 * value[0]
			dpos[1] += 10 * value[1]
			oldpos[0] = value[0]
			oldpos[1] = value[1]
		else: # in case of a timeout
			dpos[0] += 10 * oldpos[0]
			dpos[1] += 10 * oldpos[1]
			# we keep track of the previous position of
			# the axes, since no joystick movement does
			# not necessarily mean a user does not want
			# to move the dot: when it is held steadily
			# but forward, no new movement will be detected
			# but the user does want to move the dot
			# forward!
		
		# adjust canvas 
		my_canvas.copy(exp.items[BASICCANVAS].canvas) # copy basic canvas
		my_canvas.fixdot(x=dpos[0],y=dpos[1],color='red') # draw dot at new position
		
		# show canvas
		my_canvas.show()
	__end__
	set _prepare ""
	set description "Executes Python code"

define sequence experiment
	run read_me "always"
	run welcome "always"
	run loop "always"
	run part_2 "always"
	run instructions_part_2 "always"
	run inline_script_get_axes "always"
	run part_3 "always"
	run instructions_part_3 "always"
	run _loop "always"

define sketchpad instructions_part_3
	set duration "5000"
	set description "Displays stimuli"
	set start_response_interval "no"
	draw textline 0 0 "In the following screens, please place the dot in the circle and press button 1." center=1 color=white font_family=mono font_size=18 show_if="always"

define sketchpad instructions_part_2
	set duration "1000"
	set description "Displays stimuli"
	set start_response_interval "no"
	draw textline 0 0 "Move the stick about, please." center=1 color=white font_family=mono font_size=18 show_if="always"

define sketchpad basic_screen
	set duration "0"
	set description "Displays stimuli"
	set start_response_interval "no"
	draw circle [cxpos] [cypos] 50 fill=0 penwidth=3 color=green show_if="always"

define notepad read_me
	__note__
	This experiment shows how the joystick plugin
	can be implemented in an experiment. Feel free
	to use anything you may find to your liking
	and/or adjust the code to your own needs.
	
	Author: Edwin Dalmaijer
	__end__
	set description "Some pointers to help you get started!"

define logger logger
	set ignore_missing "yes"
	set auto_log "no"
	set description "Logs experimental data"
	set unicode "no"
	set use_quotes "yes"
	log "response_joystick"
	log "response_time_joystick"
	log "correct_response"

define sketchpad part_3
	set duration "keypress"
	set description "Displays stimuli"
	set start_response_interval "no"
	draw textline 0 -100 "Part 3" center=1 color=white font_family=serif font_size=32 show_if="always"
	draw textline 0 0 "Press any key (on the keyboard) to continue" center=1 color=white font_family=serif font_size=16 show_if="always"

define sketchpad part_2
	set duration "keypress"
	set description "Displays stimuli"
	set start_response_interval "no"
	draw textline 0 -100 "Part 2" center=1 color=white font_family=serif font_size=32 show_if="always"
	draw textline 0 -30 "" center=1 color=white font_family=serif font_size=16 show_if="always"
	draw textline 0 0 "Press any key (on the keyboard) to continue" center=1 color=white font_family=serif font_size=16 show_if="always"

define loop loop
	set repeat "1"
	set description "Repeatedly runs another item"
	set skip "0"
	set offset "no"
	set item "sequence"
	set column_order "correct_response"
	set cycles "5"
	set order "random"
	setcycle 0 correct_response "1"
	setcycle 1 correct_response "2"
	setcycle 2 correct_response "3"
	setcycle 3 correct_response "4"
	setcycle 4 correct_response "5"
	run sequence

define feedback feedback
	set duration "200"
	set reset_variables "yes"
	set description "Provides feedback to the participant"
	draw textline 0 0 "Correct!" center=1 color=green font_family=mono font_size=18 show_if="[response]=[correct_response]"
	draw textline 0 0 "Incorrect!" center=1 color=red font_family=mono font_size=18 show_if="[response]!=[correct_response]"