Skip to content

Commit

Permalink
jsPsych.plugins.parameterType.COMPLEX is used.
Browse files Browse the repository at this point in the history
  • Loading branch information
kurokida committed Nov 1, 2019
1 parent 3903368 commit adfc5b4
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 50 deletions.
6 changes: 4 additions & 2 deletions demos/rectangles.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
height: 50,
line_color: 'black', // You can use the HTML color name instead of the HEX color.
show_start_time: 500, // ms after the start of the trial
endX: 400,
endY: 400,
// endX: 400,
// endY: 400,
endX: 'center',
endY: 'center',
motion_start_time: 1500,
motion_end_time: 3000,
}
Expand Down
2 changes: 1 addition & 1 deletion demos/twoSoundsWithSOA.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// This file demonstrates how to present sounds with 1000-ms SOA.
// This demo must be uploaded in a web-server to run.

sounds = [ // All the images used in this demo
sounds = [ // All the sound files used in this demo
'./sound/tone100ms.wav'
];

Expand Down
4 changes: 2 additions & 2 deletions docs/pluginParams.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ Only the 'stimuli' parameter is required; Other parameters can be left unspecifi

|Parameter|Type|Default Value|Description|
|---|---|---|---|
|stimuli|array|'customize'|An array of objects, each object represents a stimulus to be presented in this trial. The properties of each object are depend on the type of the object. See [the properties of the stimulus object](objectProperties.md). The default value (customize) should be used with the stepFunc which is called by the requestAnimationFrame method.|
|stimuli|array|undefined|An array of objects, each object represents a stimulus to be presented in this trial. The properties of each object are depend on the type of the object. See [the properties of the stimulus object](objectProperties.md). The stimuli is not needed when you use the stepFunc which is called by the requestAnimationFrame method.|
|canvas_width|numeric|window.innerWidth|The width of the canvas in which stimuli are drawn. If it is not specified, the width of the canvas is identical to that of the window.|
|canvas_height|numeric|window.innerHeight|The height of the canvas in which stimuli are drawn. If it is not specified, the height of the canvas is identical to that of the window.|
|background_color|string|'grey'|The background color of the canvas.The color can be specified using the HTML color names, hexadecimal (HEX) colors, and RGB values that are often used in a general HTML file. |
|response_type|string|'key'|To have a participant respond to the stimulus using a mouse instead of a keyboard, specify 'mouse'.|
|response_start_time|numeric|0|The defalut value (0) means that the participant can respond to the stimuli from the start of the trial, and the reaction time is the time from the start of the trial until the participant's response. If the response_start_time is set to 1000, the participant can respond to the stimuli 1000 ms after from the start of the trial, and the reaction time is the time from 1000 ms after the start of the trial until the participant's response.|
|stepFunc|function|null|**Advanced.** This function is called by the *requestAnimationFrame* method, and excuted synchronized with the refresh of the display. When you specify the *stepFunc*, the *stimuli* should not be specified (should be 'customize'). If you would like to draw stimuli using the canvas-drawing methods manually, the *stepFunc* would be benefit.|
|stepFunc|function|null|**Advanced.** This function is called by the *requestAnimationFrame* method, and excuted synchronized with the refresh of the display. When you specify the *stepFunc*, the *stimuli* should not be specified. If you would like to draw stimuli using the canvas-drawing methods manually, the *stepFunc* would be benefit.|
|choices|array of keycodes|jsPsych.ALL_KEYS|This array contains the keys that the participant is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](https://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g., 'a', 'q'). The default value of jsPsych.ALL_KEYS means that all keys will be accepted as valid responses. Specifying jsPsych.NO_KEYS will mean that no responses are allowed.|
|prompt|string|null|This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the participant is supposed to take (e.g., which key(s) to press).|
|trial_duration|numeric|null|How long to wait for the participant to make a response before ending the trial in milliseconds. If the participant fails to make a response before this timer is reached, the participant's response will be recorded as null for the trial and the trial will end. If the value of this parameter is null, the trial will wait for a response indefinitely.|
Expand Down
122 changes: 77 additions & 45 deletions jspsych-psychophysics.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/**
* jspsych-mulit-objects
* Daiichiro Kuroki
* jspsych-psychophysics
* Copyright (c) 2013 Daiichiro Kuroki
* Released under the MIT license
*
* jspsych-psychophysics is a plugin for conducting Web-based psychophysical experiments using jsPsych (de Leeuw, 2015).
*
* plugin for displaying images, sounds, texts, and moving geometric figures and getting a keyboard/mouse response
*
* documentation:
* http://jspsychophysics.hes.kyushu-u.ac.jp/
*
**/

Expand All @@ -19,11 +20,71 @@ jsPsych.plugins["psychophysics"] = (function() {
parameters: {
stimuli: {
type: jsPsych.plugins.parameterType.COMPLEX, // This is similar to the quesions of the survey-likert.
//type: jsPsych.plugins.parameterType.STRING,
array: true,
pretty_name: 'Stimuli',
default: 'customize',
description: 'The objects will be presented in the canvas.',
nested: {
startX: {
type: jsPsych.plugins.parameterType.STRING,
pretty_name: 'startX',
default: 'center',
description: 'The horizontal start position.'
},
startY: {
type: jsPsych.plugins.parameterType.STRING,
pretty_name: 'startY',
default: 'center',
description: 'The vertical start position.'
},
endX: {
type: jsPsych.plugins.parameterType.STRING,
pretty_name: 'endX',
default: null,
description: 'The horizontal end position.'
},
endY: {
type: jsPsych.plugins.parameterType.STRING,
pretty_name: 'endY',
default: null,
description: 'The vertical end position.'
},
show_start_time: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'Show start time',
default: 0,
description: 'Time to start presenting the stimuli'
},
show_end_time: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'Show end time',
default: null,
description: 'Time to end presenting the stimuli'
},
line_width: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'Line width',
default: 1,
description: 'The line width'
},
lineJoin: {
type: jsPsych.plugins.parameterType.STRING,
pretty_name: 'lineJoin',
default: 'miter',
description: 'The type of the corner when two lines meet.'
},
miterLimit: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'miterLimit',
default: 10,
description: 'The maximum miter length.'
},
drawFunc: {
type: jsPsych.plugins.parameterType.FUNCTION,
pretty_name: 'Draw function',
default: null,
description: 'This function enables to move objects horizontally and vertically.'
},
}
},
choices: {
type: jsPsych.plugins.parameterType.KEYCODE,
Expand Down Expand Up @@ -86,13 +147,6 @@ jsPsych.plugins["psychophysics"] = (function() {
default: null,
description: 'This function enables to move objects as you wish.'
},
// drawFunctはプラグインの関数ではなく、stimuliに渡されるオブジェクトの関数
// drawFunc: {
// type: jsPsych.plugins.parameterType.FUNCTION,
// pretty_name: 'Draw function',
// default: null,
// description: 'This function enables to move objects horizontally and vertically.'
// },
}
}

