Howdy, Stranger!

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

Supported by

Moving texts and shapes using canvas functions

edited February 2017 in OpenSesame

Hi everyone,

I am trying to create a small animation as a feedback for participants using moving rectangles and texts. Basically, I am designing a mouse-tracking experiment with 2 clickable options (let's call them A & B. These two options are colored squares with centered text indicating money values and their positions are counterbalanced left-right). Depending on whether they click on option A or B, the money is either for the participants alone or to be split between the participants and a virtual partner. The mouse-tracking part of the experiment is fully functional so far.

To illustrate whether the money is for them alone or to be split, I would like to present two rectangles at the bottom left & right of the screen, indicating 'personal gains' & 'partner's gains' respectively.

When participants click on the response 'A', I want the button to 'fall' into the participants' gain box.
When participants click on the response 'B', I want the button to 'fall' first into the participants' gain box and then into the partner's gain box.
Ideally, the button would disappear when the gains have been distributed.

So far so good, I manage to animate the shapes and texts but:

i) I'm struggling to place the text at the center of the shape. It is centered at the #initial screen# but for some reasons, starts from above the rectangle when the animation starts. I'm assuming I did something wrong with the coordinates list at the start but cannot figure out what.

ii) I cannot really decide where to place a canvas.clear() (and which one to clear) so that the buttons disappear after the gains are distributed.

iii) For now, I was thinking to have 4 inlines with modified versions of this script to give feedbacks for the 4 types of trials that I have (Trial 'A' or 'B' and clicked button on the left or the right) with a Run if statement. Is it the most optimal thing to do ? If not, in which direction should I look ?

I started from the code presented here.

It looks as follows (this would be an example of a feedback when the left button is clicked and the gains must be shared):

cv = canvas()
cv1 = canvas()
cv2 = canvas()

value = var.moneyvalue #value indicated by the response
currency = 'HUF'
text = ("%s %s"%(value,currency))

# starting position
x1,y1 = -352,-256
x2,y2 = -352,-256
points = [[x1,y1],[x2,y2]]

#Text position
a1,b1 = -288,-192
a2,b2 = -288,-192


# initial screen # Text is well positioned here
for x,y in points:
    cv.rect(x,y,128,128, fill=True, color= var.responsecolor)
    cv.text(text,True,a1,b1,font_family ='sans',font_size = 40)
    cv.show()

# prepare first moving square #Text moves here
for x,y in points[:2]:
    cv1.rect(x,y,128,128, fill=True, color= var.responsecolor)
    cv1.text(text,True,a1,b1,font_family ='sans',font_size = 40)

# set a speed
speed = 3
# let first square move
for i in range(30):# range represents the distance that is covered on the screen
    cv2.copy(cv1)
    x1,y1 = x1+speed*i,y1+speed*i
    a1,b1 = a1+speed*i,a1+speed*i
    cv2.rect(x1,y1,128,128, fill=True, color= var.responsecolor)
    cv2.text(text,True,a1,b1,font_family ='sans',font_size = 40)
    cv2.show()
    cv2.clear()
    self.sleep(50)

points = [[x1,y1],[x2,y2]]
# prepare 2nd moving square
for x,y in points[:2]:
    cv1.rect(x,y,128,128, fill=True, color= var.responsecolor)
    cv1.text(text,True,a2,b2,font_family ='sans',font_size = 40)

# let second square move
# set a speed 
speed = 3
for i in range(30):# range represents the distance that is covered on the screen
    cv2.copy(cv1)
    x2,y2 = x2+speed*i,y2+speed*i
    a2,b2 = a2+speed*i,a2+speed*i
    cv2.rect(x2,y2,128,128, fill=True, color= var.responsecolor)
    cv2.text(text,True,a2,b2,font_family ='sans',font_size = 40)
    cv2.show()
    cv2.clear()
    self.sleep(50)

Thanks in advance for any comments, help, suggestions, I tried to make this as clear as possible :dizzy:

Comments

  • Hi Clem,

    You want to change a1 to b1 and a2 to b2. See screenshot below:

    Note I used print to print to the Debug window to debug your code.

    Best,
    Jarik

  • Hmm of course, that's such a stupid mistake ! Thank you ! I don't really know how I could miss that !

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