Howdy, Stranger!

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

Supported by

[solved] Text/Image position independent of resolution?

edited April 2014 in OpenSesame

Hey!
I'm trying to set up an experimental paradigm on OpenSesame that is going to be used on multiple different systems. Since display resolutions might differ, I'm looking for a way to define stimulus positions based on percentage of the display rather than pixels. Right now I'm thinking about using an inline script to calculate the positions. I was wondering, however, if there is an easier way to change coordinates in opensesame.

Thanks in advance,
Jannis

Comments

  • edited April 2014

    Hi Jannis.

    The inline_script option is the easiest way to go, as OpenSesame does not support other coordinate units than pixels, and arithmetic operations in sketchpad's aren't supported. This doesn't mean that it has to be difficult to find a solution, though!

    Let's say you define the x and y coordinate of a stimulus in a loop item, as a percentage of the display size. Let's call the variables xpos and ypos. To recalculate this to pixels based on the display resolution, place the following code in the Prepare phase of an inline_script at the start of the trial sequence:

    # calculate the pixel values
    xpos = int(self.get("xpos") * self.get("width"))
    ypos = int(self.get("ypos") * self.get("height"))
    
    # overwrite the percentage values
    exp.set("xpos", xpos)
    exp.set("ypos", ypos)
    

    Now in a sketchpad, you can use [xpos] and [xpos] to define the stimulus coordinates.

    Good luck!

  • edited 9:42AM

    Hey Edwin,
    thanks for your help, works perfectly!

    cheers

  • edited April 2016

    Hi there Jannis,

    I'm trying to use the same inline script to get my images to fit my screen for an MRI experiment since some images are a bit on the large side. However I keep getting an error relating to my int. value I think. Any advice?

    image

    EDIT: More specifically, is there a way to scale in image to match the screen resolution/size

    Thank you!

  • edited April 2016

    Hi,

    The error that you are posting is related to some type conflict. As it seems you are trying to convert something to an integer (maybe even implicitly), which cannot be an integer. To say for sure, I would have to see the piece of code that produced this error.

    EDIT: More specifically, is there a way to scale in image to match the screen resolution/size

    var.width and var.height represent the dimensions of the screen. If you normalize your images based on these to values, you will get a scaling factor, that you have to apply to your images, so that your images will fit the screen. Something like that:

    image_width = 1680
    image_height = 1050
    
    # var.width = 800
    # var.height = 600
    
    scaling_x = var.width / float(image_width)
    scaling_y = var.height / float(image_height)
    
    # later when you draw your canvas, something like that
    canvas.image(image, scale = scaling_?) # if you wanna keep the ratio, use the
    # smaller of scaling_x, or scaling_y, respectively
    
    

    Does this help?

    Eduard

  • edited 9:42AM

    Hi Eduard,

    The images I have vary in dimension, some are 22501250, while others maintain a 800600 dimension. I opted for manually editing the images and scaling them with a locked aspect ration. Not the most elegant or efficient solution, but Occams razor.

    Thanks for the quick reply though. (y)

Sign In or Register to comment.