> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.eOneUTM1ekm/rev.428
 * 
 * authors: 
 *   Fergus Ray Murray
 *   
 *   

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



// This sketch builds on a prior work, "Chrono-Synclastic Curlicue Calendar (featuring the Mayan Long Count)", created by Fergus Ray Murray
// http://studio.sketchpad.cc/sp/pad/view/ro.9r12DqIHXiPMS/rev.994
  // This sketch builds on a prior work, "Chronosynclastic Curlicue Clock", created by Fergus Ray Murray. Mayan Long Count added with the help of Comotion from Hackeriet.
  // http://studio.sketchpad.cc/sp/pad/view/ro.9PXzsGOaaeT-z/rev.41
  // http://studio.sketchpad.cc/sp/pad/view/ro.9v7e1McEGqXQs/rev.207
  // http://studio.sketchpad.cc/sp/pad/view/ro.9UGEP6aVRfP9j/rev.29
  /* Here's a fun mating of the Curlicue fractal with a clock. The seed for the fractal is taken from the exact time of day. You can watch the build-up and wind-down that surrounds major landmarks of the day - mid-day, four thirty and so on 
   - and at the exact moment they pass, the form dramatically simplifies. This is because those times are relatively simple fractions of the way through the day. */
   
  float x, y, f, stepSize=28; // Each seed value gives a different fractal.
  double df=0, ddf=0, dddf=0.000000005; // dddf controls how much the fractal changes with each frame.
  int i=0;
  Date rightNow=new Date();
  
  // August 11, 3114 BCE - start of long count
  //int startTime=(int)Date.UTC(2012,11,21,0,0,0)-(int)rightNow.getTime();
//  long startTime=Date.UTC(rightNow.getTime() - 3114, 8 ,11,0,0,0)-(int)rightNow.getTime();
//  long startTime =rightNow.getTime() - Date.UTC(-3114, 8, 11, 0, 0, 0);                                                      
  long startTime=Date.UTC(-3114,8,11,0,0,0)-rightNow.getTime();
  
  long baseTime=Date.UTC(-3114,9,11,0,0,0);
  
  //startTime=3600*hour()+60*minute()+second(); // How many seconds since midnight?
  void setup() { // 'setup' is called just once, when the program is run.
    size (600, 600); // Tell Processing how big a window it should use.
    //startTime=3600*hour()+60*minute()+second(); // How many seconds since midnight?
    colorMode (HSB, 360);
    background (0);
    frameRate (20);
  }
  void draw() { // 'draw' is called every time the program draws a frame.
    // We need to reset most of the variables every frame.
    strokeWeight(2);
   
    fill(0, 6);
    stroke(255);
    rect(0, 0, width, height);
    //translate(-width/2,-height/2);
    //scale(1);
    Date newDate=new Date();
    float daysSinceBeginning=(newDate.getTime()-baseTime)/86400000.0;
    ddf=TWO_PI*daysSinceBeginning; 
/*
1                 1 Kin         
20                20 Kin                1 Uinal         
360               18 Uinal        1 Tun        ~ 1
7,200             20 Tun          1 Ka'tun        19.7
144,000           20 Ka'tun       1 Bak'tun        394.3
2,880,000         20 Bak'tun      1 Pictun        7,885
57,600,000        20 Pictun       1 Kalabtun        157,808
1,152,000,000     20 Kalabtun     1 K'inchiltun        3,156,164
23,040,000,000    20 K'inchiltun  1 Alautun        63,123,288
*/
// Clock hand:
// if (frameCount%5==0){
    stroke(360, 12); 
    strokeWeight(8);
    float angle=TWO_PI*(float)(second()-15)/60;
    line (
      width/2+width/2.2*cos(angle),
      height/2+width/2.2*sin(angle),
      width/2+width/2*cos(angle),
      height/2+width/2*sin(angle));
//    }
    // base rate of change // length // scale // start color // range of colors // period (every f frames)
//    curlicue (ddf*1440,12, 64.0, 0, 30, 10); // seconds (1 rev/minute)     
//translate (-240, 0);
  
    curlicue (ddf*1440,4, 120.0, 240, 30, 0, 60); // seconds (1 rev/minute)     
    //curlicue (ddf*1440,24, 32.0, 15, 45, 2); // seconds (1 rev/minute)     
    //curlicue (ddf*1440,2, 256.0, 0, 30, 3); // seconds (1 rev/minute)     
    curlicue (ddf*24,  60, 12.0, 80, 65, 2, 240); // minutes (1 rev/hour)
    curlicue (ddf,     120, 16.0, 150, 90, 3, 360);  // kin (1/day)  
    curlicue (ddf/20,  360, 6.0, 23, 13, 30); // uinal (20 days)
    curlicue (ddf/360, 360, 5.0, 90.0, 42.0,  20); // tun (360 days)
    //curlicue (ddf/365.2499, 360, 3.0, 132, -42, 20); // date (1 rev/year)
    //curlicue (ddf/7200, 360, 2.0, 44.0, 97.3,  120); // ka'tun (7200 days)
    curlicue (ddf/144000, 360, 24.0, 84.0, 97.3,  180, 260); // bak'tun (144000 days)
    //curlicue (ddf/2880000, 360, 1.3, 23, 1337,  480); // pictun (2,880,000 days)
/*    curlicue (ddf/57600000, 360, 2, 38.0, 355, 15,  960); //  kalabtun (57,600,000 days)
    curlicue (ddf/1152000000, 360, 2, 14925, 787, 16,  1920); //  k'inchiltun (1,152,000,000 days)
    curlicue (ddf/23040000000, 160, 3,    5, 24, 32, 3840); //  kalabtun (23,040,000,000 days)
    int procession = 360/26000;*/
  }
  void curlicue(double ddf, int curlLength, float stepSize, float baseHue, float hueRange) {
    curlicue( ddf, curlLength, stepSize, baseHue, hueRange, 1);
  }
  void curlicue(double ddf, int curlLength, float stepSize, float baseHue, float hueRange, int period) {
    curlicue( ddf, curlLength, stepSize, baseHue, hueRange, period, 360.0);
  }
  void curlicue(double ddf, int curlLength, float stepSize, float baseHue, float hueRange, int period, float saturation) {
    //translate (60,0,0);
    //if (frameCount%period==0||period==1){
    f=0;
    df=0;
    x=width/2;
    y=height/2;

    for (i=0; i<curlLength; i+=1) { 
      float ox=x;
      float oy=y;
      if (abs(-frameCount+i)%period==1||period==1){
      strokeWeight (stepSize/2);

      point(x, y);
      if (i>0) point(width-x, height-y); // draw 180 mirror, except the first

      }
      else {
         // rect(width-x, height-y, 3, 3);
          }
    //}
      df+=ddf;
      f+=df;
      x+=stepSize*sin(f);
      y-=stepSize*cos(f);
      strokeWeight(2);
      stroke (baseHue+((float)i/curlLength)*hueRange, saturation, 360, 108);      
      //if (period==0){
      if (abs(-frameCount+i)%period==1||period==0){
          line (x,y,ox,oy);
          line (width-x,height-y,width-ox,height-oy);
      }
    }
  }
   
  void keyPressed() {
    if (key=='s') save("Chrono-"+hour()+"-"+minute()+"-"+second()+"-"+millis()+".png");
  }