Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Canvas functions using JavaScript

Hi there, 


I'm building an online experiment and encountered some dead ends when using Canvas() (JavaScript).

I have found some workarounds, but would still be interested in finding out about these 2 issues, as all my attempts to solve them unfortunately involved JavaScript functions that are not supported in OpenSesame (or maybe I failed to import the libraries correctly?).


a) Is there a way to draw a canvas on an existing sketchpad (like drawing on an image from the filepool)?

b) Is there a way to present a canvas for a specific duration (similar to a sketchpad where you can fix the duration to e.g. 500 ms, even if there is no response collected afterwards), so that I can update my canvas every 500 ms for 4 times (e.g. add an extra rectangle each time) - preferably without inculding additional items? 


Many thanks in advance!

Best,

Carla

Comments

  • Hi @CarlaC ,

    Is there a way to draw a canvas on an existing sketchpad (like drawing on an image from the filepool)?

    It is possible, but requires hacking into the OSWeb internals. So this may break in the future, and I would only do this if any other solution is impractical!

    The trick is to create an empty Canvas in an inline_javascript item, and then change it's internal _canvas property to the canvas of a sketchpad . You would need to do this after the sketchpad has been prepared, but before it has actually been shown. Here's the general idea (using the canvas from the welcome sketchpad):

    sketchpadItem = 'welcome'
    myCanvas = Canvas()
    myCanvas._canvas = runner._itemStore._items[sketchpadItem].canvas
    myCanvas.text({'text': 'Some additional text!'})
    

    Is there a way to present a canvas for a specific duration (similar to a sketchpad where you can fix the duration to e.g. 500 ms, even if there is no response collected afterwards), so that I can update my canvas every 500 ms for 4 times (e.g. add an extra rectangle each time) - preferably without inculding additional items? 

    JavaScript works with callbacks and does not have a regular sleep() function. This makes it impractical (though not impossible) to do what you're describing in javascript. But an easy solution might be to include the script in a sequence and have it followed by an advanced_delay , like so:

    Does that help?

    — Sebastiaan

  • Hi @sebastiaan,


    thanks a lot, that's what I was looking for!


    Best,

    Carla

Sign In or Register to comment.