smathot

Untitled

Dec 18th, 2012
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. #!/usr/bin/env python
  2. from psychopy import core, visual, event
  3. import numpy as np
  4.  
  5. # Main constants
  6.  
  7. brightness = .3 # brightness between 0 and 1
  8. res = 1280, 960
  9. nX = 44
  10. nY = 33
  11. bgOri = 0
  12. targetOri = 45
  13. distOri = 90
  14. targetPos = range(33, 35), range(5, 15)
  15. distPos = range(23, 24), range(2, 20)
  16. imgPath = 'myStimulus.png'
  17.  
  18. w = res[0] / nX
  19. h = res[0] / nY
  20. dx = w/2
  21. dy = h/2
  22.  
  23. x = np.linspace(0, 4*np.pi, 256) # Create a linspace as input for sin
  24. tex = np.cos([x]) # A sine between 1 and -1
  25. tex = tex * brightness - (1-brightness) # Adjust the texture brightness
  26.  
  27. myWin = visual.Window(res, units='pix', color=(-1+brightness))
  28. bgStim = visual.GratingStim(myWin, size=(w,h), tex=tex, mask='gauss', ori=bgOri)
  29. targetStim = visual.GratingStim(myWin, size=(w,h), tex=tex, mask='gauss', ori= \
  30.     targetOri)
  31. distStim = visual.GratingStim(myWin, size=(w,h), tex=tex, mask='gauss', ori= \
  32.     distOri)
  33.  
  34. for i in range(nX):
  35.     for j in range(nY):
  36.         x = (w*i + dx) - res[0]/2
  37.         y = res[1]/2 - (h*j + dy)
  38.         if i in targetPos[0] and j in targetPos[1]:
  39.             print 'Target at %d, %d / %d, %d' % (i, j, x, y)
  40.             patch = targetStim
  41.         elif i in distPos[0] and j in distPos[1]:
  42.             print 'Distractor at %d, %d / %d, %d' % (i, j, x, y)
  43.             patch = distStim
  44.         else:
  45.             patch = bgStim
  46.         patch.setPos( (x, y) )
  47.         patch.draw()
  48.  
  49. # Show the screen
  50. myWin.flip()
  51.  
  52. # Save the image to disk
  53. myWin.getMovieFrame()
  54. myWin.movieFrames[0].save(imgPath)
  55.  
  56. print 'Done!'
  57. raw_input()
Advertisement
Add Comment
Please, Sign In to add comment