Skip to content

Commit

Permalink
Fixes #42: sketchpad bg color in coroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
dschreij committed Dec 6, 2020
1 parent d328898 commit a2e1c4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Binary file modified example-experiments/coroutines.osexp
Binary file not shown.
22 changes: 15 additions & 7 deletions src/js/osweb/items/sketchpad.js
Expand Up @@ -40,7 +40,7 @@ export default class Sketchpad extends GenericResponse {
this.elements = []
this.vars.duration = 'keypress'
}

/** Process a time out response. */
process_response_timeout () {
// Nothing happens
Expand Down Expand Up @@ -78,6 +78,18 @@ export default class Sketchpad extends GenericResponse {
}
}

/**
* Set the background color of the canvas if it is defined in the var store
*
* @memberof Sketchpad
*/
_set_bg_color () {
const backgroundColor = this.vars.get('background')
if (backgroundColor) {
this.canvas._styles.background_color = backgroundColor
}
}

/** Implements the prepare phase of an item. */
prepare () {
// Clear the canvas.
Expand All @@ -99,12 +111,7 @@ export default class Sketchpad extends GenericResponse {
// Inherited.
super.run()

// Check if background color needs to be changed
const backgroundColor = this.vars.get('background')
if (backgroundColor) {
this.canvas._styles.background_color = backgroundColor
}

this._set_bg_color()
// Set the onset and start the stimulus response process.
this.set_item_onset(this.canvas.show())
this.set_sri(false)
Expand All @@ -113,6 +120,7 @@ export default class Sketchpad extends GenericResponse {

* coroutine () {
yield
this._set_bg_color()
this.set_item_onset(this.canvas.show())
}
}

0 comments on commit a2e1c4d

Please sign in to comment.