Howdy, Stranger!

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

Supported by

Setting a background that is an image

edited January 2017 in OpenSesame

Hi Guys,

I am trying to edit a small experiment and am not really familiar with this program.
In the beginning of the code we have a code set background "white". How could I do this so that I set an image there instead? Additionally, I would like to have it switching every couple of questions. It would look like this:


Which animal do you prefer (2 pictures in different places to choose)
What food do you prefer?

Which clothing would you rather wear?

etc...

Would be grateful for any responses!

Comments

  • Hi Pain,

    Welcome to the forum!

    What you describe seems absolutely possible, and it could be achieved with multiple methods depending on the exact workings of your experiment.

    The most straightforward option would be to use sketchpad items to present your stimuli (questions) on which you insert a background image. The image can be changed after every X amount of trials, depending on the specific. See the documentation for a better description:

    However, in the example you provide it seems that you want participants to choose between two pictures? If you want to use clickable pictures it might be a solution to use forms instead of sketchpads. Check the documentation what is possible or this recent forum post for more inpsiration:

    Bottom line, it is certainly possible but we need a bit more information on what you have tried so far and what it exactly is that you want to create.

    Best,
    Laurent

  • Thank you!
    I have actually been able to figure this out by using bgroung_image = exp.get_file('materials/house.jpg')
    +
    my_canvas.image(bgroung_image, False, 0, 0), with image sized to the screen resolution. Then, while in loop, it is easy to change them as I wish.

    Now I have a different dilemma, which is changing a cursor. The same idea as before, it should change along with the background - for example to .png of a shooting gun, or to a "+" sign or whatever.

    Is it possible as well?

    Thank you for taking your time to help me, I really appreciate it!

  • Hi again,

    I have actually been able to figure this out by using bgroung_image = exp.get_file('materials/house.jpg')
    +
    my_canvas.image(bgroung_image, False, 0, 0), with image sized to the screen resolution. Then, while in loop, it is easy to change them as I wish.

    Great!

    Now I have a different dilemma, which is changing a cursor. The same idea as before, it should change along with the background - for example to .png of a shooting gun, or to a "+" sign or whatever.

    If i'm not mistaken the cursor is being drawn by your operating system and is therefore difficult to change with OpenSesame. You could try and see if you can manually change the cursor, but then i can't think of a method where you would be able to vary it. Perhaps @sebastiaan has an solution?

  • If i'm not mistaken the cursor is being drawn by your operating system and is therefore difficult to change with OpenSesame.

    Exactly, the mouse cursor is handled by the operating system. If you want to draw your own mouse cursor, you have to hide the actual cursor (it is hidden by default in OpenSesame) and then draw your own cursor onto a canvas. This is actually the example for the documentation of the mouse object. :wink:

    Let's say that you have two files in the file pool: background.png, to be used for the background image, and cursor.png, to be used for the cursor image. Then you could do something like this:

    my_mouse = mouse()
    my_canvas = canvas()
    while True:
        button, position, timestamp = my_mouse.get_click(timeout=20)
        if button is not None:
            break
        (x,y), time = my_mouse.get_pos()
        my_canvas.clear()
        my_canvas.image(pool['background.png'])
        my_canvas.image(pool['cursor.png'], x=x, y=y)
        my_canvas.show()
    
Sign In or Register to comment.