psychopy.org | Reference | Downloads | Github

Blinking texts and images

Hi everyone!

I would like to know how I could make a text or an image to blink?

Thank you for your help!

Jessica.

@JessicaSanchezBeisel, you could try changing the opacity of the stimuli, using a sin wave function. E.g., for a shape, you set the opacity to update every repeat, and use the value

sin(t)
# or for a faster flash
sin(t*10)
# To keep values between 0 and 1 in your opacity
(.5*sin(t*10))+.5

For text, you will have to add a code component and change the contrast, like this:

# On Every Frame tab
# For full range of color contrast
text.contrast = sin(t)  
# To keep color alternating between grey and white, or whatever color
text.contrast = (.5*sin(t*10))+.5 

Hi David,

Thank you for your help.

I tried putting the function that you recommended to me in the opacity box as it follows:

Unfortunately, I had the following error:

It looks like I should define ‘t’ but I am not sure where I have to do this.

Thank you!

Jessica.

@JessicaSanchezBeisel, try setting your updates to “set every frame” for the opacity, rather than “constant”. Also, you can remove the $ sign, PsychoPy will sort that out for you.

David,

I tried with your suggestions and it worked!

I’m really grateful to you for helping me!

Have a nice day!

Jessica.

No problem, for a diffrerent style of flicker see Flickering stimuli

@JessicaSanchezBeisel, another option if you want flicker vs fade is to use a square wave instead of a sine wave. In your code component, add the following to the begin experiment tab:

from scipy import signal as sg

Fs = 44100
f = 440
sample = Fs / f
speed = 200  # Speed of flicker

Now, set your opacity of your image to the following, where updates are every frame:

sg.square(2*np.pi*f*(t*speed)/Fs, duty=.5)

@dvbridges

Hi David,
Sorry for asking a dumb question. If I want to present a stimuli for 500ms, vanish it for 200ms, present it for 500ms and vanish it 200ms again etc…(within 5s). How should I set the parameter values here?

Looking forward to your reply. Thanks in advance!