Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from psychopy import core, visual, event
- import numpy as np
- # Main constants
- brightness = .3 # brightness between 0 and 1
- res = 1280, 960
- nX = 44
- nY = 33
- bgOri = 0
- targetOri = 45
- distOri = 90
- targetPos = range(33, 35), range(5, 15)
- distPos = range(23, 24), range(2, 20)
- imgPath = 'myStimulus.png'
- fixPos = -200, 0
- fixColor = [1, 1, 1, 1] # Red, Green, Blue, Transparency
- w = res[0] / nX
- h = res[0] / nY
- dx = w/2
- dy = h/2
- x = np.linspace(0, 4*np.pi, 256) # Create a linspace as input for sin
- tex = np.cos([x]) # A sine between 1 and -1
- tex = tex * brightness - (1-brightness) # Adjust the texture brightness
- myWin = visual.Window(res, units='pix', color=(-1+brightness))
- bgStim = visual.GratingStim(myWin, size=(w,h), tex=tex, mask='gauss', ori=bgOri)
- targetStim = visual.GratingStim(myWin, size=(w,h), tex=tex, mask='gauss', ori= \
- targetOri)
- distStim = visual.GratingStim(myWin, size=(w,h), tex=tex, mask='gauss', ori= \
- distOri)
- for i in range(nX):
- for j in range(nY):
- x = (w*i + dx) - res[0]/2
- y = res[1]/2 - (h*j + dy)
- if i in targetPos[0] and j in targetPos[1]:
- print 'Target at %d, %d / %d, %d' % (i, j, x, y)
- patch = targetStim
- elif i in distPos[0] and j in distPos[1]:
- print 'Distractor at %d, %d / %d, %d' % (i, j, x, y)
- patch = distStim
- else:
- patch = bgStim
- patch.setPos( (x, y) )
- patch.draw()
- # Draw the fixation point
- # We use a 16x16 texture with 4 colors (R,G,B,A=transparency) per pixel
- tex = np.empty( (16,16, 4) )
- tex[:] = [-1,-1,-1,-1] # First make the entire patch transparent
- tex[:,7:9] = fixColor # Give one slice of the patch a color
- tex[7:9,:] = fixColor # Give another slice a color
- fix = visual.GratingStim(myWin, tex=tex, size=16, pos=fixPos) # Use the texture to create a patch
- fix.draw() # Draw!
- # Show the screen
- myWin.flip()
- # Save the image to disk
- myWin.getMovieFrame()
- myWin.movieFrames[0].save(imgPath)
- print 'Done!'
- raw_input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement