Howdy, Stranger!

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

Supported by

[solved] Mouse click to return grid coordinates instead

edited September 2012 in OpenSesame

If I have a picture of an xy graph on a sketchpad and then have a mouse_response following it, I can have participants click/touch on the picture to mark their response. But, the mouse_response records the tuple of the cursor according to the screen resolution and not the picture. I have centered the picture perfectly because the graph is such that the middle is 0,0. How can I change the mouse_response behavior to record the cursor location with regards to the sketchpad graph? I can manipulate the picture and the sketchpad functions, but the resolution is still what the mouse_reponse plugin seems tied to. Would inline_script be applicable here?

:)

Kyle

Comments

  • edited September 2012

    Hi Kyle!

    If I understand correctly, you want to register a mouse click position with regards to your picture. Is that correct?

    In that case, you might want to remove the mouse_response and replace it with an inline_script. In the run phase, you can type the following:

    from openexp.canvas import canvas
    from openexp.mouse import mouse
    
    # FILL THIS OUT YOURSELF
    picsize = (400,200) # width and height in pixels
    sketchpadname = "my_sketchpad" # name of the sketchpad in which you present your picture
    
    # create items
    my_canvas = canvas(self.experiment)
    my_mouse = mouse(self.experiment)
    
    # copy your sketchpad to canvas
    my_canvas.copy(exp.items[sketchpadname].canvas)
    
    # show canvas
    my_canvas.show()
    t0 = self.experiment.time()
    
    # wait for mouse response
    no_click = True
    while no_click:
        # get mouse position
        pos, postime = my_mouse.get_pos()
        # draw cursor
        my_canvas.fixdot(x=pos[0],y=pos[1])
        my_canvas.show()
        # wait for buttonpress
        click, clickpos, clicktime = my_mouse.get_click(timeout=5)
        # if button is clicked...
        if click:
            RT = clicktime - t0 # ...record time and...
            # ...check if the buttonclick is in between the picture's left and right edges and...
            if clickpos[0] > (self.get("width")/2) - (picsize[0]/2) and clickpos[0] < (self.get("width")/2) + (picsize[0]/2):
                # ...check if the buttonclick is in between the picture's top and bottom edges
                if clickpos[1] > (self.get("height")/2) - (picsize[1]/2) and clickpos[1] < (self.get("height")/2) + (picsize[1]/2):
                    no_click = False # discontinue while loop
        # reset screen (remove cursor)
        my_canvas.copy(exp.items[sketchpadname].canvas)
        
    # recalculate position
    response_x = clickpos[0] + self.get("width")/2
    response_y = clickpos[1] + self.get("height")/2
    
    # save some stuff
    self.experiment.set("response_x", response_x)
    self.experiment.set("response_y", response_y)
    self.experiment.set("response_time", RT)
    

    Since a standard OpenSesame canvas uses the top left of the screen as it's origin (point (0,0)), the only thing you have to do is add the distance to where you want your origin to be. In the above script, it is the center of the screen (and thus the center of your picture). I do not know if this is indeed the location that you wanted to calculate, so see below for the other options (replace the code underneath '# recalculate position' with one of the following):

    (0,0) is top left of picture:

    # recalculate position
    response_x = clickpos[0] + (self.get("width")/2 - (picsize[0]/2))
    response_y = clickpos[1] + (self.get("height")/2 - (picsize[1]/2))
    

    (0,0) is bottom left of picture:

    # recalculate position
    response_x = clickpos[0] + (self.get("width")/2 - (picsize[0]/2))
    response_y = clickpos[1] + (self.get("height")/2 + (picsize[1]/2))
    

    Please note that you should set your sketchpad's duration to 0 and that you should adjust the values of picsize and sketchpadname yourself!

    Good luck!
    Edwin

  • edited 4:24PM

    Edwin,

    Thank you for the inline-script direction and code. This seems to function well, but I'm still not getting the correct coordinates. I have the picture centered in the sketchpad (which I wonder, does the grid in the sketchpad have any bearing on the pictures location or is it simply a visual reference?) Still, if I run my experiment and click on the center of the picture I return my maximum resolution tuple 1280,800 (x,y).

    Looking at your code, I see that you are dividing the length and width in half to reach the center of the picture, so that seems clear. I have added the correct picture size at the top of course (774,689).

    Any ideas? This is so close, I feel it may be a bit of code work and we've got it. I'll tinker more with it as well.

    Thanks again,

    Kyle

  • edited September 2012

    Woops, my bad! To recalculate the coordinates to the cenre one shouldn't add half of the screen size, but deduct it in stead. I had just disected a human brain, so I was a bit distracted... Sorry!

  • edited 4:24PM

    Perfect! That was the chink in the armour. No we're rock solid. Thank you again sir!

  • edited October 2014

    Hi,
    I would like to ask then how to devide areas on a picture into different regions and then register the mouse clicks of the participants in these pre-defines regions? So I basically need the location where participants click on the picture, not in absolute coordinates but in terms of specific regions. Thank you very much!

  • edited 4:24PM

    I would like to ask then how to devide areas on a picture into different regions and then register the mouse clicks of the participants in these pre-defines regions?

    This depends on how you have defined your regions of interest (ROIs). If you simple divide the screen into a grid, you can use the touch_response plug-in, as described here:

    If you have defined ROIs in a different way, then you first need to know exactly how they are defined. For example, do you have a spreadsheet with coordinates and radii that define your ROIs? Or do you have a bitmap in which ROIs are color coded? Or something different altogether?

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