Howdy, Stranger!

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

Supported by

[solved] Adding a random number of elements in my experiment

edited December 2014 in OpenSesame

In my experiment I have 6 empty squares circled around the center of the screen. I want to sequentially add dots to them, randomly. The starting position should be random and the end position should be random. How can I achieve this using OpenSesame? It's my first time making an experiment in this program, I have tried to use for loops and random variables in both 'Sketchpad' and 'Inline script'. Unfortunately, 'Inline script' does not support drawing elements and 'Sketchpad' does not support random variables and/or drawing in sequences. I think 'loops' should be used to achieve the effect that I want, but I am unable to figure out the specifics.

Comments

  • edited 6:16AM

    Hi,

    You'll probably want to draw your stimuli in an inline_script, using the canvas object. (inline_scripts do support drawing!) To do this, you'll need to know a bit of Python though:

    To get you started, here's a short snippet that shows how you can draw an array of circles:

    from openexp.canvas import canvas
    from math import pi, cos, sin
    
    n = 6 # number of circles
    r = 32 # radius of the circle
    ecc = 128 # eccentricity of the circles
    
    # Create an empty canvas
    my_canvas = canvas(exp)
    my_canvas.fixdot()
    # Loop through all circles
    for i in range(n):
        # Determine the position of the circle, using
        # a bit of trigonometry
        a = 2.*pi*(1.*i/n)
        dx = ecc*cos(a)
        dy = ecc*sin(a)
        x = my_canvas.xcenter()+dx
        y = my_canvas.ycenter()+dy
        # Draw the circle
        my_canvas.circle(x, y, r)
    # And show the full display!
    my_canvas.show()
    

    Cheers,
    Sebastiaan

  • edited 6:16AM

    Thanks Sebastian, very helpful.
    I added 'self.sleep(1000)' to your sample to make it show a bit longer

Sign In or Register to comment.