LeeB_86

shape generating

Sep 23rd, 2013
72
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Generated by OpenSesame 0.27.4 (Frisky Freud)
  2. # Mon Sep 23 12:34:20 2013 (nt)
  3. # <http://www.cogsci.nl/opensesame>
  4.  
  5. set mouse_backend "xpyriment"
  6. set subject_parity "even"
  7. set height "768"
  8. set font_family "sans"
  9. set font_italic "no"
  10. set custom_cursor "yes"
  11. set synth_backend "legacy"
  12. set title "visuospatial_1234"
  13. set coordinates "relative"
  14. set start "experiment"
  15. set sampler_backend "legacy"
  16. set transparent_variables "no"
  17. set foreground "Black"
  18. set font_bold "no"
  19. set description "Default description"
  20. set background "White"
  21. set font_size "20"
  22. set enable_escape "yes"
  23. set keyboard_backend "legacy"
  24. set canvas_backend "xpyriment"
  25. set compensation "0"
  26. set subject_nr "0"
  27. set width "1366"
  28.  
  29. define loop practice
  30.     set repeat "1"
  31.     set description "Repeatedly runs another item"
  32.     set item "practice_sequence"
  33.     set column_order ""
  34.     set cycles "1"
  35.     set order "sequential"
  36.     run practice_sequence
  37.  
  38. define loop p_block_loop
  39.     set repeat "1"
  40.     set description "Repeatedly runs another item"
  41.     set skip "0"
  42.     set item "p_trial_sequence"
  43.     set column_order ""
  44.     set cycles "50"
  45.     set order "sequential"
  46.     run p_trial_sequence
  47.  
  48. define sequence experiment
  49.     set flush_keyboard "yes"
  50.     set description "Runs a number of items in sequence"
  51.     run read_point_files "always"
  52.     run practice "always"
  53.  
  54. define sketchpad p_trial_display
  55.     set duration "0"
  56.     set description "Displays stimuli"
  57.     draw textline -180 0 "[shape1]" center=1 color=black font_family="sans" font_size=40 font_italic=no font_bold=no show_if="always" html="yes"
  58.     draw textline 180 0 "[shape2]" center=1 color=black font_family="sans" font_size=40 font_italic=no font_bold=no show_if="always" html="yes"
  59.     draw rect -480 -160 960 320 fill=0 penwidth=3 color=black show_if="always"
  60.  
  61. define sequence practice_sequence
  62.     set flush_keyboard "yes"
  63.     set description "Runs a number of items in sequence"
  64.     run ongoing_task "always"
  65.     run p_block_loop "always"
  66.  
  67. define inline_script ongoing_task
  68.     set _run ""
  69.     ___prepare__
  70.     # For both images, shuffle points:
  71.    
  72.     import random
  73.     image1 = random.shuffle(image1_points)
  74.     image2 = random.shuffle(image2_points)
  75.    
  76.     # Make lists global for future use
  77.     global image1, image2
  78.     __end__
  79.     set description "Executes Python code"
  80.  
  81. define sequence p_trial_sequence
  82.     set flush_keyboard "yes"
  83.     set description "Runs a number of items in sequence"
  84.     run ongoing_script "always"
  85.     run p_trial_display "always"
  86.  
  87. define inline_script ongoing_script
  88.     set _run ""
  89.     ___prepare__
  90.     # Create the shape generating script:
  91.    
  92.     # First, define a list of numerical values representing an 'n' sided-shape
  93.     n = [12,8,6,4,3]
  94.    
  95.     # Then, we need a random value from 'n' for every shape presented:
  96.     #(code found in cogsci.nl thread http://forum.cogsci.nl/index.php?p=/
  97.     # discussion/325/solved-question-randomization-on-one-page-using-forms/p1)
  98.     random.shuffle(n) # Shuffle the list order
  99.     while len(n) > 0: # While the list is not empty
  100.         nss = n.pop() # 'Pop' the first item
  101.    
  102.     # Import the built-in OS function 'canvas':
  103.     from openexp .canvas import canvas
  104.     p_trial_display = canvas(exp)
  105.    
  106.     # ...  each group of 'image points' totals 24 points, so divide by value of 'nss'
  107.     # and take a random sample to generate various randomly presented 3, 4, 6, 8 and 12
  108.     # sided shapes:
  109.     shape_1 = random.sample(image1, len(image1)/nss)
  110.     shape_2 = random.sample(image2, len(image2)/nss)
  111.     # Use variables 'shape1' and 'shape2' with the polygon function:
  112.     shape1 = p_trial_display.polygon(shape_1)
  113.     shape2 = p_trial_display.polygon(shape_2)
  114.    
  115.     # Set variables using built-in OS function exp.set, to make variables
  116.     # available in GUI (i.e. sketchpad item):
  117.     exp.set('shape1', shape1)
  118.     exp.set('shape2', shape2)
  119.     __end__
  120.     set description "Executes Python code"
  121.  
  122. define inline_script read_point_files
  123.     set _run ""
  124.     ___prepare__
  125.     # Read the coordinate points from the two .txt files.
  126.    
  127.     # Specify the path to the files by using the built-in OpenSesame function exp.get_file.
  128.     path_image1_points = exp.get_file('image1_points.txt')
  129.     path_image2_points = exp.get_file('image2_points.txt')
  130.    
  131.     # Use the built-in Python module numpy to read the .txt files:
  132.     # Import the module
  133.     import numpy as np
  134.    
  135.     # And load the text file, with value set to 'integer':
  136.     image1_points = np.loadtxt(path_image1_points, dtype=int)
  137.     image2_points = np.loadtxt(path_image2_points, dtype=int)
  138.    
  139.     # Make the files global for future use:
  140.     global image1_points, image2_points
  141.     __end__
  142.     set description "Executes Python code"
RAW Paste Data