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;
segwidth = 3;
digitspace = 10;
padding = 40;
on = HLS Color( 0.3, 0.7, 1.0 );
off = HLS Color( 0, 0.2, 0 );
hseg = Spacer Box( size( seglength, segwidth ), color( on ) );
vseg = Spacer Box( size( segwidth, seglength ), color( on ) );
corn = Spacer Box( size( segwidth, segwidth ), color( off ) );
cent = Spacer Box( size( seglength, seglength ), color( off ) );
digit = H List Box(
Spacer Box( size( digitspace, 1 ) ),
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 ) )
);
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 = [
0 0 1 0 0 1 0,
1 0 1 1 1 0 1,
1 0 1 1 0 1 1,
0 1 1 1 0 1 0,
1 1 0 1 0 1 1,
1 1 0 1 1 1 1,
1 0 1 0 0 1 0,
1 1 1 1 1 1 1,
1 1 1 1 0 1 1,
1 1 1 0 1 1 1
];
segIdx = [2 4 6 8 10 12 14];
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;
lastSecond = -1;
While( 1,
Wait( .05 );
now = Today();
If( target > now > target - In Hours( 100 ),
time = target - now;
h = Floor( time / 3600 );
time = time - h * 3600;
,
time = now;
h = Hour( time );
);
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 ) );
);
);