Solution
Use a LineUp box to hold a bunch of spacer boxes to form 7-segment LED displays. Control the color of the spacer boxes to make the digits.7-segment display countdown clock
seglength = 50; // long dimension of one of the 7 segments
segwidth = 3; // narrow dimension
digitspace = 10; // padding around a 7-segment digit, left and right
padding = 40; // padding around the display, top/bot/left/right
on = HLS Color( 0.3, 0.7, 1.0 ); // green
off = HLS Color( 0, 0.2, 0 ); // gray
hseg = Spacer Box( size( seglength, segwidth ), color( on ) ); // a horizontal segment
vseg = Spacer Box( size( segwidth, seglength ), color( on ) ); // a vertical segment
corn = Spacer Box( size( segwidth, segwidth ), color( off ) ); // a corner
cent = Spacer Box( size( seglength, seglength ), color( off ) ); // a center
digit = H List Box( // a complete digit
Spacer Box( size( digitspace, 1 ) ), // space to left of digit
// lineup box, 3 wide, holds the H and V segments and other filler bits
// < H >
// V ~ V
// < H >
// V ~ V
// < H >
Lineup Box( N Col( 3 ), corn, hseg, corn, vseg, cent, vseg, corn, hseg, corn, vseg, cent, vseg, corn, hseg, corn ),
Spacer Box( size( digitspace, 1 ) ) // space to right of digit
);
dot = Spacer Box( size( 1.5 * segwidth, 1.5 * segwidth ), color( on ) );
gap = Spacer Box( size( segwidth, seglength ), color( off ) );
colon = V Center Box( H List Box( Spacer Box( size( digitspace, 1 ) ), V List Box( dot, gap, dot ), Spacer Box( size( digitspace, 1 ) ) ) );
decoder = [// which segs are on?
0 0 1 0 0 1 0, // 1
1 0 1 1 1 0 1, // 2
1 0 1 1 0 1 1, // 3
0 1 1 1 0 1 0, // 4
1 1 0 1 0 1 1, // 5
1 1 0 1 1 1 1, // 6
1 0 1 0 0 1 0, // 7
1 1 1 1 1 1 1, // 8
1 1 1 1 0 1 1, // 9
1 1 1 0 1 1 1 // 0
];
segIdx = [2 4 6 8 10 12 14];// segment subscripts in each digit
setdigit = Function( {digit, value},
{LB, iseg, decodeIdx = If( value == 0, 10, value ), codes = decoder[decodeIdx, 0]},
For( iseg = 1, iseg <= 7, iseg++,
LB = digit[Lineup Box( 1 )];
LB[Spacer Box( segIdx[iseg] )] << color( If( codes[iseg], on, off ) );
);
);
New Window( "7 segment",
Border Box( Left( padding ), Right( padding ), top( padding ), bottom( padding ),
H List Box(
hour10 = digit << clonebox,
hour1 = digit << clonebox,
colon,
minute10 = digit << clonebox,
minute1 = digit << clonebox,
colon,
second10 = digit << clonebox,
second1 = digit << clonebox
),
<<backgroundcolor( off )
)
);
target = 1jan2018; // new years eve count down if within 99 hours
lastSecond = -1;
While( 1,
Wait( .05 );
now = Today();
If( target > now > target - In Hours( 100 ),
time = target - now;
h = Floor( time / 3600 ); // for the countdown the hours can be >23
time = time - h * 3600; // adjust the time for the minutes and seconds
, // else
time = now;
h = Hour( time ); // counting up, hours does not include days, etc
);
m = Minute( time );
s = Second( time );
If( s != lastSecond,
lastSecond = s;
setdigit( hour10, Floor( h / 10 ) );
setdigit( hour1, Mod( h, 10 ) );
setdigit( minute10, Floor( m / 10 ) );
setdigit( minute1, Mod( m, 10 ) );
setdigit( second10, Floor( s / 10 ) );
setdigit( second1, Mod( s, 10 ) );
);
);