[solved] modulate brightness of an object
Hi all,
I am trying to modulate the brightness of an object (e.g. square) in a ramped fashion (fade in or fade out). Additionally, I would like to try and synchronize this ramped brightness with ramped loudness of a presented auditory stimulus (a tone that either goes from quiet to loud or loud to quiet). Obviously, the presentation of the auditory stimulus is a trivial affair with the existing synth tool. However, I have no idea how to tackle ramping the visual stimulus or how best to sychronize the two. Any assistance you could offer would be greatly appreciated.
Best wishes,
merle

Comments
Hi Merle,
Ramping the brightness of the screen will not be difficult. You could use the script below in an inline_script item. Simultaneously ramping the sound will be tricky, though, as sounds presentation on most computers is subject to unpredictable latencies. The script below provides a potential solution, but depending on the specifics of your experiment, you might want to test whether the sound an visuals sync correctly.
prepare phase
run phase
Good luck!
Thank you so very much Edwin - much obliged! I will see how things go and if I have anything useful to add, will update the post.
Hi Edwin,
the script works a treat - thank you so much!
I need to create different conditions however:
3: sound: quiet - loud; canvas: bright - dark
Your script was perfect for the 1st but because I am not familiar with the synch object you used, I am not sure how to modify it to create the other 3 conditions. Your help would be greatly appreciated!
Best wishes,
Merle
Hi Merle,
You define the envelope of the
synthobject with two parameters: The attack, which specifies the time it takes to reach full volume, and the decay which is the time it takes to go back to silence. So to fade out, instead of fading in, you simply specify a decay, but no attack.So this fades in (i.e. Edwin's example) ...
... and this fades out ...
With respect to the
canvasobjects, the way that the fading in works is that there is a for-loop that increments the variableifrom 0 to 255:This is then used to specify a brightness for the canvas objects, by passing
(i,i,i)ascolorkeyword.This works, because a color is defined by three values (a
tuple) which define the amount of red, green, and blue on a scale from 0 to 255. Therefore, becauseiincrements, thecanvasobjects become progressively brighter. To reverse this, you simply use255-ias color:Do you see the logic here? I'll leave it up to you to integrate this further into your experiment!
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Sorry Merle, completely missed this for some reason! Thankfully, Sebastiaan provided all of the conditions you needed
Good luck!
Dear Sebastiaan, dear Edwin - thank you both! I was away on holiday and so have only seen the super helpful reply today. This not only helps me sort out my experiment but thank you so much for the useful description of the tool - this will be very useful in the future!
Best wishes
Dear both,
thanks again for helping me get this far. I now have an experiment that has all four conditions described above however I am getting an error that I can't quite seem to sort out.
For the conditions in which the screen goes from light to dark at the end of the fade, the screen seems to jolt and "refresh" and re-present the dark.
(exp.my_canvaslist[-1].rect(x=0, y=0, w=self.get("width"), h=self.get("height"), color=(255-i,255-i,255-i), fill=True)
This may be happening in the fade from dark to light conditions as well but one would not see the refreshing of the brightest end point, so it is hard to tell. I added a delay at the end of the target (the synched fade in/out of sound and screen brightness) before the start of the next visual stimulus to see if perhaps the system needed more time to finish the fade but this didn't help. I have no idea why this is happening so any advice you can offer would be greatly appreciated.
On a separate note, I am struggling with the logger and have tried to search the forum for ideas. Basically I have the following experiment order (randomised blocks using an inline script; and then I create repeats of these 8 blocks (the four conditions described above plus each of these using two orientations of the responses) using the "randomise blocks sequence" to iterate 10 times -- I hope this is correct and clear):

I would like to log three key things:
1. key press ("left" or "right")
2. response time (when did they hit "left" or "right" after the start of "keyboard response" - at the moment I have set the sketchpad item which contains the response options to duration=0, so can I assume that the keyboard response is starting at more or less the same time as the sketchpad?)
3. type of block for that response (1-8 as defined in the inline script, "item_list")
I am struggling a bit with the host of variables the logger can potentially record and find it difficult (when selecting "automatically detect and log all variables" as a failsafe) to identify which ones relate to the three things I need to log. I think I have found the "correct" variable and possible the response time but there is no indication of the block. How could I script this in?
Any help would be greatly appreciated.
Best wishes,
Merle
Hi Merle,
It's probably a little bug in your script. Could you post the script here, or upload the full experimental script to pastebin?
Regarding the logging issue. For the response and response time, it looks like you can simply use the
responseandresponse_timevariables, which are logged automatically. See also:To log which block you're currently running, it looks like you could use the
itemvariable from yourinline_script, like so:As a small aside, you should prepare and run each
sequenceat a time, instead of first preparing allsequences and then running allsequences. I'm not sure what happens in your case, but in some cases this could definitely cause problems. See also:Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Spotted the bug, I think. My fault as well! Sorry!
Should be:
EDIT: oh, no, wait, it was @sebastiaan's code that was to blame!
You guys are amazing! Thank you so much. I woke up to these two answers and can't tell you how grateful I am. This project is in its final phase with a planned write-up over Christmas. Could you please point me on how best to reference you incredible product?
Hi Merle,
No worries!
To cite OpenSesame, please use the information below:
Additionally, you might want to cite PsychoPy (if you used the psycho back-end), expyriment (if you used the xpyriment back-end), or PyGaze (if you used the EyeTracker or PyGaze plug-ins):
Good luck with the write-up!