Ok, I’ve got a change I like…
this uses my idea of extra pixels to convey a second hand change every second
// better smooth clock by ScruffyNerf
// written for https://forum.electromage.com/t/how-to-force-a-value-to-be-an-integer/814
// built for a 24 pixel circle. Clocks are much easier with 30 pixels, or 12 even... 60 is ideal.
export var sec = 0;
export var min = 0;
export var hour = 0;
export var secpixel = 0;
export var secpixel2 = 0;
export var minpixel = 0;
export var hourpixel = 0;
// pick your own colors if you want
var hrColor = array(3);
hrColor[0] = 1 // this is a cheat, array is all zeros otherwise, but let's default to Red, Green, Blue pointers
export function rgbPickerHoursColor(r, g, b){
hrColor[0] = r
hrColor[1] = g
hrColor[2] = b
}
var minColor = array(3);
minColor[1] = 1
export function rgbPickerMinutesColor(r, g, b){
minColor[0] = r
minColor[1] = g
minColor[2] = b
}
var secColor = array(3);
secColor[2] = 1
export function rgbPickerSecondsColor(r, g, b){
secColor[0] = r
secColor[1] = g
secColor[2] = b
}
export function render(index) {
// what time is it?
sec = clockSecond(); // values from 0-59
min = clockMinute(); // values from 0-59
hour = clockHour(); // values from 0-23
//let's convert these to fit 24 pixels nicely
// hours would seem easy, except we don't want a 24 hour clock, we want a 12 hour clock
hourpixel = (hour%12) * 2
//that will fold it in half, mod12 aka %12 turns 12 into 0, 13 into 1, etc...
// our pixels start at 0, but we need to light pixel 2 for 1 o'clock, pixel 4 for 2 o'clock, etc. so double it
if (min > 29) {
// if we are past 29 minutes, add one more, so the hour hand/pixel will move on the half-hour
hourpixel++
if (hourpixel>23) { hourpixel = 0} // catch the wrap around exception at 24/0
}
// seconds and minutes have to fit 60 into 24... or every 2.5 minutes
minpixel = floor(min/2.5) // floor rounds down
if (min%5 == 2 && sec > 29) {
// if we're in minute 2 out of every five, and more than 30 seconds, add one, to shift on time.
minpixel++
if (minpixel>23) { minpixel = 0} // catch the wrap around exception at 24/0
}
//seconds is the hard one...
//the eye can see the sweep 'stutter' irregularly
// we don't have 60 pixels to get 1 per second
// but can we fake smoothly 60 seconds with 24 pixels?
// not well with the existing clock functions it seems...
// sec 0: X00
// sec 1: xx0
// sec 2: xX0
// se2.5: 0X0 - never can do this
// sec 3: 0Xx
// sec 4: 0xx
// sec 5: 00X
secpixel = floor(sec/2.5) // floor rounds down, this is actual seconds
secpixel2 = secpixel // same location, as default
mainbrightness = 1;
secondbrightness = .05;
cycle = sec%5 // we get a cycle of 5 positions as above...
if (cycle == 1 || cycle ==3) {
secpixel2 = secpixel + 1 // add a pixel after...
if (secpixel2 > 23) { secpixel2 = 0 } //catch the overflow at 24/0
}
if (cycle == 2 || cycle == 4) {
secpixel2 = secpixel //the earlier pixel is less bright
secpixel++ // brighter pixel is added here
if (secpixel > 23) { secpixel = 0 } // catch the overflow at 24/0
}
// Set the pixel for the second, then the minute, then the hour
if (index == hourpixel) {
rgb(hrColor[0],hrColor[1],hrColor[2]);
} else if (index == minpixel) {
rgb(minColor[0],minColor[1],minColor[2]);
} else if (index == secpixel2 && secpixel2 != secpixel) {
rgb(secColor[0]*secondbrightness,secColor[1]*secondbrightness,secColor[2]*secondbrightness);
} else if (index == secpixel) {
rgb(secColor[0]*mainbrightness,secColor[1]*mainbrightness,secColor[2]*mainbrightness);
} else {
// none of the above, so we can turn it off
rgb(0, 0, 0);
}
}
I’ll likely change this later to use HSV instead of RGB, and also add some color blending when pixels overlap… the second hand sweep could be improved by varying the brightness more… making it seem to move more fluidly… but it was a proof of concept.
And It’ll make it generic (so it’ll work on any size ring) and then I’ll post that into my github PB repo (and add it to the pattern repo…