add an optional second hand to the clock. this can be useful for human-scale timing. Reference: /n/atom/patch/applied2013/clocks Date: Sun Oct 27 00:46:43 CES 2013 Signed-off-by: quanstro@quanstro.net --- /sys/src/cmd/clock.c Sun Oct 27 00:45:54 2013 +++ /sys/src/cmd/clock.c Sun Oct 27 00:45:54 2013 @@ -3,9 +3,11 @@ #include #include -Image *hrhand, *minhand; +Image *hrhand, *minhand, *sechand; Image *dots, *back; +int flags; + Point circlept(Point c, int r, int degrees) { @@ -25,7 +27,7 @@ static int rad; static Image *im; int i; - int anghr, angmin; + int anghr, angmin, angsec; static Tm tms; static Tm ntms; @@ -36,6 +38,7 @@ ntms = *localtime(ntm); anghr = 90-(ntms.hour*5 + ntms.min/12)*6; angmin = 90-ntms.min*6; + angsec = 90-ntms.sec*6; tm = ntm; tms = ntms; r = screen->r; @@ -48,6 +51,8 @@ for(i=0; i<12; i++) fillellipse(screen, circlept(c, rad, i*(360/12)), 2, 2, dots, ZP); + if(flags) + line(screen, c, circlept(c, (rad), angsec), 0, 0, 1, sechand, ZP); line(screen, c, circlept(c, (rad*3)/4, angmin), 0, 0, 1, minhand, ZP); line(screen, c, circlept(c, rad/2, anghr), 0, 0, 1, hrhand, ZP); @@ -63,7 +68,14 @@ } void -main(int, char**) +usage(void) +{ + fprint(2, "usage: clock [-s]\n"); + exits("usage"); +} + +void +main(int argc, char **argv) { Event e; Mouse m; @@ -72,17 +84,32 @@ int key, timer; int t; + ARGBEGIN{ + case 's': + flags ^= 1; + break; + default: + usage(); + }ARGEND + if(argc != 0) + usage(); + if (initdraw(0, 0, "clock") < 0) sysfatal("initdraw failed"); back = allocimagemix(display, DPalebluegreen, DWhite); hrhand = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DDarkblue); minhand = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPaleblue); + sechand = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xbbbb); dots = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DBlue); redraw(screen); einit(Emouse); - t = (30*1000); + if(flags) + t = 1000; + else + t = 30*1000; + timer = etimer(0, t); menu.item = mstr; --- /sys/man/1/date Sun Oct 27 00:45:54 2013 +++ /sys/man/1/date Sun Oct 27 00:45:54 2013 @@ -10,6 +10,9 @@ ] .br .B clock +[ +.B -s +] .SH DESCRIPTION Print the date, in the format .PP @@ -36,7 +39,9 @@ the real time. .PP .I Clock -draws a simple analog clock in its window. +draws a simple analog clock in its window. The +.B -s +option adds a second hand. .SH FILES .TF /adm/timezone/local .TP