smathot

Oriented patch stimulus

Oct 31st, 2012
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. from psychopy import visual
  2. import numpy as np
  3. import random
  4.  
  5. size = 128 # Size of the patch
  6. ori = 45 # Orientation of the patch
  7. # The minimum and maximum number of consecutive pixels of the same colour. Higher
  8. # values give a more pronounced orientation
  9. minD = 1
  10. maxD = 8
  11.  
  12. # Create a texture, which is a 2D size*size numpy array
  13. tex = np.empty( [size, size] )
  14.  
  15. # Create a view onto this array, which is just a long 1D array
  16. a = tex.view()
  17. a.shape = size**2
  18.  
  19. # Fill the view with random values. Crucially, do not fill random values one pixel
  20. # at a time, but fill a stroke of pixels to get the oriented effect
  21. i = 0
  22. while i < size**2:
  23.     val = random.random()*2-1 # Random colour value (-1 = black, 1 = white)
  24.     j = i + random.randint(minD, maxD) # Random range of pixels
  25.     a[i:j] = val # Fill it!
  26.     i = j # Advance pointer
  27.    
  28. # Create the GratingStim and show it. For old versions of PsychoPy, you need to
  29. # use PatchStim() instead.
  30. # See http://www.psychopy.org/api/visual/gratingstim.html
  31. p = visual.GratingStim(win, tex=tex, mask='circle', ori=ori, size=size)
  32. p.draw()
  33. win.flip()
Advertisement
Add Comment
Please, Sign In to add comment