Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import psychopy
from math import sin, pi
#create a window to draw in
myWin = psychopy.visual.Window((800,600),fullscr=0, winType="pygame",
bitsMode='fast', rgb=-0, gamma=1.0)
grating1 = psychopy.visual.PatchStim(myWin,tex="sin",mask="circle",texRes=128,
rgb=[1.0,1.0,1.0],opacity=1.0,
size=(1.0,1.0), sf=(4.0,2.0),
ori = 45, contrast=0.99)
fpsDisplay = psychopy.visual.TextStim(myWin,pos=(-0.95,-0.95),text='fps...')
trialClock = psychopy.Clock()
timer = psychopy.Clock()
t = lastFPSupdate = 0
while t<20:#quits after 20 secs
t=trialClock.getTime()
#grating1.draw() #redraw it
myWin.update() #update the screen
for keys in psychopy.event.getKeys():
if keys in ['escape','q']:
# get 'shortcut' handles to the devices you will be using in the experiment:
myMouse=io.devices.mouse
display=io.devices.display
myKeyboard=io.devices.keyboard
#create a 'fullscreen' window to draw in
screen_resolution=display.getStimulusScreenResolution()
monitor= monitors.Monitor("expMonitor", width=490,distance=500)
monitor.setSizePix(screen_resolution)
myWin = visual.Window(screen_resolution, allowGUI=False, fullscr=True,monitor=monitor)
#INITIALISE SOME STIMULI
fixSpot = visual.PatchStim(myWin,tex="none", mask="gauss",
pos=(0,0), size=(0.05,0.05),color='black', autoLog=False)
grating = visual.PatchStim(myWin,pos=(0.5,0),
tex="sin",mask="gauss",
color=[1.0,0.5,-1.0],
size=(1.0,1.0), sf=(3,0),
autoLog=False)#this stim changes too much for autologging to be useful
message = visual.TextStim(myWin,pos=(-0.95,-0.9),alignHoriz='left',height=0.08,
text='left-drag=SF, right-drag=pos, scroll=ori',
autoLog=False)
last_wheelPosY=0
while True: #continue until keypress
#handle key presses each frame
for event in myKeyboard.getEvents(EventConstants.KEYBOARD_PRESS):
if event.key in ['ESCAPE','q']:
io.quit()
pygame.joystick.init()#initialise the module
if event.joystick.get_count()>0:
myJoystick = pygame.joystick.Joystick(0)
myJoystick.init()#initialise the device
print 'found ', myJoystick.get_name(), ' with:'
print '...', myJoystick.get_numbuttons(), ' buttons'
print '...', myJoystick.get_numhats(), ' hats'
print '...', myJoystick.get_numaxes(), ' analogue axes'
else:
print "You don't have a joystick connected!?"
myWin.close()
core.quit()
#INITIALISE SOME STIMULI
fixSpot = visual.PatchStim(myWin,tex="none", mask="gauss",pos=(0,0), size=(0.05,0.05),color='black')
grating = visual.PatchStim(myWin,pos=(0.5,0),
tex="sin",mask="gauss",
color=[1.0,0.5,-1.0],
size=(0.2,.2), sf=(2,0))
message = visual.TextStim(myWin,pos=(-0.95,-0.95),text='Hit Q to quit')
trialClock = Clock()
t = 0
while 1:#quits after 20 secs
#handle events first
pygame.event.pump()#refresh the event loop
if myJoystick.get_button(0):
myWin.close()
core.quit()
misc.toFile('lastParams.pickle', expInfo)#save params to file for next time
else:
core.quit()#the user hit cancel so exit
#make a text file to save data
fileName = expInfo['observer'] + dateStr
dataFile = open(fileName+'.txt', 'w')
dataFile.write('targetSide oriIncrement correct\n')
#create window and stimuli
globalClock = core.Clock()#to keep track of time
trialClock = core.Clock()#to keep track of time
win = visual.Window([800,600],allowGUI=False, monitor='testMonitor', units='deg')
foil = visual.PatchStim(win, sf=1, size=4, mask='gauss', ori=expInfo['refOrientation'])
target = visual.PatchStim(win, sf=1, size=4, mask='gauss', ori=expInfo['refOrientation'])
fixation = visual.PatchStim(win, color='black', tex=None, mask='circle',size=0.2)
message1 = visual.TextStim(win, pos=[0,+3],text='Hit a key when ready.')
message2 = visual.TextStim(win, pos=[0,-3], text="Then press left or right to identify the %.1fdegree probe." %(expInfo['refOrientation']))
#create the staircase handler
staircase = data.StairHandler(startVal = 20.0,
stepType = 'lin', stepSizes=[8,4,4,2,2,1,1], #reduce step size every two reversals
minVal=0, maxVal=90,
nUp=1, nDown=3, #will home in on the 80% threshold
nTrials=50)
#display instructions and wait
message1.draw()
message2.draw()
fixation.draw()
win.flip()
#check for a keypress
))
center = visual.Circle(
self.win,
name = 'center',
fillColor = color,
lineColor = None,
radius = r2,
)
fixation = GroupStim(stimuli=oval + [center],
name='fixation')
fixation.color = color
self.fixation = fixation
elif shape == 'dot':
self.fixation = GroupStim(
stimuli=visual.PatchStim(
self.win,
name = 'fixation',
color = 'red',
tex = None,
mask = 'circle',
size = size,
),
name='fixation')
fullscr=True,
allowGUI=False,
screen=screen_index)
# Hide the 'system mouse cursor'
mouse.setSystemCursorVisibility(False)
gamepad.updateBatteryInformation()
bat=gamepad.getLastReadBatteryInfo()
print "Battery Info: ",bat
gamepad.updateCapabilitiesInformation()
caps=gamepad.getLastReadCapabilitiesInfo()
print "Capabilities: ",caps
fixSpot = visual.PatchStim(myWin,tex="none", mask="gauss",pos=(0,0),
size=(30,30),color='black')
grating = visual.PatchStim(myWin,pos=(0,0),
tex="sin",mask="gauss",
color='white',
size=(200,200), sf=(2,0))
message = visual.TextStim(myWin,pos=(0,-300),text='Hit "r" key to Rumble; Hit "q" to quit')
END_DEMO=False
while not END_DEMO:
#update stim from joystick
x,y,mag=gamepad.getThumbSticks()['RightStick'] # sticks are 3 item lists (x,y,magnitude)
xx=self.normalizedValue2Pixel(x*mag,screen_resolution[0], -1)
yy=self.normalizedValue2Pixel(y*mag,screen_resolution[1], -1)
# Hide the 'system mouse cursor'
mouse.setSystemCursorVisibility(False)
gamepad.updateBatteryInformation()
bat=gamepad.getLastReadBatteryInfo()
print "Battery Info: ",bat
gamepad.updateCapabilitiesInformation()
caps=gamepad.getLastReadCapabilitiesInfo()
print "Capabilities: ",caps
unit_type = display.getCoordinateType()
fixSpot = visual.PatchStim(myWin,tex="none", mask="gauss",pos=(0,0),
size=(30,30),color='black',units=unit_type)
grating = visual.PatchStim(myWin,pos=(0,0), tex="sin",mask="gauss",
color='white',size=(200,200), sf=(0.01,0),units=unit_type)
screen_resolution= display.getPixelResolution()
msgText='Left Stick = Spot Pos; Right Stick = Grating Pos;\nLeft Trig = SF; Right Trig = Ori;\n"r" key = Rumble; "q" = Quit\n'
message = visual.TextStim(myWin,pos=(0,-200),
text=msgText,units=unit_type,
alignHoriz='center',alignVert='center',height=24,
wrapWidth=screen_resolution[0]*.9)
END_DEMO=False
while not END_DEMO:
#update stim from joystick
#
# Otherwise the settings provided for the iohub Display device are used and the psychopy
# monitor config is updated with these display settings and eye to monitor distance.
psychoWindow = FullScreenWindow(display)
# Hide the 'system mouse cursor' so we can display a cool gaussian mask for a mouse cursor.
mouse.setSystemCursorVisibility(False)
# Currently each stimulus created needs to have the Display's corrdinate type
# bassed to it explicitedly. (This will be fixed in a future release). The default
# coordinate type is 'pix', you can change this to one of the following supported
# corrdinate types by specifying the type you want to use in the Display config dict
# passed to launchHubServer.
coord_type=display.getCoordinateType()
grating = visual.PatchStim(psychoWindow, mask="circle",units=coord_type,
size=150,pos=[0,0], sf=.075)
# To add an entry to the psychopy log file you created, and **not** have it also
# sent to the ioHub and stored in the ioDataStore, then just use the psychopy
# logging module as normal, and as described in the psychopy documentation.
# i.e.
logging.log("Visual Stim Resources Created.",'DEBUG',Computer.currentSec())
# or
logging.debug("Visual Stim Resources Created take 2.",Computer.currentSec())
# or
logging.log("Visual Stim Resources Created take 3.",'DEBUG')
# To use the ioHub-PsychoPy logging integration then instead of using the logging
# module of psychopy to create log entries, use the ioHub experiment object
# that was turned into a local variable above by using:
#
#! /usr/local/bin/python2.5
from psychopy import visual
#copy pixels from the frame buffer
myWin = visual.Window([200,200])
myStim = visual.PatchStim(myWin, pos=[-0.5,-0.5],size=1, sf=5,rgb=[0,1,1],ori=30, mask='gauss')
n=10
for frameN in range(n): #for n frames
myStim.setPhase(0.1, '+')
myStim.draw()
#you can either read from the back buffer BEFORE win.flip() or
#from the front buffer just AFTER the flip. The former has the
#advantage that it won't be affected by other windows whereas
#latter can be.
myWin.getMovieFrame(buffer='back')
myWin.flip()
#save the movie in the format of your choice
#myWin.saveMovieFrames('frame.jpg')
#myWin.saveMovieFrames('myMovie.gif')
myWin.saveMovieFrames('myMovie.mpg')
# Create a psychopy window, using settings from Display device config
psychoWindow = FullScreenWindow(display)#,res=(500,500),fullscr=False,allowGUI=True)
# Hide the 'system mouse cursor' so we can display a cool gaussian mask for a mouse cursor.
#mouse.setSystemCursorVisibility(False)
# Set the mouse position to 0,0, which means the 'center' of the screen.
mouse.setPosition((0.0,0.0))
# Read the current mouse position (should be 0,0) ;)
currentPosition=mouse.getPosition()
mouse.lockMouseToDisplayID(display.getIndex())
# Create an ordered dictionary of psychopy stimuli. An ordered dictionary is one that returns keys in the order
# they are added, you you can use it to reference stim by a name or by 'zorder'
psychoStim=OrderedDict()
psychoStim['grating'] = visual.PatchStim(psychoWindow, mask="circle", size=75,pos=[-100,0], sf=.075)
psychoStim['fixation'] =visual.PatchStim(psychoWindow, size=25, pos=[0,0], sf=0, color=[-1,-1,-1], colorSpace='rgb')
psychoStim['keytext'] = visual.TextStim(psychoWindow, text=u'?', pos = [100,200], height=48, color=[-1,-1,-1], colorSpace='rgb',alignHoriz='center',alignVert='center',wrapWidth=400.0)
psychoStim['ucodetext'] = visual.TextStim(psychoWindow, text=u'?', pos = [-100,200], height=48, color=[-1,-1,-1], colorSpace='rgb',alignHoriz='center',alignVert='center',wrapWidth=400.0)
psychoStim['mods'] = visual.TextStim(psychoWindow, text=u'?', pos = [0,-200], height=48, color=[-1,-1,-1], colorSpace='rgb',alignHoriz='center',alignVert='center',wrapWidth=400.0)
psychoStim['mouseDot'] =visual.GratingStim(psychoWindow,tex=None, mask="gauss", pos=currentPosition,size=(50,50),color='purple')
# Clear all events from the global and device level event buffers.
self.hub.clearEvents('all')
QUIT_EXP=False
# Loop until we get a keyboard event with the space, Enter (Return), or Escape key is pressed.
while QUIT_EXP is False:
# for each loop, update the grating phase
psychoStim['grating'].setPhase(0.05, '+')#advance phase by 0.05 of a cycle
# and update the mouse contingent gaussian based on the current mouse location