Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from psychopy import visual
- import numpy as np
- import random
- size = 128 # Size of the patch
- ori = 45 # Orientation of the patch
- # The minimum and maximum number of consecutive pixels of the same colour. Higher
- # values give a more pronounced orientation
- minD = 1
- maxD = 8
- # Create a texture, which is a 2D size*size numpy array
- tex = np.empty( [size, size] )
- # Create a view onto this array, which is just a long 1D array
- a = tex.view()
- a.shape = size**2
- # Fill the view with random values. Crucially, do not fill random values one pixel
- # at a time, but fill a stroke of pixels to get the oriented effect
- i = 0
- while i < size**2:
- val = random.random()*2-1 # Random colour value (-1 = black, 1 = white)
- j = i + random.randint(minD, maxD) # Random range of pixels
- a[i:j] = val # Fill it!
- i = j # Advance pointer
- # Create the GratingStim and show it. For old versions of PsychoPy, you need to
- # use PatchStim() instead.
- # See http://www.psychopy.org/api/visual/gratingstim.html
- p = visual.GratingStim(win, tex=tex, mask='circle', ori=ori, size=size)
- p.draw()
- win.flip()
Advertisement
Add Comment
Please, Sign In to add comment