Expand Down Expand Up @@ -152,18 +206,10 @@ jsPsych.plugins["psychophysics"] = (function() {
const centerX = canvas.width/2;
const centerY = canvas.height/2;

// initialize
let hasStimuli = true;
if (trial.stimuli === 'customize') {
if (trial.stepFunc !== 'undefined') {
hasStimuli = false;
} else {
alert('You have to specify the stimuli/stepFunc parameter in the psychophysics plugin.')
return;
}
}
if ((typeof trial.stimuli === 'undefined') && (trial.stepFunc === null))
alert('You have to specify the stimuli/stepFunc parameter in the psychophysics plugin.')

if (hasStimuli) {
if (typeof trial.stimuli !== 'undefined') {
for (let i = 0; i < trial.stimuli.length; i++){
const stim = trial.stimuli[i];
if (stim.obj_type === 'sound') {
Expand Down Expand Up @@ -196,23 +242,11 @@ jsPsych.plugins["psychophysics"] = (function() {

} else { // other than sound

if (typeof stim.startX === 'undefined' || stim.startX === 'center') stim.startX = centerX;
if (typeof stim.startY === 'undefined' || stim.startY === 'center') stim.startY = centerY;

if (typeof stim.endX === 'undefined') {
stim.endX = null;
} else if (stim.endX === 'center') {
stim.endX = centerX;
};

if (typeof stim.endY === 'undefined') {
stim.endY = null;
} else if (stim.endY === 'center') {
stim.endY = centerY;
};
if (stim.startX === 'center') stim.startX = centerX;
if (stim.startY === 'center') stim.startY = centerY;
if (stim.endX === 'center') stim.endX = centerX;
if (stim.endY === 'center') stim.endY = centerY;

if (typeof stim.show_start_time === 'undefined') stim.show_start_time = 0;
if (typeof stim.show_end_time === 'undefined') stim.show_end_time = null;
if (typeof stim.motion_start_time === 'undefined') stim.motion_start_time = stim.show_start_time; // Motion will start at the same time as it is displayed.
if (typeof stim.motion_end_time === 'undefined') stim.motion_end_time = null;

Expand All @@ -233,9 +267,6 @@ jsPsych.plugins["psychophysics"] = (function() {
stim.img = new Image();
stim.img.src = stim.file;
} else { // for drawing lines, rects, circles, and texts.
if (typeof stim.line_width === 'undefined') stim.line_width = 1;
if (typeof stim.lineJoin === 'undefined') stim.lineJoin = 'miter';
if (typeof stim.miterLimit === 'undefined') stim.miterLimit = 10;

if (stim.obj_type === 'line') {
if (typeof stim.angle === 'undefined') {
Expand Down Expand Up @@ -413,7 +444,8 @@ jsPsych.plugins["psychophysics"] = (function() {
}

if (stim.obj_type === 'manual') {
if (trial.drawFunc === null) {
//if (trial.drawFunc === null) {
if (stim.drawFunc === null) {
alert('You have to specify the drawFunc() when you set the obj_type parameter to manual.');
} else {
stim.drawFunc(stim, canvas, ctx);
Expand Down
6 changes: 6 additions & 0 deletions jspsych.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
*
* documentation: docs.jspsych.org
*
* The MIT License (MIT)
* Copyright (c) 2019 Joshua R. de Leeuw
* https://www.jspsych.org/about/license/
*
**/
window.jsPsych = (function() {

Expand Down Expand Up @@ -928,6 +932,7 @@ window.jsPsych = (function() {
if(typeof trial[param][i][p] == 'undefined' || trial[param][i][p] === null){
if(typeof jsPsych.plugins[trial.type].info.parameters[param].nested[p].default == 'undefined'){
console.error('You must specify a value for the '+p+' parameter (nested in the '+param+' parameter) in the '+trial.type+' plugin.');
alert('You must specify a value for the '+p+' parameter (nested in the '+param+' parameter) in the '+trial.type+' plugin.');
} else {
trial[param][i][p] = jsPsych.plugins[trial.type].info.parameters[param].nested[p].default;
}
Expand All @@ -940,6 +945,7 @@ window.jsPsych = (function() {
else if(typeof trial[param] == 'undefined' || trial[param] === null){
if(typeof jsPsych.plugins[trial.type].info.parameters[param].default == 'undefined'){
console.error('You must specify a value for the '+param+' parameter in the '+trial.type+' plugin.');
alert('You must specify a value for the '+param+' parameter in the '+trial.type+' plugin.');
} else {
trial[param] = jsPsych.plugins[trial.type].info.parameters[param].default;
}
Expand Down

0 comments on commit adfc5b4

Please sign in to comment.