Howdy, Stranger!

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

Supported by

Use touch coordinates to draw element

edited May 2017 in OpenSesame

I'm trying to create a task involving a touchscreen response wherein participants listen to a recording while looking at a picture on screen. This sketchpad is then replaced by a second screen where participants see a line of text and a circle, and perform their response. Then, participants will touch somewhere around the circumference of the circle, and I then need an arrow element to be drawn with the tip coordinates corresponding to the coordinates of the touch response.

To do all this I'm using the inline script below, which displays the circle and instructions correctly, but does not seem to register a response or draw the arrow element. From what I gather from the documentation, a touch response is effectively equivalent to a mouse click, so I'm using the get_click() function to record the "key" press, position, and time (I will need response time as well). I suspect I might be going wrong when trying to unpack and reference the "position" tuple, but maybe the problem is elsewhere?

DISCLAIMER: I'm very much a Python noob.

my_canvas = canvas()
my_mouse = mouse()

while True:
        my_canvas.clear()
        my_canvas.text("INSERT INSTRUCTIONS HERE", center=True, x=0.0, y=372.0, color='white')
        my_canvas.circle(0, 0, 300, color='white')
        t0 = my_canvas.show()
        my_canvas.show()
        button, position, t1 = my_mouse.get_click()
        var.x = position[0]
        var.y = position[1]
        my_canvas.arrow(0, 0, var.x, var.y, body_length=0.8, body_width=0.5, head_width=30)

Comments

  • Hi Fabio,

    You are almost there, the response are collected and the arrow is constructed. However, you need to 'flip' the canvas to update the screen once a response has been collected. Simply add my_canvas.show() at the end of your script and it should work.

    You can test this by adding print statements throughout the script (e.g. print('The cursor was at (%d, %d)' % (x, y)))

    Best,
    Laurent

  • I noticed that I was asking it to draw the tip at the click position, while also accidentally trying to force a fixed arrow length, so I changed the code as follows:

    my_canvas = canvas()
    my_mouse = mouse()
    
    while True:
            my_canvas.clear()
            my_canvas.text("You're now standing the end of the route. Point to the direction of your starting location.", center=True, x=0.0, y=372.0, color='white')
            my_canvas.circle(0, 0, 300, color='white')
            t0 = my_canvas.show()
            my_canvas.show()
            button, position, t1 = my_mouse.get_click()
            var.xpos = position[0]
            var.ypos = position[1]
            var.arrow_length = xy_distance(0, 0, var.xpos, var.ypos)
            my_canvas.arrow(0, 0, x=var.xpos, y=var.ypos, body_length=var.arrow_length, body_width=0.5, head_width=30)
    

    However, this doesn't seem to work either, and produces the following error:

    TypeError: arrow() takes at least 5 arguments (6 given)

    I know that the variables xpos, ypos, and arrow_length are being calculated correctly, because they are saved in the variable inspector.

  • edited May 2017

    Ok, progress! I've added the my_canvas.show() line as you suggested, and It seems to be doing something, at least with the PsychoPy backend. Is there a way to make the cursor visible, at least for testing on Windows? That way I know where the arrow should be drawn. At the moment, it looks rather odd, no matter where I click (not that I can tell where I'm clicking). Also, the arrow doesn't persist on the screen, but disappears when I unclick. Is there a way to change that?

    EDIT: Silly me. Removing the body_length argument altogether fixed the weirdness.

  • edited May 2017

    Hi Fabio,

    Good to see progress!

    at least with the PsychoPy backend.

    If the experiment is designed for a touch-based device (e.g. an Android tablet), it is required to use the Droid back-end.

    Is there a way to make the cursor visible, at least for testing on Windows?

    Adding my_mouse.show_cursor(show=True) should work, but depending on the back-end and version of OS it is not always as consistent. See:

    Also, the arrow doesn't persist on the screen, but disappears when I unclick. Is there a way to change that?

    Sure! Add something like clock.sleep(1000) at the end of the script, where the number is the amount of time you want to display the cursor in ms.

  • Thanks Laurant, that helps a lot! What if I wanted to give participants the chance to change their response (i.e. re-orient the arrow) and then confirm it by pressing on a button (that would appear in the middle of the circle after the arrow was first position and would stay there until the answer is confirmed)?

    Basically, the canvas should remain until the participant clicks on the button. I know how to load the image file, but I'm not sure how to turn it into an interactive button.

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