# @name Days Left # @desc Shows elapsed/remaining days of the year as a 32x8 pixel grid # @author Hank_the_Tank / Claude # @version 1.0 # @config colorDone color "Color: days elapsed" default=#00AA00 # @config colorLeft color "Color: days remaining" default=#202020 # @config highlightToday bool "Highlight today" default=true # @config colorToday color "Color: today" default=#FFFFFF class DaysLeft var colorDone, colorLeft, colorToday, highlightToday var filled # number of "elapsed" pixels, recomputed once per day var lastDay # last day() value we computed for def init() self.colorDone = store.get("colorDone") self.colorLeft = store.get("colorLeft") self.colorToday = store.get("colorToday") self.highlightToday = store.get("highlightToday") self.filled = 0 self.lastDay = -1 end def is_leap(y) return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0 end def day_of_year() var mdays = [31,28,31,30,31,30,31,31,30,31,30,31] var y = year() var m = month() var doy = day() var i = 0 while i < m - 1 doy += mdays[i] if i == 1 && self.is_leap(y) doy += 1 end i += 1 end return doy end def refresh() if hour() < 0 return end # time not known yet at boot var d = day() if d == self.lastDay return end self.lastDay = d var total = self.is_leap(year()) ? 366 : 365 var cells = width() * height() self.filled = self.day_of_year() * cells / total end def loop() self.refresh() end def draw() clear() var w = width() var idx = 0 for y : 0 .. height() - 1 for x : 0 .. w - 1 var c = self.colorLeft if idx < self.filled c = (self.highlightToday && idx == self.filled - 1) ? self.colorToday : self.colorDone end pixel(x, y, c) idx += 1 end end end end return DaysLeft()