Howdy, Stranger!

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

Supported by

[solved] modulate brightness of an object

edited September 2014 in OpenSesame

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

  • edited August 2014

    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

    from openexp.canvas import canvas
    from openexp.synth import synth
    
    # set the sound length (in milliseconds)
    exp.soundlen = 5000
    
    # prepare the canvas objects
    exp.my_canvaslist = []
    for i in range(256):
        # create a new canvast, and add it to the list
        exp.my_canvaslist.append(canvas(exp))
        # fill the latest canvas with a new colour
        exp.my_canvaslist[-1].rect(x=0, y=0, w=self.get("width"), h=self.get("height"), color=(i,i,i), fill=True)
    
    # prepare the synch object
    exp.my_synth = synth(exp, osc='sine', freq=440, attack=exp.soundlen, decay=0, length=exp.soundlen)
    

    run phase

    # start the sound
    exp.my_synth.play()
    
    # show the canvasses
    for i in range(len(exp.my_canvaslist)):
        # show a new canvas
        exp.my_canvaslist[i].show()
        # wait a bit before showing the next canvas
        self.sleep(exp.soundlen / len(exp.my_canvaslist))
    

    Good luck!

  • edited 9:31AM

    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.

  • edited August 2014

    Hi Edwin,

    the script works a treat - thank you so much!

    I need to create different conditions however:

    1. sound: quiet - loud; canvas: dark - bright
    2. sound: loud - quiet; canvas: bright - dark
      3: sound: quiet - loud; canvas: bright - dark
    3. sound: loud - quiet; canvas: dark - bright

    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

  • edited 9:31AM

    Hi Merle,

    You define the envelope of the synth object 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) ...

    exp.my_synth = synth(exp, osc='sine', freq=440, attack=exp.soundlen, decay=0, length=exp.soundlen)
    

    ... and this fades out ...

    exp.my_synth = synth(exp, osc='sine', freq=440, attack=0, decay=exp.soundlen, length=exp.soundlen)
    

    With respect to the canvas objects, the way that the fading in works is that there is a for-loop that increments the variable i from 0 to 255:

    for i in range(256):
    

    This is then used to specify a brightness for the canvas objects, by passing (i,i,i) as color keyword.

    exp.my_canvaslist[-1].rect(x=0, y=0, w=self.get("width"), h=self.get("height"), color=(i,i,i), fill=True)
    

    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, because i increments, the canvas objects become progressively brighter. To reverse this, you simply use 255-i as color:

    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)
    

    Do you see the logic here? I'll leave it up to you to integrate this further into your experiment!

    Cheers,
    Sebastiaan

  • edited 9:31AM

    Sorry Merle, completely missed this for some reason! Thankfully, Sebastiaan provided all of the conditions you needed :)

    Good luck!

  • edited 9:31AM

    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

  • edited 9:31AM

    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):
    image
    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

  • edited 9:31AM

    Hi Merle,

    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.

    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 response and response_time variables, which are logged automatically. See also:

    To log which block you're currently running, it looks like you could use the item variable from your inline_script, like so:

    for item in item_list:
        exp.set('current_block', item)
        exp.items[item].prepare()
        exp.items[item].run()
    

    As a small aside, you should prepare and run each sequence at a time, instead of first preparing all sequences and then running all sequences. I'm not sure what happens in your case, but in some cases this could definitely cause problems. See also:

    Cheers!
    Sebastiaan

  • edited December 2014

    Spotted the bug, I think. My fault as well! Sorry!

    (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)
    

    Should be:

    (exp.my_canvaslist[-1].rect(x=0, y=0, w=self.get("width"), h=self.get("height"), color=(256-i,256-i,256-i), fill=True)
    

    EDIT: oh, no, wait, it was @sebastiaan's code that was to blame! :p

  • edited 9:31AM

    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?

  • edited 9:31AM

    Hi Merle,

    No worries!

    To cite OpenSesame, please use the information below:

    • Mathôt, S., Schreij, D., & Theeuwes, J. (2012). OpenSesame: An open-source, graphical experiment builder for the social sciences. Behavior Research Methods, 44(2), 314-324. doi:10.3758/s13428-011-0168-7

    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):

    • Peirce, JW (2007) PsychoPy - Psychophysics software in Python. J Neurosci Methods, 162(1-2):8-13.
    • Krause, F. & Lindemann, O. (2014). Expyriment: A Python library for cognitive and neuroscientific experiments. Behavior Research Methods, 46(2), 416-428. doi:10.3758/s13428-013-0390-6.
    • Dalmaijer, E.S., Mathot, S., & Van der Stigchel, S. (2014). PyGaze: An open-source, cross-platform toolbox for minimal-effort programming of eyetracking experiments. Behaviour Research Methods, 46:4, p. 913-921.

    Good luck with the write-up!

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games