Sunrise Alarm Clock Pattern

Sunrise Alarm Clock.epe (13.7 KB)

I had a lot of fun writing this pattern to play a little sunrise and sunset and then show something for the rest of the day. Some of it’s probably generally useful as well:

Pattern starts by playing a demo
Because the pattern itself depends on the time of day, and the example isn’t very illustrative of the appearance or effect, I set the pattern to play a quick demo to record the ~10s that gets shown as the preview. This was also useful for testing.

Sunrise

Track milliseconds for smoother operation
One barrier to driving a pattern purely based on the time of day is we only get time functions with resolution down to 1 second, which creates a very slow frame rate. If we’re tracking hours, the 16 bits after the decimal leaves room for 50ms increments. I count milliseconds and syncronize to observations of second rollovers, and then construct a time of day with as much resolution as I can store in hours.

// Getter for ms analagous to clockSecond()
function clockMs() {
  return _ms
}
{
  var _ms
  var _lastSecond
  // Update ms based on delta and observations of clockSecond rollover events
  // Called by beforeRender
  function updateMS(delta){
    if (_lastSecond == clockSecond()){
      _ms+=delta
    } else {
      _lastSecond = clockSecond()
      _ms = min(delta,_ms%1000)
    }
  }
}

I think I can get better resolution in time of day by tracking time of day in minutes (seconds would overflow)

2 Likes

I’ve posted some updates to the source on GitHub: Sunrise Alarm Clock

Sunrise Alarm Clock 1.3.epe (17.2 KB)

I just pushed a new version:

  • 3 step sunrise to play a bit more with pinks and oranges.

  • Sunsets simply reversed sun-rises to make everything a bit easier to track.

  • Configurable time spent performing sunrises

  • Better preview rendering (to help debug)

  • Set wake and sleep times with hours and minutes

  • Clouds and sky far from low sun darkened

  • Low sun changes colors

1 Like

I just realized I can use

export function inputNumber(v){
    ...
}

and

export function inputNumber_(v){
    ...
}

Because the underscore isn’t printed but is part of the name, I can get multiple controls with the same text to set minutes and pairs of colors…
Yay!

1 Like