In this section, you will find some hints and examples about OpenSesame.
For more information, please visit the website: https://osdoc.cogsci.nl/
All the following examples are created under OpenSesame 3.2.8 (Windows 10, 64bits)
#1 - Random Dots Kinematogram (RDK)
# import library
import random
from random import randint
# create the canvas
canvas = Canvas()
# determine the x and y limits of the screen (depends the resolution you set)
xMin = exp.get('width')/-2
xMax = exp.get('width')/2
yMin = exp.get('height')/-2
yMax = exp.get('height')/2
# choose the number of points (here, a random number between 50 and 100)
nbMin = 50
nbMax = 100
nbPoints = randint(nbMin, nbMax)
# for each number, add a random x and y position
for i in range(0, nbPoints):
xPos = randint(xMin, xMax)
yPos = randint(yMin, yMax)
canvas.fixdot(x=xPos, y=yPos, style=u'medium-filled')
# display the canvas for 1000ms
canvas.show()
self.sleep(1000)
#2 - Draw and save (x, y, time)
# create the canvas
canvas = Canvas()
# create the mouse and keep it visible
mouse = Mouse()
mouse.show_cursor(show=True)
# display the title
title = 'HOUSE'
canvas.text(title, y=(exp.get('height')/-2)+100, font_size=24)
canvas.show()
# Create an empty variable
dataDrawing = 'xPos, yPos, Time,\n'
# infinite loop (press left click to draw and rigth click to quite)
while True:
c1, c2, c3 = mouse.get_pressed()
if c1==1:
(xMouse, yMouse), timestamp = mouse.get_pos()
dataDrawing = dataDrawing + str(xMouse) + ',' + str(yMouse) + ',' + str(timestamp) + ',\n'
canvas.text('.', x=xMouse, y=yMouse)
canvas.show()
if c3==1:
break
# save the data (x, y, and time) of the drawing
log.open(u'[insert the pathway here]/dataDrawing.csv')
log.write(dataDrawing)
log.close()
#3 - Rod-and-Frame (Field dependance)
# before running the script, add an image 'bar.png' (created on Paint for example) into the pool folder
# create the canvas
canvas = Canvas()
valRotation = 0
canvas.image(exp.pool[u'bar.png'], rotation=valRotation)
canvas.show()
# create the keyboard
keyboard = Keyboard()
# infinite looop (stop pressing 'space' key)
while True:
# get the key (and time)
response, timestamp = keyboard.get_key()
if response=='+':
valRotation = valRotation + 1
canvas.clear()
canvas.image(exp.pool[u'bar.png'], rotation=valRotation)
canvas.show()
if response=='-':
valRotation = valRotation - 1
canvas.clear()
canvas.image(exp.pool[u'bar.png'], rotation=valRotation)
canvas.show()
if response=='space':
break
#4 - Reproduction of a duration
# create canvas
canvas = Canvas()
# create keyboard
keyboard = Keyboard()
# display an object with a certain duration
canvas.text('Step 1 : evaluate the presentation duration of the circle', y = -300)
canvas.circle(0, 0, 100, fill=True)
valDuration = 1000
canvas.show()
self.sleep(valDuration)
# reproduce the keyboard
canvas.clear()
canvas.text('Step 2 : reproduce the duration pressing the spacebar', y = -300)
canvas.show()
key, timestamp1 = keyboard.get_key()
key, timestamp2 = keyboard.get_key_release()
releaseTime = timestamp2 - timestamp1
# display the result
canvas.clear()
canvas.text('Time presented: ' + str(valDuration) + 'ms', y = -300)
canvas.text('Time evaluated: ' + str(releaseTime) + 'ms', y = -200)
canvas.show()
self.sleep(2000)
#5 - Randomize word order in a sentence
# import library
import random
from random import shuffle
# create canvas
canvas = Canvas()
# create keyboard
keyboard = Keyboard()
# create a sentence
Sentence = 'this is an example of a sentence displayed with OpenSesame'
# transposing order word the
words = Sentence.split(' ')
shuffle(words)
transposedWordSentence = ' '.join(words)
# display the sentences
while True:
canvas.text('Original : ' + Sentence, y = -100)
canvas.text('Modified : ' + transposedWordSentence)
canvas.show()
key, timestamp = keyboard.get_key()
if key == 'space':
break
#6- Numbers comparison
# import library
import random
from random import randint
# create canvas
canvas = Canvas()
# create keyboard
keyboard = Keyboard()
# random number
number1 = randint(0,10)
number2 = randint(0,10)
while number2 == number1:
number2 = randint(0,10)
if number2 > number1:
goodResponse = 'right'
else:
goodResponse = 'left'
# display the sentences
canvas.text(number1, x = -100, font_size=60)
canvas.text(number2, x = 100, font_size=60)
canvas.show()
# select a response: clik on the right arrow if the right number is bigger
# or the left arrow if the left number is bigger
while True:
key, timestamp = keyboard.get_key()
if key == goodResponse:
canvas.clear()
canvas.text('Good response!', font_size=60)
canvas.show()
self.sleep(500)
break
else:
canvas.clear()
canvas.text('Bad response!', font_size=60)
canvas.show()
self.sleep(500)
break
#7- Find a target in a distractors' matrix
# import library
import random
from random import shuffle
# create canvas
canvas = Canvas()
# create mouse and set it visible
mouse = Mouse()
mouse.show_cursor(show=True)
# create a list o 81 identical 'L'
listItem = list(80 * 'L' + 'T')
shuffle(listItem)
index = 0
# create a matrix of dots
for i in range(-120,150,30):
for j in range(-120,150,30):
canvas.text(listItem[index], x = i, y = j)
if listItem[index] == 'T':
xTarget = i
yTarget = j
index = index +1
canvas.show()
# select the response
while True:
c1, c2, c3 = mouse.get_pressed()
(x, y), timestamp = mouse.get_pos()
if c1 == 1:
if (xTarget-20) < x < (xTarget+20) and (yTarget-20) < y < (yTarget+20):
canvas.text('GOOD !', y=-300)
canvas.text('T', x=xTarget, y=yTarget, color='green')
canvas.show()
self.sleep(2000)
break
else:
canvas.text('WRONG !', y=-300)
canvas.text('T', x=xTarget, y=yTarget, color='red')
canvas.show()
self.sleep(2000)
break
#8- Stroop effect
# import library
import random
from random import shuffle
# create the canvas
canvas = Canvas()
# keyboard
keyboard = Keyboard()
# create a liste of colors
color1 = ['red', 'blue', 'yellow', 'orange', 'green']
shuffle(color1)
color2 = ['red', 'blue', 'yellow', 'orange', 'green']
shuffle(color2)
for i in range(1,len(color1)):
canvas.text(color1[i], color=color2[i], font_size=60)
canvas.show()
key, timestamp = keyboard.get_key()
if key == 'space':
i = i +1
canvas.clear()
#9- Masked priming
# create the canvas
canvas = Canvas()
# keyboard
keyboard = Keyboard()
# create a liste of colors
prime = ['prime 1', 'prime 2', 'prime 3', 'prime 4']
target = ['target 1', 'target 2', 'target 3', 'target 4']
# create the masks
mask = ['0'] * len(prime)
for j in range(0, len(prime)):
mask[j] = '#' * len(prime[j])
# display the stimuli
for i in range(1,len(prime)):
# display the prime for 200ms
canvas.text(prime[i], font_size=60)
canvas.show()
self.sleep(200)
# display the mask for 200ms
canvas.clear()
canvas.text(mask[i], font_size=80)
canvas.show()
self.sleep(200)
# display the target until response
canvas.clear()
canvas.text(target[i], font_size=60)
canvas.show()
key, timestamp = keyboard.get_key()
if key == 'space':
i = i +1
canvas.clear()