Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2013
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.30 KB | None | 0 0
  1. # Generated by OpenSesame 0.27.2~pre5 (Frisky Freud)
  2. # Tue Apr 23 11:29:21 2013 (posix)
  3. # <http://www.cogsci.nl/opensesame>
  4.  
  5. set foreground "white"
  6. set subject_parity "even"
  7. set description "A template containing a practice and an experimental phase"
  8. set title "Extended template"
  9. set compensation "0"
  10. set coordinates "relative"
  11. set height "768"
  12. set mouse_backend "xpyriment"
  13. set width "1024"
  14. set sampler_backend "legacy"
  15. set keyboard_backend "legacy"
  16. set background "black"
  17. set subject_nr "0"
  18. set canvas_backend "xpyriment"
  19. set start "experiment"
  20. set synth_backend "legacy"
  21.  
  22. define loop patch_loop
  23. set repeat "1"
  24. set description "A single block of trials"
  25. set skip "0"
  26. set offset "no"
  27. set item "stream_of_patches"
  28. set column_order ""
  29. set cycles "1"
  30. set order "random"
  31. run stream_of_patches
  32.  
  33. define sequence vigilance_task
  34. set flush_keyboard "yes"
  35. set description "A sequence containing a single block of trials followed by feedback to the participant"
  36. run define_patch_list "always"
  37. run patch_loop "always"
  38.  
  39. define form_multiple_choice mc
  40. set question ""
  41. set allow_multiple "no"
  42. set description "A simple multiple choice item"
  43. set advance_immediately "no"
  44. set options ""
  45.  
  46. define reset_feedback _reset_feedback
  47.  
  48. define sequence stream_of_patches
  49. set flush_keyboard "yes"
  50. set description "A single trial"
  51. run mc "never"
  52. run inline_script "always"
  53. run logger "never"
  54.  
  55. define loop experimental_loop
  56. set repeat "1"
  57. set description "A loop containing one or more experimental blocks"
  58. set item "vigilance_task"
  59. set column_order ""
  60. set cycles "2"
  61. set order "random"
  62. run vigilance_task
  63.  
  64. define sequence experiment
  65. set flush_keyboard "yes"
  66. set description "The main sequence of the experiment"
  67. run constants "always"
  68. run experimental_loop "always"
  69.  
  70. define inline_script inline_script
  71. ___run__
  72. import pygame
  73. from openexp.exceptions import response_error
  74.  
  75. # Start by playing the sound file:
  76. my_sampler.play()
  77. sampler_paused = False
  78.  
  79. # Walk through the list of patches:
  80. for i in range(len(patch_list)):
  81.  
  82. # If the sampler was paused in the previous iteration, it has
  83. # to be resumed.
  84. if sampler_paused:
  85. my_sampler.resume()
  86.  
  87. # Determine the stimulus by selecting one item from the
  88. # stimulus list (without replacement).
  89. # (Of course, you might do this differently, for example
  90. # by defining the variable 'stim' in a loop item.)
  91. stim = patch_list.pop()
  92.  
  93. # Determine the absolute path to the image in the file pool:
  94. path = exp.get_file(stim)
  95.  
  96. # Set the stimulus for future use in the GUI (notably, the logger
  97. # item):
  98. exp.set("stim", stim)
  99.  
  100.  
  101. # Show the stimulus:
  102.  
  103. # Start with a gray background for a certain duration:
  104. my_canvas.clear()
  105.  
  106. # We have to draw something in order to clear the background.
  107. my_canvas.circle(0,0,0,color=self.get('background'))
  108. my_canvas.show()
  109. self.sleep(wait)
  110.  
  111. # Present the patch
  112. my_canvas.image(path)
  113. my_canvas.show()
  114.  
  115. # The patch is presented until a mouse or key response is given,
  116. # or a timeout (of duration ISI) occurred:
  117.  
  118. # Geth the current time:
  119. start_time = self.time()
  120.  
  121. # Give the value 'time_passed' a beginning value (0).
  122. time_passed = 0
  123.  
  124. # Check for key or mouse responses until a timeout occurs:
  125. while time_passed < ISI:
  126.  
  127. # Keep checking whether the duration of this
  128. # while loop is still below the maximum duration
  129. # (i.e. ISI).
  130. time_passed = self.time()-start_time
  131.  
  132. # To poll the keyboard and mouse at the same time, we use pygame
  133. # directly. This means that this piece of code requires the xpyriment
  134. # or pygame backend! See:
  135. # <http://www.pygame.org/docs/ref/event.html>
  136.  
  137. # First, give the variables 'button' and 'key' the beginning
  138. # value 'False':
  139. button = False
  140. key = False
  141.  
  142. # Loop through all 'events', which are key presses or button clicks
  143. for event in pygame.event.get([pygame.MOUSEBUTTONDOWN, pygame.KEYDOWN]):
  144. if event.type == pygame.MOUSEBUTTONDOWN:
  145. button = True
  146. elif event.type == pygame.KEYDOWN:
  147. if event.key == pygame.K_ESCAPE:
  148. raise response_error("The escape key was pressed.")
  149.  
  150. # Make sure the stream is only paused by a press on the
  151. # space bar (and not by any key press):
  152. elif event.key == pygame.K_SPACE:
  153. key = True
  154.  
  155. # If a key was pressed or a button was clicked, exit the loop
  156. if button or key:
  157. break
  158.  
  159. # Set the given responses so that they will be logged by
  160. # the logger item. Note that for the variable "mouse_click" (see below)
  161. # True' indicates that a mouse click was given, whereas'False'
  162. # indicates that no mouse response was given. This, in combination
  163. # with the variable 'stim', will enable you to evaluate participants'
  164. # performance (i.e. whether a mouse click was correct or a false alarm, etc.):
  165. exp.set("mouse_click", button)
  166.  
  167. # If a mouse response was collected, the for loop will be
  168. # continued. However, if the spacebar was pressed, we need to
  169. # do something else:
  170. if key:
  171.  
  172. # Pause the sampler:
  173. my_sampler.pause()
  174. # And set 'sampler_paused' to True, such that we won't
  175. # forget to resumse the sound stimulus after the pause.
  176. sampler_paused = True
  177.  
  178. # Show the in-the-GUI-prepared form items:
  179. # NOTE: the 'Run if' box for this form item should
  180. # be set to 'never' in the GUI.
  181. self.experiment.items['mc'].prepare()
  182. self.experiment.items['mc'].run()
  183.  
  184. # Finally, log the responses:
  185. # NOTE: the 'Run if' box for this logger item should
  186. # be set to 'never' in the GUI.
  187. self.experiment.items['logger'].prepare()
  188. self.experiment.items['logger'].run()
  189.  
  190. # And set the variable 'form_response' to 'NA' again.
  191. exp.set('form_response', "NA")
  192. __end__
  193. ___prepare__
  194. # Create a canvas item to display the stimulus:
  195. global my_canvas
  196. from openexp.canvas import canvas
  197. my_canvas = canvas(exp, bgcolor = "#7F7F7F")
  198.  
  199. # Create a sampler item that we'll need for playing
  200. # the sounds.
  201. global my_sampler
  202. from openexp.sampler import sampler
  203.  
  204. # Determine the to-be-played sound file:
  205. sound_stim = sound_list.pop()
  206. sound_file = exp.get_file(sound_stim)
  207. my_sampler = sampler(exp, sound_file)
  208. __end__
  209. set description "Executes Python code"
  210.  
  211. define inline_script define_patch_list
  212. set _run ""
  213. ___prepare__
  214. # Declare the visual stimulus list:
  215. global patch_list
  216. patch_list = ["horizontal.png"] * 2 + ["vertical.png"] * 1
  217. random.shuffle(patch_list)
  218. __end__
  219. set description "Executes Python code"
  220.  
  221. define logger logger
  222. set ignore_missing "yes"
  223. set description "Logs experimental data"
  224. set auto_log "yes"
  225. set use_quotes "yes"
  226.  
  227. define inline_script constants
  228. set _run ""
  229. ___prepare__
  230. # Here we'll declare the global variables of the
  231. # experiment:
  232.  
  233. # Import the module 'random', which we'll need to shuffle the
  234. # patch list:
  235. global random
  236. import random
  237.  
  238. # Declare the sound list:
  239. global sound_list
  240. sound_list = ["sound1.wav", "sound2.wav"]
  241. random.shuffle(sound_list)
  242.  
  243. # Declare durations in ms:
  244. global wait, ISI
  245. # Wait between blank screen and patch (to make it
  246. # flickering):
  247. wait = 100
  248. # Inter stimulus interval:
  249. ISI = 1000
  250. __end__
  251. set description "Executes Python code"
  252.  
  253. define reset_feedback reset_feedback
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement