# Making graphic of flashing lights

The following gif is from Wikipedia, lights flashing at frequencies $f=0.5 Hz$, $f=1.0 Hz$, $f=2.0 Hz$

How to make this graphic by using Mathematica?

I tried first few steps:

blackdisk = Graphics[{Black, Disk[]}, ImageSize -> 60]
graydisk = Graphics[{Gray, Disk[]}, ImageSize -> 60]

• Have you seen RunScheduledTask? Oct 6, 2016 at 13:26
• I have to admit I don't really like that this question is "how do I recreate this animation?" You probably have a more fundamental issue, such as "how do I evaluate an expression every nth second." The question should be about what you don't know, there's no point in creating a project around it and asking people to complete that project. Oct 6, 2016 at 13:46
• Perhaps Dynamic + UpdateInterval would be of use. Oct 6, 2016 at 14:01
• @ChipHurst Perhaps in practice, but conceptually it's not very good because UpdateInterval only promises to update "at least" every t seconds. That's why I recommended RunScheduledTask, which is exact. Oct 6, 2016 at 15:50

Dynamic[
t = Clock[{1/3, 8, 1/3}, 2];
Graphics[{
{GrayLevel[0.5 Boole[Mod[t, 8] == 0]], Disk[{0, 1}, 0.2]},
{GrayLevel[0.5 Boole[Mod[t, 4] == 0]], Disk[{0, 0}, 0.2]},
{GrayLevel[0.5 Boole[Mod[t, 2] == 0]], Disk[{0, -1}, 0.2]}
}]
]


• thanks. can you add Epilog on the right side?
– vito
Oct 6, 2016 at 15:37
• @vito, like this? Oct 7, 2016 at 13:46
• @JasonB yes, like this
– vito
Oct 7, 2016 at 14:59

It seems the best way to get an actually smoothly timed graphic is to make a gif..

blackdisk = Graphics[{Black, Disk[]}, ImageSize -> 60]
graydisk =
Graphics[{Black, Disk[], GrayLevel[.7], Disk[{0, 0}, .9]},
ImageSize -> 60]
Export["test.gif",
Table[Column[
Table[Blend[{blackdisk, graydisk},
N@Abs@Sin[n t]], {n, {1, 2, 4}}]], {t, 0, Pi, Pi/20}],
"DisplayDurations" -> 1/20]


Incidentally, Blend balks at exact parameter values for no evident readson:

Blend[{blackdisk, graydisk}, Sin[Pi/20]]


Sin[[Pi]/20] should be a real number or a list of non-negative numbers