4
$\begingroup$

The code below is to demonstrate color afterimages. The user chooses a color, fixates the changing number at the center until it reach 30 (seconds), then manually switches to white to observer the aftereffect. It works fine, but I would like the clock to reset every time a new color is selected. I can't get that to happen. The Refresh code is one attempt, but it does not work. Suggestions?

Manipulate[
 Graphics[{
   color, Rectangle[{-1, -1}/2, {1, 1}/2]
   , White, Rectangle[{-1, -1}/4, {1, 1}/4]
   , If[color === White, White, Black]
   , Dynamic[
    Refresh[Text[Round[Clock[30]], {0, 0}], 
     TrackedSymbols :> {color, size}]]
   }, ImageSize -> size]
 , {color, {Red, Green, Blue, Yellow, White}}
 , {size, 64, 256}
 , ContentSize -> { 256, 256}
 , Alignment -> Center]
$\endgroup$

1 Answer 1

2
$\begingroup$

I think it's easier to create the counting clock by using Refresh without Clock:

Manipulate[Graphics[{color, Rectangle[{-1, -1}/2, {1, 1}/2], White, 
    Rectangle[{-1, -1}/4, {1, 1}/4], If[color === White, White, Black], 
    Dynamic[Refresh[Text[If[Round[AbsoluteTime[] - refTime] > 30, 
         refTime = AbsoluteTime[]]; Round[AbsoluteTime[] - refTime], {0, 0}], 
      UpdateInterval -> 1]]}, ImageSize -> size], 
  {color, {Red, Green, Blue, Yellow, White}, TrackingFunction -> 
    ((color = #1; refTime = AbsoluteTime[]; ) & )}, 
  {size, 64, 256, TrackingFunction -> ((size = #1; refTime = AbsoluteTime[]; ) & )}, 
  {{refTime, AbsoluteTime[]}, None}, ContentSize -> {256, 256}, Alignment -> Center]

GIF

$\endgroup$
4
  • $\begingroup$ One could add an automatic color switch to White after 30 seconds to the If statement resetting the clock. $\endgroup$
    – Karsten7
    Jul 7, 2015 at 23:28
  • $\begingroup$ This appears to be just what I need. Thanks! $\endgroup$
    – abwatson
    Jul 8, 2015 at 23:17
  • $\begingroup$ Also, I should know this, but how do you create the animation of the manipulate? $\endgroup$
    – abwatson
    Jul 9, 2015 at 4:29
  • $\begingroup$ @abwatson I created the GIF shown in this answer using a screen recording software. It's often the most convenient way and has the advantage, that the mouse curse is visible. However, in this answer a way to create an animation using Mathematica is described. But in this case with a clock its even harder to produce a proper animation using Mathematic directly, one probably has to use Pause and Rasterize to get a correct clock. $\endgroup$
    – Karsten7
    Jul 9, 2015 at 10:50

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.