Howdy, Stranger!

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

Supported by

[open] Adding random number to Draw Textline?

edited March 2015 in OpenSesame

I have made a visual stimuli that consists of a series of numbers spaced apart in varying ways ( see below)

image

Each of the numbers is positioned using the draw text line feature with specific coordinates. I was wondering if there is anyway I can use a random number generator to add a random number in the text line, keeping the same format as I already have ( but changing the numbers shown), so that I can create a collection of the stimuli above automatically? I have a number of other test cards with varying degrees of spacing that I will apply the method too as well.

Thank you in advance,

Tyler

Comments

  • edited 4:50AM

    Hi Tyler,

    Do you want to change the numbers, after you have already created such a display, or is it also fine, if you create it with random numbers right from the beginning?

    The exact way of doing it depends on what it is that you need. In any case, you have to have control over which type of stimulus (line vs. number) is shown at which position. So, while creating the displays, you need to keep track of the positions, e.g. in a list that either saves the coordinates, or only the indices of them, if the coordinates are evenly spaced.

    Later, you can use this list as a boolean array like way of accessing the content at every position and manipulate it in any way you like.

    Does this make sense? If you need more help, just say so.

    Good luck,

    Eduard

    Buy Me A Coffee

  • edited 4:50AM

    Hi eduard,

    Thank you for your response. It is not necessary that I create the random number array later, but it is important that the coordinates of the numbers and the lines remain the same. If it is not too much trouble, could you give me an example of how I might use 'list' to save the coordinates?

    This is sort of what I had in mind:

    @ [-480, -384] = output is some random number; @ [-224, -384] = output is some random number, etc

    In my mind, the idea is to set up the coordinate array and have it propagated with random numbers automatically. This is to say that once the list has been created for the coordinates, I want a function to take the coordinates and give a random number output. If this makes since.

    Thank you for your help,

    Tyler

  • edited 4:50AM

    Hi Tyler,

    I assume, that your display has a grid-like structure, that is, it consists of a certain number of cells in horizontal and vertical dimension, which are evenly spaced. Is this correct?
    If so, you could split the creation of this display into two functions. First, for creating the grid and assigning every position to the respective category (line vs. number). Second, adding random numbers and put them at the proper positions. So, pretty much like you already thought.
    The first function could look like this:

    import random
    
    def assignPositions(shape = (width,height)):
        # width and height indicate how many elements per dimension
    
        # containers for the positions
        lines = []
        numbers = []
    
        for w in range(width):
            for h in range(height):
                # pick randomly to which group this position should belong
                random.choice([lines,numbers]).append((w,h))
    
        return lines,numbers
    

    If you want to make sure that there is at least a certain numbers of positions assigned to lines/numbers you can wrap a while loop around this function and run it until the requirements are fulfilled, e.g.:

    lines, numbers = assignPositions(shape = (10,10))
    while len(lines) <10 or len(numbers) < 10:
        lines, numbers = assignPositions(shape = (10,10))
    

    After you have the indices of every position in your display, you can loop over each of it, check to which group it belongs and draw the corresponding stimulus. Here, you also have to translate the position indices into real coordinates, which is not really difficult. The general idea is to divide the total space your display should cover, by the number of elements per dimension.


    def drawGrid(canvas,shape,lines,numbers): # first, you have to translate the indices into real coordinates x_max = 500 # Whatever you prefer here y_max = 500 step_x = 500 / width step_y = 500 / height for w in range(width): for h in range(height): pos_x = start_x + w * step_x pos_y = start_y + h * step_y # now check which stimulus is drawn at this position and draw it if (w,h) in lines: # length indicates how long one line should be. canvas.line(pos_x - length2/,pos_y,pos_x + length/2, pos_y) elif (w,h) in numbers: # I'm not sure whether this is the correct way of generatic random integers # if not, you can find it out via google num = random.randint(0,99) canvas.text(str(num),pos_x,pos_y) # After defining this function, you can call it: from openexp.canvas import canvas cv = canvas(exp) width,height = 10,10 drawGrid(cv,(width,height),lines, numbers) cv.show()

    This should help you getting started, right? Let us know if you need more help.

    Good luck,

    Eduard

    Buy Me A Coffee

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