mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
Suite of bugfixes and changes related to same-different and animation plugin. Animation plugin is a complete redesign that removes dependency on the canimate.js library.
This commit is contained in:
parent
6969fbcdc9
commit
e88a1b052f
@ -1,7 +1,5 @@
|
|||||||
// jsPsych plugin for showing animations
|
// jsPsych plugin for showing animations
|
||||||
// Josh de Leeuw
|
// Josh de Leeuw
|
||||||
//
|
|
||||||
// dependency: jquery.canimate.js
|
|
||||||
|
|
||||||
function animation_create(params)
|
function animation_create(params)
|
||||||
{
|
{
|
||||||
@ -11,17 +9,9 @@ function animation_create(params)
|
|||||||
{
|
{
|
||||||
trials[i] = {};
|
trials[i] = {};
|
||||||
trials[i]["type"] = "animate";
|
trials[i]["type"] = "animate";
|
||||||
//img_path needs to be of the form:
|
trials[i]["stims"] = stims[i];
|
||||||
// "path/PREFIX####.EXT
|
trials[i]["frame_time"] = params["frame_time"];
|
||||||
//substituting whatever values you want for PREFIX and EXT
|
trials[i]["repetitions"] = params["repetitions"];
|
||||||
//and putting the correct path information
|
|
||||||
//PREFIX needs to match the img_prefix param.
|
|
||||||
trials[i]["img_path"] = stims[i];
|
|
||||||
trials[i]["img_prefix"] = params["prefix"];
|
|
||||||
trials[i]["fps"] = params["fps"];
|
|
||||||
// frames is how many images are in the animation
|
|
||||||
trials[i]["frames"] = params["frames"];
|
|
||||||
trials[i]["loop"] = params["loop"];
|
|
||||||
trials[i]["timing"] = params["timing"];
|
trials[i]["timing"] = params["timing"];
|
||||||
}
|
}
|
||||||
return trials;
|
return trials;
|
||||||
@ -29,19 +19,33 @@ function animation_create(params)
|
|||||||
|
|
||||||
function animation_trial($this, block, trial, part)
|
function animation_trial($this, block, trial, part)
|
||||||
{
|
{
|
||||||
var base_img = document.createElement('img');
|
animate_frame = -1;
|
||||||
base_img.setAttribute('src',trial.img_path);
|
reps = 0;
|
||||||
base_img.setAttribute('id','animate');
|
switch(part)
|
||||||
$this.append(base_img);
|
{
|
||||||
// using the cAnimate jQuery plugin
|
case 1:
|
||||||
$('#animate').canimate({
|
animate_interval = setInterval(function(){
|
||||||
totalFrames: trial.frames,
|
showImage = true;
|
||||||
imagePrefix: trial.img_prefix,
|
$('.animate').remove();
|
||||||
fps: trial.fps,
|
animate_frame++;
|
||||||
preload:true,
|
if(animate_frame == trial.stims.length)
|
||||||
loop: trials.loop
|
{
|
||||||
});
|
animate_frame = 0;
|
||||||
|
reps++;
|
||||||
setTimeout(function(b){$('#animate').remove(); b.next();}, trial.timing[0], block);
|
if(reps >= trial.repetitions)
|
||||||
|
{
|
||||||
|
animation_trial($this, block, trial, part + 1);
|
||||||
|
clearInterval(animate_interval);
|
||||||
|
showImage = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(showImage){
|
||||||
|
$.fn.jsPsych.showImage($this, trial.stims[animate_frame], 'animate');
|
||||||
|
}
|
||||||
|
}, trial.frame_time);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
setTimeout(function(b){ b.next(); }, trial.timing[0], block);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
@ -9,6 +9,13 @@ function sd_create(params)
|
|||||||
trials[i]["a_path"] = sd_stims[i][0];
|
trials[i]["a_path"] = sd_stims[i][0];
|
||||||
trials[i]["b_path"] = sd_stims[i][1];
|
trials[i]["b_path"] = sd_stims[i][1];
|
||||||
trials[i]["timing"] = params["timing"];
|
trials[i]["timing"] = params["timing"];
|
||||||
|
trials[i]["answer"] = params["answer"];
|
||||||
|
if(params["prompt"] != undefined){
|
||||||
|
trials[i]["prompt"] = params["prompt"];
|
||||||
|
}
|
||||||
|
if(params["data"]!=undefined){
|
||||||
|
trials[i]["data"] = params["data"][i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return trials;
|
return trials;
|
||||||
}
|
}
|
||||||
@ -25,27 +32,40 @@ function sd_trial($this, block, trial, part)
|
|||||||
setTimeout(sd_trial, trial.timing[1], $this, block, trial, part + 1);
|
setTimeout(sd_trial, trial.timing[1], $this, block, trial, part + 1);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
startTime = (new Date()).getTime();
|
|
||||||
$.fn.jsPsych.showImage($this, trial.b_path, 'sd');
|
$.fn.jsPsych.showImage($this, trial.b_path, 'sd');
|
||||||
|
if(trial.timing[3]!=undefined){
|
||||||
|
setTimeout(sd_trial, trial.timing[3], $this, block, trial, part + 1);
|
||||||
|
} else {
|
||||||
|
sd_trial($this, block, trial, part + 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if(trial.timing[3]!=undefined){
|
||||||
|
$('.sd').remove();
|
||||||
|
$this.html(trial.prompt);
|
||||||
|
}
|
||||||
|
startTime = (new Date()).getTime();
|
||||||
var resp_func = function(e) {
|
var resp_func = function(e) {
|
||||||
var flag = false;
|
var flag = false;
|
||||||
var correct = false;
|
var correct = false;
|
||||||
if(e.which=='80') // 'p' key -- different
|
if(e.which=='80') // 'p' key -- different
|
||||||
{
|
{
|
||||||
flag = true;
|
flag = true;
|
||||||
if(trial.a_path!=trial.b_path) { correct = true; }
|
if(trial.answer == "different") { correct = true; }
|
||||||
} else if(e.which=='81') // 'q' key -- same
|
} else if(e.which=='81') // 'q' key -- same
|
||||||
{
|
{
|
||||||
flag = true;
|
flag = true;
|
||||||
if(trial.a_path==trial.b_path){ correct = true; }
|
if(trial.answer == "same"){ correct = true; }
|
||||||
}
|
}
|
||||||
if(flag)
|
if(flag)
|
||||||
{
|
{
|
||||||
endTime = (new Date()).getTime();
|
endTime = (new Date()).getTime();
|
||||||
rt = (endTime-startTime);
|
rt = (endTime-startTime);
|
||||||
block.data[block.trial_idx] = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path}
|
var trial_data = {"rt": rt, "correct": correct, "a_path": trial.a_path, "b_path": trial.b_path, "key": e.which}
|
||||||
|
block.data[block.trial_idx] = $.extend({},trial_data,trial.data);
|
||||||
$(document).unbind('keyup',resp_func);
|
$(document).unbind('keyup',resp_func);
|
||||||
$('.sd').remove();
|
$('.sd').remove();
|
||||||
|
$this.html('');
|
||||||
setTimeout(function(b){b.next();}, trial.timing[2], block);
|
setTimeout(function(b){b.next();}, trial.timing[2], block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ function text_create(params)
|
|||||||
trials[i] = {};
|
trials[i] = {};
|
||||||
trials[i]["type"] = "text";
|
trials[i]["type"] = "text";
|
||||||
trials[i]["text"] = params.text[i];
|
trials[i]["text"] = params.text[i];
|
||||||
|
trials[i]["cont_key"] = params.cont_key;
|
||||||
trials[i]["timing"] = params.timing;
|
trials[i]["timing"] = params.timing;
|
||||||
}
|
}
|
||||||
return trials;
|
return trials;
|
||||||
@ -15,7 +16,7 @@ function text_trial($this, block, trial, part)
|
|||||||
{
|
{
|
||||||
$this.html(trial.text);
|
$this.html(trial.text);
|
||||||
var key_listener = function(e) {
|
var key_listener = function(e) {
|
||||||
if(e.which=="80") // 'spacebar'
|
if(e.which==trial.cont_key)
|
||||||
{
|
{
|
||||||
flag = true;
|
flag = true;
|
||||||
$(document).unbind('keyup',key_listener);
|
$(document).unbind('keyup',key_listener);
|
||||||
|
@ -105,11 +105,7 @@
|
|||||||
$.fn.jsPsych.defaults = {
|
$.fn.jsPsych.defaults = {
|
||||||
// overall experiment parameters
|
// overall experiment parameters
|
||||||
experiment_structure: [],
|
experiment_structure: [],
|
||||||
plugins: [
|
plugins: []
|
||||||
{"type": "sim", "createFunc": similarity_create, "trialFunc": similarity_trial},
|
|
||||||
{"type": "sd", "createFunc": sd_create, "trialFunc": sd_trial},
|
|
||||||
{"type": "text", "createFunc": text_create, "trialFunc": text_trial},
|
|
||||||
{"type": "xab", "createFunc": xab_create, "trialFunc": xab_trial}]
|
|
||||||
};
|
};
|
||||||
//
|
//
|
||||||
// useful helper functions for multiple plugins //
|
// useful helper functions for multiple plugins //
|
||||||
|
Loading…
Reference in New Issue
Block a user