Programming with PsychoPy, 4 PsychoPy functions and objects
Three types of function
In assignment 3 we used a number of functions. For instance the sum() function was used to return the sum of the variables in a list and the len() function was used to return the length of the list. These functions are always available.
We already saw that most functions are not always available. Before we we could use the sine function we had to to import the math module with import math and call the sine function using math.sin(). PsychoPy has 17 such modules which you can use.
We also used a third type of function. This type of function works on an object. message.draw()for instance draws a message and win.flip() flips the window buffers. These objects are a special kind of variable, that we had to make before we could use them:
# next line makes a Window object win = visual.Window([400,300], monitor="testMonitor") # next line makes a TextStim object message = visual.TextStim(win, text=myText) message.draw()
Note that the special functions that return objects always have names that start with an upper case letter. (we will occasionally see an exception to this rule, but the reason behind this is beyond the scope of this course)
Look at the reference manual to see what the 17 modules do.
Assignment 4: Working with the online documentation
- Look up what the PsychoPy TextStim object can do. Try several of its optional arguments.
- Find a built-in function that is suitable for showing a image from a jpg-file and write an experiment that uses it. You can start from the code given in assignment 3.
Continue with the next lesson