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!

Greetings from the future!

I am trying to make an “anomoloscope” using a variation on your method, but I can’t get it to go fast enough.

Real anomoloscopes use 3 lamps: a yellow matching lamp and a red and green lamp that are close enough together that they normally create a yellow colour. Participants alter the balance of red and green with a variable resistor until it matches the yellow lamp. Red and green’s currents should be about equal but colour blind people will make mistakes. You can’t do this on a computer display, though.

Instead, I have a red rectangle and a green rectangle that should alternate fast enough (<50kHz?) to fuse and appear as yellow. I have a circle overlaying the rectangle that is yellow (with some random variation). The idea is that people will adjust the circle’s colour (<-/-> keyboard presses) until it matches the rectangle’s artificial yellow created by the red/green flashes.

I used your Code Component and the code for the opacity. The second rectangle’s opacity is set to -1* the value to make it out-of-phase with the first. This works at your speed = 200 value and increasing the speed, does increases the flicker rate, but it seems to max-out at too low a rate. It also seems to pause every so often.

I also tried using the sine-wave method, which also maxed out.

Do you have any idea how I can get this to work? TIA

Anomoloscopy.psyexp (61.5 KB)

Personally, if your red and green rectangle never appear together, I would recommend using a single polygon for them and change the colour in a code component every X frames.

Thank you. Yes, that’s what I’ve tried here.

I’ve since adapted the code to be based on the modulo of 2 for the variable “frameN”, which AFAIK is the frame rate. This generates alternating 0s and 1s, which can be used to set the opacity of the red and green rectangles.

It does produce very rapid red and green alternating rectangles, which blur slightly; but it doesn’t really produce a fully-fused yellow. I’m using an iMac, which is surprising difficult to find the refresh-rate of; but I believe it’s 60Hz. I thought critical flicker fusion was lower than that so maybe it’s an artefact of the display. One of my vision-science colleagues thought I’d stand a better chance with a CRT display and maybe a gaming PC with a faster refresh-rate.