Howdy, Stranger!

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

Supported by

[solved] Using "show if" in sketchpads

edited June 2013 in OpenSesame

Hi,

I have a simple problem, I'm trying to set up an element on a sketchpad that should be shown only sometimes but I can't seem to get the syntax correct. Can you help me with this please?

draw rect 245 22 86 35 fill=1 penwidth=3 color=0 show_if="[Task]=Lum"

There are two main issues... First the color was originally in the #0000 format and that had the effect of commenting out the show if statement. Second, I'm not sure how to use quotations in the [Task] = Lum part.

Thanks

Comments

  • edited 10:00PM

    Sorry for reposting but I forgot to include that I would like to include the color of the rectangle en RGB system so how can I include that in that kind of syntax?

  • edited 10:00PM

    Also... I wan tot calculate the natural logarithm of a number I tried using math.log, but didn't work...

  • edited May 2013

    On your first issue: you are using the quotations and brackets correctly; quotations might be added around the Lum part (i.e. show_if="[Task] = 'Lum'"), but this shouldn't be necessary.

    On your colour issue: even if it seems as though your code is being commented out, it should still work. So I'm pretty puzzled why your syntax proved incorrect. Could you perhaps post the entire sketchpad script? And elaborate a bit on why it did not work? (e.g.: an error message, or a description of any unwanted behaviour).

    EDIT: the natural logarithm may be calculated the easiest via numpy's log function, which uses e as it's base (if you want 10 as your base, use log10). In code:

    # first we import numpy, so we may use it's functions
    import numpy
    
    # now we're set to do some log calculations
    some_value = numpy.log(some_other_value)
    

    Cheers!

  • edited 10:00PM

    Thanks I got everything working (including the color) but now I need to use RGB code to make several shades of gray following a formula... How can I do that?

    Also, I drew some lines on the sketchpad, and calculate other lines using pixel count. Will these work when I present them in other computers with possibly different setups (like resolution)?

  • edited 10:00PM

    I need to use RGB code to make several shades of gray following a formula... How can I do that?

    The #XXXXXX notation is RGB in disguise: It's three RGB values in hexadecimal notation (so 00 - FF, which corresponds to 0 to 255 in decimal notation) in a row. To convert a tuple of three 0 - 255 values to this hexadecimal notation, you can use Python string formatting:

    color = 255, 0, 0 # Corresponds to red
    hexColor = '#%.2X%.2X%.2X' % color
    print '%s is the same as %s' % (color, hexColor)
    

    See here:

    Also, I drew some lines on the sketchpad, and calculate other lines using pixel count. Will these work when I present them in other computers with possibly different setups (like resolution)?

    Yes, the relative proportions will be preserved.

Sign In or Register to comment.