Time as float values

hello!

I’m making an ‘analog’ clock, but I want the hands of the clock to move smoothly between values, rather than snapping to the int values returned by hour(), minute(), and second()

I know I could implement something counting elapsed millis and adding them to the current second value to interpolate between one second and the next, and so on.

However I was wondering if there’s a value I can access that represents the time as an absolute value that can be remapped, or a library like dateTime in python that allows you to subtract time objects to get deltas

Thanks!

For hour you can use minutes to smooth the movement. Formula hour() + minute()/60 gives you enough precision for hour hand. Same thing with minutes minute + second()/60 Second is trickier, but that may be solved with millis(). When second() changes take value of millis() and divide difference with current millis() by 1000.
Hand for seconds might be a bit jerky, but it’s movement is so short that you probably wont notice it.
the other option is to set time at start from hour(), minute() and second() and store millis() and then work the change in time from current millis() and stored millis()

Hi
This may help

Here’s what I came up with

Works except there’s a jump after the first second / minute / hour as it doesn’t know how far through a given interval it is when it boots

Should be easy enough to fix for minute and hour, may have to live it with for second

float m;
float s;

float r = 0;

float offset1 = 0;
float offset2 = 0;

float secondMillis;
float prevSecondMillis;

float minuteMillis;
float prevMinuteMillis;

float hourMillis;
float prevHourMillis;

int prevSecond;
int prevMinute;
int prevHour;

float seed = 0;

float shortDashLength;
float longDashLength;

void setup() {
  noCursor();
  size(720, 720, P3D);
  //fullScreen(P3D);
  frameRate(60);


  textSize(50);
  //shortDashLength = 35;
  //longDashLength = 45;

  prevSecond = second();
}

void draw() {
  
  strokeWeight(1);
  shortDashLength = map(noise(seed),0,1,15,65);
  longDashLength = map(noise(seed+100),0,1,5,150);
  seed += 0.001;
  

  if (second()!=prevSecond) {
    secondMillis = 0;
    prevSecond = second();
  } else {
    secondMillis += millis() - prevSecondMillis;
    prevSecondMillis = millis();
  }

  if (minute()!=prevMinute) {
    minuteMillis = 0;
    prevMinute = minute();
  } else {
    minuteMillis += millis() - prevMinuteMillis;
    prevMinuteMillis = millis();
  }

  if (hour()!=prevHour) {
    hourMillis = 0;
    prevHour = hour();
  } else {
    hourMillis += millis() - prevHourMillis;
    prevHourMillis = millis();
  }



  s = map(second(), 0, 60, 0, TWO_PI);
  s += map(secondMillis, 0, 1000, 0, TWO_PI/60);


  m = map(minute(), 0, 60, 0, TWO_PI);
  m += map(minuteMillis, 0, 60000, 0, TWO_PI/60);
  //m += TWO_PI/60;

  h = map(hour(), 0, 12, 0, TWO_PI);
  h += map(hourMillis, 0, 60000*12, 0, TWO_PI/60);
  //h -= TWO_PI/12*2;


  background(0);
  stroke(255);

  drawDots();
  drawDashes();

  strokeWeight(1);

  pushMatrix();
  translate (width/2, height/2);
  rotate(s);
  line(0, 0, 0, (-height/2)+33);
  popMatrix();

  strokeWeight(2);

  //minute

  pushMatrix();
  translate (width/2, height/2);
  rotate(m);
  line(0, 0, 0, -height/2 + 33);
  popMatrix();

  //hour

  pushMatrix();
  translate (width/2, height/2);
  rotate(h);
  line(0, 0, 0, -height/4);
  popMatrix();


  //text

  //pushMatrix();

  //translate (width/2, height/2);
  //text(second(), 0, 0);
  //text(minuteMillis, 0, 50);
  //popMatrix();
}

void drawDots() {

  noFill();
  pushMatrix();
  translate (width/2, height/2);
  for (int i = 0; i <12; i++) {

    rotate(TWO_PI / 12);
    //circle(height/2-30, 0, 10);
    //line(height/4, 0,height/4-10, 0);
  }
  popMatrix();
}

void drawDashes() {

  pushMatrix();
  translate (width/2, height/2);
  //rotate(-TWO_PI/12*2);
  rotate(-TWO_PI/60);
  for (int i = 0; i <60; i++) {

    rotate((TWO_PI / 60));
    if (i%5==0) {
      //println(i);
      line(height/2-longDashLength, 0, height/2-30, 0);
    } else {
      line(height/2-shortDashLength, 0, height/2-30, 0);
    }
  }
  popMatrix();
}