Howdy, Stranger!

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

Supported by

[open] Position certain word character relative to a point

edited February 2015 in OpenSesame

Hello,

I'm building an experiment which consists of RSVP of a series of words. Among other things I'm trying to position each word onto the canvas, in a way that a certain character of the word (e.g. the 3rd character -not constant between words, for some word it would be the 2nd for some other the 4th, etc.) will be centered relative to a given point on the canvas (a coordinate on the canvas).

Is there a way I could do the trick? (I've only managed, despite a lot of programming effort and time invested, to do a not so accurate approximation)

Thanks in advance.

Comments

  • edited 6:57AM

    I got it!!

    Someone can use in a smart way the canvas.text_size() function which returns the size of a text string in pixels (width, height tuple) in conjunction with appropriate slicing for the string array.

  • edited 6:57AM

    Hi Michael,

    An even easier solution would be to pad your string with spaces. That way you can present the text always at the same position, but vary the way that the string is padded, like so:

    "   ABC   " # Centered on B
    "  ABC    " # Centered on C
    "    ABC  " # Centered on A
    

    Cheers!
    Sebastiaan

Sign In or Register to comment.