Howdy, Stranger!

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

Supported by

[solved] Sinusoidal smooth pursuit target

edited February 2016 in OpenSesame

Hi all,

I'm relatively new to OpenSesame and I need to get familiar with it for my Masters. For my experiment, I am trying to create a smooth pursuit target (fixation dot) that travels in a horizontal sinusoidal wave across the canvas (from left to right). At a later stage, I also need to vary the speed of this smooth pursuit target.

I understand that there is a plug in to represent a sinusoidal moving stimulus but I'm not sure how to use it.

Hope one of you can help me with my problem!

Thanks in advance!
Anupama

Comments

  • edited 5:36AM

    Hi Anapama,
    Nice to see you have found the forum. This should be easy to do, but I don't have an example readily available. If I have a few moments tomorrow I will see if I can quickly create some example to post here for you (or if another forum member has done something similar and can beat me to it that is also fine).
    Good to see you are already starting your own project with OpenSesame.

    Buy Me A Coffee

  • edited February 2016

    Hi Anapuma,

    here is small example script with which you can achieve what you want. Simply copy its contents to the run phase of an inline_script item placed in your experiment. We actively encourage people to make the step to OpenSesame 3, in which some things have changed compared to version 2, but nevertheless, support for version 2 will stop at some point in the future, so why not make the transition now ;)

    from math import sin, cos
    
    # Create keyboard reference
    kb = keyboard()
    # Create a canvas
    cnvs = canvas()
    
    # Left and right x coordinate of screen
    screen_min_x = 0
    
    # Wave properties in pixels
    amplitude = 100
    
    #might be not the real wavelength in physical terms. Check this
    wavelength = 40.0 
    
    # x to start with
    x = screen_min_x
    
    # horizontal translation in pixels per frame
    dx = 5
    
    while True:
        # Check for keypress and stop if detected
        key, time = kb.get_key(timeout=0)
        if not key is None:
            break
    
        # Calculate y coordinate for current frame
        y = sin(x/wavelength)*amplitude
    
        # Erase old canvas contents
        cnvs.clear()
        # Draw fixation dot at current position
        # OS3 works with (0,0) as the screen center coordinate, so translate
        # x coordinate to the right position
        cnvs.fixdot(x=x-cnvs.width/2,y=y)
        # Show the canvas
        cnvs.show()
    
        # Calculate x coordinate for next frame, make sure that it restart at 0
        # once the right edge of the screen is reached.
        x=(x+dx)%cnvs.width
    

    If you must (for instance, you are on a mac), here is a solution in the old OpenSesame 2 syntax (spot the difference :) )

    from openexp.keyboard import keyboard
    from math import sin, cos
    
    # Create keyboard reference
    kb = keyboard(exp)
    
    cnvs = self.offline_canvas()
    
    # Left and right x coordinate of screen
    screen_min_x = 0
    screen_max_x = cnvs.xcenter()*2
    
    # Wave properties in pixels
    amplitude = 100
    
    #might be not the real wavelength in physical terms. Check this
    wavelength = 40.0 
    
    # x to start with
    x = screen_min_x
    
    # horizontal translation in pixels per frame
    dx = 5
    
    while True:
        # Check for keypress and stop if detected
        key, time = kb.get_key(timeout=0)
        if not key is None:
            break
    
        # Calculate y coordinate for current frame
        y = sin(x/wavelength)*amplitude + cnvs.ycenter()
    
        # Erase old canvas contents
        cnvs.clear()
        # Draw fixation dot at current position
        cnvs.fixdot(x=x,y=y)
        # Show the canvas
        cnvs.show()
    
        # Calculate x coordinate for next frame, make sure that it restart at 0
        # once the right edge of the screen is reached.
        x= (x+dx)%screen_max_x
    

    Buy Me A Coffee

  • edited February 2016

    Hi Daniel,

    Thank you so much, this is great! I still have OpenSesame 2.9 so the second solution worked!
    I notice the subtle differences like the need to import keyboard in OS2 and the difference in center coordinate values between the two versions.

    I had a few follow up questions about the code:

    1. I see the wavelength needs to be a float. I'm guessing this is always the case?

    2. I'm a bit confused about the use of the sin function. i know it returns a sine wave of the arguments but I hadn't thought of using x/wavelength as the argument before (when I was trying this myself, I thought we had to use pi and whatnot!) What is a good way to determine what can be an argument for the sin function? (In this case, for example?)

    3. I don't entirely follow the last part of the code though I understand what it does - I understand that %screen_max_x ensures that the sinusoidal fixation dot repeats itself from the start of the screen at the end of one loop. I was just wondering how it does that.
      I printed the x values for clarification and I see it rises consecutively as x travels through the screen and then starts from scratch once it has reached the screen end. So the modulo operator here ensures that the values start over each time?

    Once again, thank you so much for your help! This definitely helps me start off with my experiment :)

  • edited February 2016
    1. Ha! You know the answer to this question yourself already. int/int -> int as result, so if I want to have a float result, I have to make one of the operands a float

    2. You are right about the sin function expecting radial values, but these are also just numbers right? So you can provide values 0 to 2 * pi, which translates to roughly 6.28. You can provide the sin and cos functions higher values, but they just keep treating these as fractions of pi (so for instance 9.52 which is 2.5 * pi would have the same result as 0.5 * pi). I suggest you look up more information on Wikipedia if you want to know more about this topic. It's all just math.

    3. When the dot has reached the right side of the screen, I want it to reappear at the left side again. If I do any x value modulo the max_x pixel of the canvas, I make sure that my x always falls between 0 and the max_x value. That's basically what modulo does, but if you find this a bit vague now I can also recommend reading up on modulo or try some examples out with it yourself. Modulo is a very powerful operator, which can take a lot of work out of your hands.

    Buy Me A Coffee

  • edited 5:36AM

    This was quite helpful! thanks again, Daniel :)

  • edited March 2016

    Hi again Daniel,

    I got a bit far on my experiment and I had a few additional questions about OpenSesame functions.

    In my experiment, I'm trying to create one long experimental run consisting of individual trials that go on for 8 minutes. More specifically, I'm trying to create a sinusoidally moving fixation dot that moves from back and forth continuously for 8 mins. Each individual trial should last for 1 second (therefore, 480 trials in all in one run)

    I managed to program the sinusoidal fixation dot in such a way that it travels for 8 minutes (exp.time() - start_time) > 48000). My question is:
    If I want to present a line stimulus on any one randomly chosen trial (while the fixation dot is still moving back and forth), what would be the best way to do that in my inline script? I did ask some others for help and this is what I have so far:

    Hz = 0.5
    frame_times = np.arange(0,480,1.0/60.0)
    plot(frame_times, np.sin(Hz * frame_times))
    first_stim_present_times = np.random.randint(2, 5, size = 500).cumsum()
    
    first_stim_present_times = first_stim_present_times[first_stim_present_times < frame_times.max()]
    

    So, I think the above code picks out random trials (stored in first_stim_present_times ) How do I then draw my stimulus on these chosen trials?

    Looking forward to your reply!

    Thanks in advance!
    Anupama

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