-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the change_attr function to change attributes of the object dyn…
…amically.
- Loading branch information
kurokida
committed
Oct 24, 2020
1 parent
1147e61
commit 3d2e9ab
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="../jspsych.js"></script> | ||
<script src="../jspsych-psychophysics.js"></script> | ||
<link rel="stylesheet" href="../css/jspsych.css"></link> | ||
</head> | ||
<body></body> | ||
<script> | ||
let color = 0; | ||
|
||
var text_object = { | ||
obj_type: 'text', | ||
startX: 0, | ||
startY: 100, | ||
origin_center: true, | ||
content: 'RGB = [0, 0, 0]', | ||
font: "22px 'Arial'", | ||
text_color: 'white', | ||
change_attr: function(stim){ // Change the content dynamically | ||
stim.content = `RGB = [${color}, ${color}, ${color}]` | ||
} | ||
} | ||
|
||
var rect_object = { | ||
obj_type: 'rect', // means a rectangle | ||
startX: 0, // location in the canvas | ||
startY: 0, | ||
origin_center: true, | ||
width: 100, // of the rectangle | ||
height: 100, | ||
line_color: 'rgb(0,0,0)', | ||
fill_color: 'rgb(0,0,0)', | ||
change_attr: function(stim, times, frames){ // called by the requestAnimationFrame | ||
const frequency = 0.05; | ||
const sin_value = Math.sin(2 * Math.PI * frequency * times/1000) // The times are in terms of milliseconds | ||
const normalized_value = sin_value/2 + 1/2; // from 0 to 1 | ||
color = Math.floor(normalized_value * 255) // An integer between 0 and 255 | ||
stim.fill_color = `rgb(${color}, ${color}, ${color})` | ||
} | ||
} | ||
|
||
var trial = { | ||
type: 'psychophysics', | ||
stimuli: [text_object, rect_object], | ||
choices: ['y', 'n'], // The participant can respond to the stimuli using the 'y' or 'n' key. | ||
canvas_width: 600, | ||
canvas_height: 600, | ||
} | ||
|
||
jsPsych.init({ | ||
timeline: [trial], | ||
on_finish: function(){jsPsych.data.displayData();} | ||
}); | ||
</script> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters