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
- Copy assignment 2.
- Look up the API documentation: http://www.psychopy.org/api/api.html. Select the psychopy.visual module. It contains the TextStim object and most of the other stimuli used in this course. Try several of its optional arguments. Look up what the PsychoPy TextStim object can do. Make it fancy.
- Find an object that is suitable for showing an image from a jpg-file and show it together with the fancy text stimulus.
Continue with the next lesson