Howdy, Stranger!

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

Supported by

Controlled Randomization?

HI!

I'm a super beginner to coding and opensesame! For my experiment, I need to define the areas on the screen (excluding the center and corners) in which the stimulus will appear on random locations. I also want to be able to record the relative distance of the stimulus appearance to later look at. How do I accomplish this?

Thank you in advance!

Comments

  • Hi,

    There are many, many ways to do that.

    First of all, if you are a super beginner, I recommend that you finish a few tutorials before you tackle your problems. This will make your life so much easier in the future and even though it will take some extra time now, you'll save much more time later.

    You can start with the Opensesame tutorial to get familiar with the interface and the structure:

    https://osdoc.cogsci.nl/3.2/tutorials/beginner/

    and can also have a look at some basic Python tutorials (there are soo many out there!):

    https://python.cogsci.nl/

    I need to define the areas on the screen (excluding the center and corners) in which the stimulus will appear on random locations

    One approach could be to define areas that you want to exclude, and then randomly sample x,y positions and check whether they fall in that area. Here an example for how you would exclude the central 100 pixels around fixation (in a box shape, if you want a circular shape, you should use the distance between the middle of the sphere and the sampled position)

    import random
    
    # the define the limits of the area you want to exclude
    x_min = -50
    x_max = 50
    y_min = -50
    y_max = 50
    
    screen_width = 1600
    screen_height = 1000
    
    # keep on sampling x and y coordinates until you have some that lie outside the central box.
    while True: 
        x = random.sample(range(-0.5*screen_width,0.5*screen_width),1)[0]
        y = random.sample(range(-0.5*screen_height,0.5*screen_height),1)[0]
        if (x < x_min or x> x_max) and (y < y_min or y> y_max):
            break
    

    I also want to be able to record the relative distance of the stimulus appearance

    Distance can easily be computed with Pythagoras. For two points (x1,y1 and x2,y2) you square the difference between the x coordinates and add it with the squared distance of the y-coordinates and, finally, take the square root of that sum (sqrt((x1-x2)^2 + (y1-y2)^2)). You can write this code yourself or use existing functions, e.g. hypot in the math library.

    I hope this will get you started.

    Eduard

Sign In or Register to comment.