[solved] Sketchpad and Canvas question
Hey guys,
My question is pretty straightforward - I'm just trying to copy a sketchpad into a canvas so I can run canvas.show() in some inline code.
I have the following code in my script (engage_disengage is the name of my sketchpad):
my_canvas = self.experiment.copy_sketchpad('engage_disengage')
my_canvas.show()
I get a run-time error with the above code - it tells me that it can't run the command because engage_disengage does not have a canvas attribute? Was I supposed to convert the sketchpad to a canvas type at some point!
As always, thanks for the help!
-Ricky
Comments
Hi Ricky,
Assuming that you indeed have a
sketchpaditem named engage_disengage in your experiment, the problem is likely because the canvas of engage_disengage hasn't been prepared yet at the moment that you call thecopy_sketchpad()function.More specifically, if you were to place this code in the prepare phase before the engage_disengage
sketchpad, then you will get this error message, because you are trying to copy a canvas that hasn't been constructed yet. If you place this code in the run phase or after thesketchpad, then you should be fine.For more information about the prepare-run strategy, see:
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hey Sebastian,
Thanks, I actually had the sketchpad in the unused items section because I was trying to load it exclusively from inline script code because I was worried about lag time in loading the sketchpad after a certain trigger had been hit in inline code the step before in the sequence, but reading over that it looks like load time is pretty negligible given that the sketchpad is prepared beforehand..
Anways, thanks!
-Ricky
Hello again,
I'm having a similar issue to the one above (hence resurrecting the post), I'm trying to copy a sketchpad item ('stripes') into an inline script item ('ongoing-script') which already contains a canvas ('trial_display').
I need the sketchpad to overlay the canvas whilst still showing the canvas item beneath - basically so that the lines on the sketchpad disrupt the lines on the 'trial_display' canvas.
I'm just having a little trouble copying the canvas - specifically what to write where in the script entry...
Any pointers would be great!
Thanks,
Lee
Hi Lee,
A
canvasobject is not transparent, so you cannot combine the content of twocanvasobjects. What you can do, is first copy thecanvasfrom asketchpadand then draw extra things on it, like so:But the reverse is not possible, i.e. you cannot first draw things onto a
canvasand then add the contents of anothercanvas. So my recommendation would be to restructure the code so that you don't need to superimpose twocanvasobjects, which is usually possible.Otherwise, in principle it is possible to 'hack' your code together by delving into the OpenSesame internals. For example, for the
psychoback-end, everycanvashas astim_list, which you can copy and combine with thestim_listfrom anothercanvas. This is a back-end-specific hack though, I wouldn't do it unless it's really necessary.Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hmmm, this is actually related to a previous problem (http://forum.cogsci.nl/index.php?p=/discussion/619/solved-changing-polygon-linestyle#Item_5), but so far I haven't been able to create the workaround you suggested and make it work the way I need.
The canvas 'trial_display' shows all of the primary stimuli, the 'stripes' will be a secondary stimulus (i.e. "press key X when the primary image is disrupted" so they only need to occur twice in each of the last two sessions.
I had thought to just copy the sketchpad stripes and present it over the top of the trial_display canvas, but all I get is the 'stripes screen' wedged between two presentations of the primary stimuli... I have also tried this as a solution http://www.cogsci.nl/forum/index.php?p=/discussion/156/open-question-on-how-to-make-a-sketchpad-object-partly-transparent/p1, but in reverse, however I can't make it work either.
I have decided to post the script via pastebin as a last resort (I have started collecting data on the first condition for this experiment, so time has become a factor in making this work... I am now a desperate chap!)
Pastebin here
Hopefully you can see the problem, I need to show the sketchpad on top of the canvas [trial_display] whilst still being able to see the stimuli beneath... thus the image pairs will have 'broken lines' as you previously suggested.
Many thanks!
Lee
Hi Lee,
You are first showing
trial_displayand thenstripes. As I explained above, this will not cause the contents of both canvas objects to be combined, but will first cause (only)trial_displayto be shown, followed by (only)stripes.In your case, it's probably easiest to draw the white vertical stripes on your
trial_displaywith something like the following script:That way you don't have to bother with copying a sketchpad, etc. Does that make sense?
As an aside, you have put all your code in the prepare phase of your
inline_scriptitems. Although this may work, it is good style to use the prepare phase only for preparatory stuff, and not for stimulus presentation, etc. See also:Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Sebastiaan,
That looks similar to a Bresenham algorithm (I think!) which I saw somewhere in my trying-to-find-a-solution research. I'll give it a try and let you know what happens.
As for the prepare-run, I presume then that if I move all of my stimulus presentation to the run phase it will reduce any timing lag I'm experiencing?
Best,
Lee
Not necessarily, but it will avoid problems when you combine your inline scripts with other items that do follow the prepare-run strategy.
Check out SigmundAI.eu for our OpenSesame AI assistant!
I've incorporated the script snippet into my experiment as:
This covers the area I require.
I've taken a picture - its not great, but you can see vertical grey lines between each white stripe. This isn't ideal as it adds 'accidental stimuli' to the screen, rendering any responses ambiguous... Just wondering if there is anything that can be done about this as I haven't a clue (aside from changing the instructions to "press key X when image is disrupted").
It also causes a huge pause just before it is shown which is a massive clue to the participant that something is going to happen and also messes up the timing. I've tried putting it in both the prepare and run phases - seems to work better in the run phase.
Hopefully this will be the last issue I have - it's the LAST stimulus... so frustrating!
Thanks,
Lee
P.S. I also put all of my display code in the run phase as suggested - much neater!
Yes, I see them. I suspect that these gray lines result from the way that Expyriment (and PsychoPy for that matter) draws the stimuli, using OpenGL. This sometimes causes a bit of fuzziness, which in this case appears to be especially bothersome. I don't know if there's anything that can be done about it really, except disabling OpenGL under the back-end preferences or switching to the legacy back-end.
Given these gray lines and the speed issue, perhaps you would be better off using a semitransparent image as a mask. For example, you could create an image that is the size of your stimuli and is transparent except for some white vertical stripes. Then you could draw this image (
mask.png) on top of your stimuli, instead of drawing the masking lines one-by-one as I suggested previously:And to make sure that the timing is identical between mask and non-mask trials, you could show a completely transparent image as a dummy mask on non-mask trials. Is that an idea?
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
I used Paint.Net to make the stripe.png files (a different version for different sessions - I don't need participants practicing now...) and it works like a charm.
Very many thanks, that has made me a happy chap!
Best,
Lee