1
$\begingroup$

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

enter image description here

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]
$\endgroup$
4
  • $\begingroup$ Have you seen RunScheduledTask? $\endgroup$
    – C. E.
    Oct 6, 2016 at 13:26
  • 6
    $\begingroup$ 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. $\endgroup$
    – C. E.
    Oct 6, 2016 at 13:46
  • $\begingroup$ Perhaps Dynamic + UpdateInterval would be of use. $\endgroup$
    – Greg Hurst
    Oct 6, 2016 at 14:01
  • $\begingroup$ @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. $\endgroup$
    – C. E.
    Oct 6, 2016 at 15:50

2 Answers 2

5
$\begingroup$
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]}
   }]
 ]

enter image description here

$\endgroup$
3
  • $\begingroup$ thanks. can you add Epilog on the right side? $\endgroup$
    – vito
    Oct 6, 2016 at 15:37
  • 4
    $\begingroup$ @vito, like this? $\endgroup$
    – Jason B.
    Oct 7, 2016 at 13:46
  • $\begingroup$ @JasonB yes, like this $\endgroup$
    – vito
    Oct 7, 2016 at 14:59
2
$\begingroup$

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]

enter image description here

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.