I managed to adapt the task.
It is not very fancy, but it works. I dont know whether it translates well to JS. I defined fixed postions on the screen for every block, and then calculated a random jitter. Then added it to each postion manually, and randomized the postions in the list, to make it look like block were preseneted in a radom order. The rest of the task is as on Pavlovia.
In the —Prepare to start Routine “trial”— part of the code I added the following:
Note that I have 9 blocks.
blocks = {}
blocks['blk1']=blk1
blocks['blk2']=blk2
blocks['blk3']=blk3
blocks['blk4']=blk4
blocks['blk5']=blk5
blocks['blk6']=blk6
blocks['blk7']=blk7
blocks['blk8']=blk8
blocks['blk9']=blk9
locations on the screen
locations = [(-.52, 0.3), (-.52, 0.03), (-.52, -0.25), (0.04, 0.3), (0.04, 0.03),(0.04,-.25), (0.47, 0.3), (0.47, 0.03), (0.47, -0.25)]
create jitter
jitter = [np.random.uniform(-0.1, 0.1) for x in range(18)]
manually ad jitter to lacations
locations_1 = [
[locations[0][0] + jitter[0],
locations[0][1] + jitter[1]],
[locations[1][0] + jitter[2],
locations[1][1] + jitter[3]],
[locations[2][0] + jitter[4],
locations[2][1] + jitter[5]],
[locations[3][0] + jitter[6],
locations[3][1] + jitter[7]],
[locations[4][0] + jitter[8],
locations[4][1] + jitter[9]],
[locations[5][0] + jitter[10],
locations[5][1] + jitter[11]],
[locations[6][0] + jitter[12],
locations[6][1] + jitter[13]],
[locations[7][0] + jitter[14],
locations[7][1] + jitter[15]],
[locations[8][0] + jitter[16],
locations[8][1] + jitter[17]]]
Shuffle locations in list
np.random.shuffle(locations_1)
set counter to 0
i = 0
#give blocks a new set of random locations
for label, block in blocks.items():
block.pos = locations_1[i]
i = i + 1 #add to counter to itterate through list
block.color = 'white'
Also you probably need to add some libraries to the skript. These are the ones I used for the corsi task. some were there by default, others I added but not sure which. I believe to remember that the “numpy.random” was missing and the “numpy as np” to call on the numpy lib.
from psychopy import locale_setup
from psychopy import prefs
from psychopy import sound, gui, visual, core, data, event, logging, clock
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)
import numpy as np # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle
import os # handy system and path functions
import sys # to get file system encoding
from psychopy.hardware import keyboard
Hope this is helpfull enough, otherwise let me know!
Helene