4

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]
Karsten7
  • 27,448
  • 5
  • 73
  • 134
abwatson
  • 1,919
  • 1
  • 12
  • 19

1 Answers1

2

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

Karsten7
  • 27,448
  • 5
  • 73
  • 134
  • One could add an automatic color switch to White after 30 seconds to the If statement resetting the clock. – Karsten7 Jul 07 '15 at 23:28
  • This appears to be just what I need. Thanks! – abwatson Jul 08 '15 at 23:17
  • Also, I should know this, but how do you create the animation of the manipulate? – abwatson Jul 09 '15 at 04:29
  • @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. – Karsten7 Jul 09 '15 at 10:50