Sometimes eccentric, often inconspicuous

14 July 2013

Whatever you prefer

Already since 20 November 2002, the eccentric, crazy, weird, unethical and irritating colours on my website are switchable. Website visitors can click a link that is present in many but not all pages, to indicate that they’d rather have quiet, dull, normal, acceptable, aesthetic colours. Then a cookie is set to remember their preference.

Especially for me, the only person in the world who likes the crazy colours, because I personally and specially designed them, there is also a link to establish a preference for eccentricity. (Press F5, or a similar button that works in your browser, to make the choice effective, by having the page reloaded.)

Today on 14 July 2013, I added a third possibility, only here in this article for now, to reset (i.e. remove) the cookie. Technically, that works by setting the cookie with an expiration date in the past.

Default

The question that remains is, what do people get when they don’t explicitly say want they want, or if they’d rather not have any cookies set?

Until 26 August 2011 the default value was: crazy colours. I got complaints, and I decided to make boring and flat the default. But due to some rather stupid choices in 2002, strangely, it wasn’t easy to change that. Eventually, I succeeded.

I wrote about that episode in this article. Only in Dutch and no English translation is to be expected, because the story was intimately tied to some Twitter encounters in Dutch.

So the default was then the quiet colours, but I changed my mind back and forth several times after that.

Time switched

Then on 21 April 2013 I got this idea, that I implemented two days ago (12 July 2013): part of the day, say 33%, those without a preference would get my website as it was designed, with the wild colours. The rest of the day, boredom would strike again.

The period over which this is switched is 7 hours, for example, deliberately chosen such that 24 is not a multiple of that period, so that the hours with the weird colours gradually shift over day and night in the course of weeks.

To strengthen that effect, some randomising is involved in the calculations.

That’s about all I have to say about it. The rest of it, in case anybody is interested, which would surprise me, can be found in the source text of the function I added to the existing little C program. I publish that function hereinbelow.

Source code

/***********************************************************************
   This function was added 12 July 2013. 

   The idea is that those who did not click a link to explicitly ask for 
   either weird or dull colours, will get weird colours some 33% of the 
   time, and dull colours the remaining 67%. This is switched in an 
   approx. 7 hour scheme, so it traverses slowly through night and day. 
   Exact switchover times are severely randomised to get a surprise 
   element into it.

   To make it efficient, the program does not read data from the status
   files WeirdOnn and WeirdOff, but instead only enquires (using the 
   'stat' function) about their latest modification date. That's why 
   there are two different status files, instead of only one with a 
   yes/no content. 
   The file that was most recently updated/recreated ("touched")
   determines which colour scheme the website visitor will get to see.

   Users who clicked a colour link and had a cookie set, will not be
   affected by all this. They always just get the colour scheme they 
   prefer and asked for.
 ***********************************************************************/

 
static char *WeirdOnnFilename = "colschem/WeirdOnn";
static char *WeirdOffFilename = "colschem/WeirdOff";

#define DRAND() ((double)random() / (double)0x7fffffffL)
#define SRAND() (srandom((unsigned long)(getpid() + getppid() + time(NULL))))

/* Parameters, all times in seconds */

#define FractionWeird 0.33
#define RandomFactor  0.45
#define SwitchPeriod (7L*60*60) 
#define CoolingOff (SwitchPeriod * FractionWeird * (1.0 - RandomFactor))

int VariableInTime (void)
{
   struct stat WeirdOnnStat, WeirdOffStat;
   time_t TimeNow;
   FILE *fp;
   int Weird;

   if (stat(WeirdOnnFilename, &WeirdOnnStat) != 0 ||
       stat(WeirdOffFilename, &WeirdOffStat) != 0)
   {
      /* Initial create of two empty colour setting control files.
         They're empty because only the stat data (modification
         date) matters.
       */
      fp = fopen(WeirdOnnFilename, "w");
      if (fp) fclose(fp);
      fp = fopen(WeirdOffFilename, "w");
      if (fp) fclose(fp);
   }

   if (WeirdOnnStat.st_mtime > WeirdOffStat.st_mtime)
   {
      Weird = 1; /* Don't filter, so display weird colours */
   }
   else
   {
      Weird = 0;
   }

   /* Is it time to switch over? */
   time(&TimeNow);

   if ((Weird && (TimeNow - WeirdOnnStat.st_mtime < CoolingOff)) ||
      (!Weird && (TimeNow - WeirdOffStat.st_mtime < CoolingOff)) )
   {
      ; /* Do nothing the first 20 or so minutes after a switch-over, to make
           it more efficient */
   }
   else
   {
      time_t TimeToSwitch;

      SRAND();   

      if (Weird)
      {
         TimeToSwitch = FractionWeird * (float)SwitchPeriod; 
         TimeToSwitch *= 1.0 + (RandomFactor * (DRAND() * 2 - 1.0)); 
         TimeToSwitch += WeirdOnnStat.st_mtime;
      }
      else
      {
         TimeToSwitch = (1.0 -  FractionWeird) * (float)SwitchPeriod;
         TimeToSwitch *= 1.0 + (RandomFactor * (DRAND() * 2 - 1.0)); 
         TimeToSwitch += WeirdOffStat.st_mtime;
      }

      // printf("/* TimeToSwitch %ld, TimeNow %ld */\n", TimeToSwitch, TimeNow);

      if (TimeToSwitch <= TimeNow)
      {
         fp = fopen(Weird ? WeirdOffFilename : WeirdOnnFilename, "w");
         if (fp) fclose(fp);
         Weird = !Weird;
      }
   }
  
   return !Weird; /* Weird = don't filter, Dull = do filter, hence the ! */
}

Colours: Neutral Weird No preference Reload screen