Advertisement
Guest User

Untitled

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