How to repeat a missed trial using the canvas-keyboard plugin? #1654
-
Hi All, var fix = {
type: 'canvas-keyboard-response', stimulus: fixation, trial_duration: fix_dura, choices: jsPsych.NO_KEYS, data: { condition: 'fixation'},
};
var r1_70 = [37,37,39,37,37,39,37,37,37,39];
var r1_90 = [37,37,37,37,39,37,37,37,37,37];
var r2_70 = [39,39,37,39,39,37,39,39,39,37];
var r2_90 = [39,39,39,39,37,39,39,39,39,39];
var s1_r2_low60 = {
type: 'canvas-keyboard-response',
on_start: function(s1_r2_low60){
s1_r2_low60.random_r2_70 = Math.floor(Math.random() * r2_70.length);
s1_r2_low60.reward_r2_70 = r2_70[jsPsych.currentTrial().random_r2_70]
s1_r2_low60.contrast = randbet(0.8,1);
s1_r2_low60.contrast1 = jsPsych.currentTrial().contrast - randbet(0.6,0.8);
},
stimulus: gabor, //function that draws on the canvas
data: {condition: 'LH', state: '1', reward: '2', prob: '30_70'},
choices: keys, trial_duration: duration, response_ends_trial: false,
on_finish: function (data) {
if (data.key_press === jsPsych.currentTrial().reward_r2_70) {
data.correct = true;
} else {
data.correct = false;
}
data.corr_resp = jsPsych.currentTrial().reward_r2_70
data.con = jsPsych.currentTrial().contrast
data.con1 = jsPsych.currentTrial().contrast1
},
};
var fb = {
type: 'html-keyboard-response', choices: jsPsych.NO_KEYS, trial_duration: duration,
stimulus: function () {
var last_trial_correct = jsPsych.data.get().last(1).values()[0].correct;
if (last_trial_correct) {
return "<p style=\"font-size: 30px;color: #016901\">You win 1 point!</p>";
} else {
return "<p style=\"font-size: 30px;color: #ba0000\">You win 0 points!</p>";
}
}
};
// Two functions used to draw on the canvas.
function fixation(c) { //generates fixation by drawing on HTML canvas.
var context = c.getContext("2d"); //Name of the canvas
context.moveTo(240, 250); //start of horizontal line
context.lineTo(280, 250); //end of horizontal line
context.moveTo(260, 230); //start of vertical line
context.lineTo(260, 270); //end of vertical line
context.filter = 'contrast(1)'; //keeps the contrast constant
context.lineWidth = 3;
context.stroke();
};
function gabor(c) { //generates 2 gabors left and right to the fixation
var context = c.getContext("2d");
const my_gradient = context.createLinearGradient(0,0,200,0); const my_gradient1 = context.createLinearGradient(225,0,425,0); //two gradients for two gabors
const bands = 10; const colors = ["#000", "#FFF"];
const stops = bands * colors.length; //number of layers that you want to color in the patch
var pos = 0; var pos1 = 0;
while (pos <= stops) { //colors each band of the patch with white and black.
my_gradient1.addColorStop(pos / stops, colors[pos % colors.length]);
pos++;
}
while (pos1 <= stops) {
my_gradient.addColorStop(pos1 / stops, colors[pos1 % colors.length]);
pos1++;
}
context.fillStyle = my_gradient; //gradients for left and right Gabor
context.filter = 'contrast('+ jsPsych.currentTrial().contrast +')' //contrast level randomly generated after every trial
context.fillRect(100,200,100,100);
context.fillStyle = my_gradient1;
context.filter = 'contrast('+ jsPsych.currentTrial().contrast1+')'
context.fillRect(325,200,100,100);
context.stroke()
context.moveTo(240, 250); context.lineTo(280, 250); //horizontal line
context.moveTo(260, 230); context.lineTo(260, 270); //vertical line
context.filter = 'contrast(1)'; context.lineWidth = 3;
context.stroke();
} Any suggestions will be really helpful. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hi @prashantig25, When you say miss a particular trial, does that mean if the subject answers incorrectly? Have you thought about using a looping timeline to repeat the trial if it is incorrect? |
Beta Was this translation helpful? Give feedback.
-
It turns out @becky-gilbert answered a similar question in the old jsPsych google group forum. The context is a little different, but the same strategy should apply. Here's the key bit from her answer:
|
Beta Was this translation helpful? Give feedback.
It turns out @becky-gilbert answered a similar question in the old jsPsych google group forum.
The context is a little different, but the same strategy should apply. Here's the key bit from her answer: