Advertisement
smathot

Untitled

Dec 20th, 2012
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 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. fixPos = -200, 0
  18. fixColor = [1, 1, 1, 1] # Red, Green, Blue, Transparency
  19.  
  20. w = res[0] / nX
  21. h = res[0] / nY
  22. dx = w/2
  23. dy = h/2
  24.  
  25. x = np.linspace(0, 4*np.pi, 256) # Create a linspace as input for sin
  26. tex = np.cos([x]) # A sine between 1 and -1
  27. tex = tex * brightness - (1-brightness) # Adjust the texture brightness
  28.  
  29. myWin = visual.Window(res, units='pix', color=(-1+brightness))
  30. bgStim = visual.GratingStim(myWin, size=(w,h), tex=tex, mask='gauss', ori=bgOri)
  31. targetStim = visual.GratingStim(myWin, size=(w,h), tex=tex, mask='gauss', ori= \
  32.     targetOri)
  33. distStim = visual.GratingStim(myWin, size=(w,h), tex=tex, mask='gauss', ori= \
  34.     distOri)
  35.  
  36. for i in range(nX):
  37.     for j in range(nY):
  38.         x = (w*i + dx) - res[0]/2
  39.         y = res[1]/2 - (h*j + dy)
  40.         if i in targetPos[0] and j in targetPos[1]:
  41.             print 'Target at %d, %d / %d, %d' % (i, j, x, y)
  42.             patch = targetStim
  43.         elif i in distPos[0] and j in distPos[1]:
  44.             print 'Distractor at %d, %d / %d, %d' % (i, j, x, y)
  45.             patch = distStim
  46.         else:
  47.             patch = bgStim
  48.         patch.setPos( (x, y) )
  49.         patch.draw()
  50.  
  51. # Draw the fixation point
  52. # We use a 16x16 texture with 4 colors (R,G,B,A=transparency) per pixel
  53. tex = np.empty( (16,16, 4) )
  54. tex[:] = [-1,-1,-1,-1] # First make the entire patch transparent
  55. tex[:,7:9] = fixColor # Give one slice of the patch a color
  56. tex[7:9,:] = fixColor # Give another slice a color
  57. fix = visual.GratingStim(myWin, tex=tex, size=16, pos=fixPos) # Use the texture to create a patch
  58. fix.draw() # Draw!
  59.  
  60. # Show the screen
  61. myWin.flip()
  62.  
  63. # Save the image to disk
  64. myWin.getMovieFrame()
  65. myWin.movieFrames[0].save(imgPath)
  66.  
  67. print 'Done!'
  68. raw_input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement