diff --git a/demos/change_attributes.html b/demos/change_attributes.html new file mode 100644 index 0000000..7df24dc --- /dev/null +++ b/demos/change_attributes.html @@ -0,0 +1,57 @@ + + + + + + + + + + + diff --git a/docs/objectProperties.md b/docs/objectProperties.md index e92511e..31950af 100644 --- a/docs/objectProperties.md +++ b/docs/objectProperties.md @@ -38,6 +38,7 @@ This code means that a white rectangle is presented at coordinates (200, 150) in |line_width|numeric|1| The width of the line.| |lineJoin|string|'miter'|[The type of the corner when two lines meet](https://www.w3schools.com/tags/canvas_linejoin.asp)| |miterLimit|numeric|10|[The maximum miter length](https://www.w3schools.com/tags/canvas_miterlimit.asp)| +|change_attr|function|null|You can change the attributes of the object dynamically. The first argument is the stimulus, the second is the elapsed times in milliseconds, and the third is the elapsed times in frames. See [the demos/change_attributes.html](https://www.hes.kyushu-u.ac.jp/~kurokid/jspsychophysics/demos/change_attributes.html).| NOTE: The *horiz(vert)_pix_frame(sec)* can be automatically calculated using the *startX(Y)*, *endX(Y)*, *motion_start_time*, and*motion_end_time*. @@ -119,7 +120,7 @@ This object would be used as the fixation point. |Property name|Type|Default Value|Description| |---|---|---|---| -|drawFunc|function|undefined|You can draw whatever the `` supports.| +|drawFunc|function|null|You can draw whatever the `` supports.| If you want to draw something that the jspsych-psychophysics does not provide the method, you can draw it using the drawFunc function. diff --git a/jspsych-psychophysics.js b/jspsych-psychophysics.js index 0707cf7..8436a36 100755 --- a/jspsych-psychophysics.js +++ b/jspsych-psychophysics.js @@ -98,6 +98,12 @@ jsPsych.plugins["psychophysics"] = (function() { default: null, description: 'This function enables to move objects horizontally and vertically.' }, + change_attr: { + type: jsPsych.plugins.parameterType.FUNCTION, + pretty_name: 'Change attributes', + default: null, + description: 'This function enables to change attributes of objects immediately before drawing.' + }, is_frame: { type: jsPsych.plugins.parameterType.BOOL, pretty_name: 'time is in frames', @@ -834,6 +840,7 @@ jsPsych.plugins["psychophysics"] = (function() { if (stim.drawFunc !== null) { stim.drawFunc(stim, canvas, ctx); } else { + if (stim.change_attr != null) stim.change_attr(stim, elapsedTime, sumOfStep) present_functions[stim.obj_type](stim); } stim.is_presented = true;