Howdy, Stranger!

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

Supported by

[solved] Use RGB_hex values to change colour of an object?

edited September 2013 in OpenSesame

I've been exploring the modules available in OS as I'm trying to find a way to change the colour of an object at a predetermined time in an experimental session (i.e. on the 10th presentation of a pair of words, they will both turn from black to 'colour A', and various variations thereof.

Is there a built-in class/module which has this function? Or perhaps another method I haven't considered?

Thanks

Lee

Comments

  • edited 3:33AM

    Hi Lee,

    Do I understand correctly that you want to use a variable color for an element of a sketchpad? This can be done quite easily, by entering a variable name (between square brackets) into the color field of the sketchpad tab.

    Let's say that you have a variable my_color, which defines the color of a text element. You then enter [my_color] into the sketchpad color field and draw some text. That's it, basically. Of course, you have to make sure that the variable my_color actually exists, typically by defining it in a loop item.

    See also:

    Does this answer your question?

    Cheers,
    Sebastiaan

  • edited 3:33AM

    Thanks for the reply Sebastiaan (loving OS btw, although learning python is a challenge)

    I currently have an ongoing task that presents 50 random word pairs through some elegant inline scripting (thanks largely to Lotje: http://forum.cogsci.nl/index.php?p=/discussion/469/solved-selective-sampling-with-a-ratio-help-please#Item_14).

    I need to incorporate some prospective cues into the task, one of which would be both word pairs changing colour at the same time (i.e. on presentation 'n' of 50 the pair turns purple). As you can see from the code I'm using (as provided by Lotje) I'm not sure that the method you've suggested would have the required effect...

    I would like to add it to the script as I think it will be easier in the long run, but I'm still familiarising myself with the modules etc... available in Python and OS so I'm not wholly confident that I'm on the right track.

    Any ideas would be great (although I am endeavouring to learn so a push in the right direction would be preferable to direct solutions).

    I can email the main file if it will be easier.

    Thanks!

    Lee

  • edited August 2013

    Hi Lee,

    I don't understand completely how you want to manipulate the text color of your word pairs. But in general I think you can do this via the graphical interface or via an inline_script item. Both should work fine.

    Via the graphical interface:

    Step 1: define the color variable:
    Add a column (e.g. 'text_color') to your block loop item and give this variable the desired value per trial (e.g. 'purple' for every fifth trial, and 'black' for all the other trials). Note that this method only works if you set the order of your block loop to 'sequential' rather than 'random'.

    image

    Step 2: use the color variable for drawing the stimuli:
    Next, you can use the in-the-loop-defined variable in your sketchpad item with the square-bracket method (as suggested by Sebastiaan in the thread above). More specifically, change the OpenSesame script (not to be confused with Python inline scripting) in your 'trial_display' sketchpad as you did for the variables 'word1' and 'word2'.

    image

    Via an inline_script item:

    Step 1: define the color variable:
    Add something like the following code to the end of your inline_script item (see comments for more details):

    # Let's say that we want the words to be shown in purple
    # on every fifth trial, and in black for all other trials.
    
    # Determine the current trial count by 'getting' the built-in
    # OpenSesame variable 'count_[to-be-counted-variable]'.
    
    # We do this by using the self.get() function.
    # For more info:
    # http://osdoc.cogsci.nl/python-inline-code/experiment-functions/#experiment.get
    
    # Note that we add 1 because Python starts counting at 0:
    trial_count = self.get('count_trial_sequence') + 1
    
    # Use the modulo operator to only set the variable 'text_color' to purple
    # for every fifth trial.
    # (Change the evaluation in whatever you want.)
    if trial_count % 5 == 0:
        text_color = "purple"
    
    # For all other trials the words will be presented in black:
    else:
        text_color = "black"
    
    # Finally, set the newly-made variable 'text_color' for future use in the GUI
    # (e.g. a sketchpad item):
    # For more info:
    # http://osdoc.cogsci.nl/python-inline-code/experiment-functions/#experiment.set
    exp.set("text_color", text_color)
    

    The advantage of this method is that it works even when you set the order of your block loop to random.

    Step 2: use the color variable for drawing the stimuli:
    As Step 2 above.

    I hope this helps! If not, could you perhaps specify how you want to manipulate the color change?

    Best,

    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • edited 3:33AM

    Lotje,

    The first method looks like it should work and I can apply it to other similar cues.

    Awesomely helpful as always!

    Thanks,

    Lee

  • edited 3:33AM

    ... further to prior posts I have to add a small query about this experiment:

    http://pastebin.com/wtqZUPuq

    As you can tell, I'm trying to get an additional keyboard response of 'g' on the two occasions when the variable 'frame_colour' is green.

    I tried with one keyboard response item and the program was just confused between g, m, and z, assigning random responses everywhere!

    I then thought "parallel keyboard responses that go into the same logger file". The word pair side seems to work (the 'kr_script' bit) and the other ('s1_cue_kr_script') also seems okay.

    I think that I need to independently link the keyboard response objects with their respective inline scripts (i.e. kr_script+kr and s1_cue_kr_script+s1_cue_kr), but I'm not sure how I might make it happen.

    If you run the experiment you'll probably see the problem immediately, any ideas on what I've missed would be great!

    Thanks,

    Lee

  • edited 3:33AM

    Realised I haven't actually stated the symptom! Essentially the 's1_cue_kr_script' variable isn't being recorded properly....

  • edited August 2013

    Just noticed that this has been reopened! Because this was marked as solved and also because I have been tinkering since, I have started a new thread here with a clearer update (and pictures! and code!)

    ... So this can probably be closed :)

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games