// I never liked the dots #include #include #include #include #include "colorclock.h" int thick = 2; // hands and ring int segsi[] = {Red67, Orange67, Yellow67, YellowGreen67, Green67, Aqua67, Cyan67, BrightBlue67, Blue67, BluePurple67, Magenta67, Pink67, }; Image *hrhand, *minhand; Image *back, *segs[12], *segs2[12]; Point circlept(Point c, int r, int degrees) { double rad; rad = (double) degrees * PI/180.0; c.x += cos(rad)*r; c.y -= sin(rad)*r; return c; } void redraw(Image *screen) { static int tm, ntm; static Rectangle r; static Point c; static int rad; static Image *im; int i; int anghr, angmin; static Tm tms; static Tm ntms; ntm = time(0); if(ntm == tm && eqrect(screen->r, r)) return; ntms = *localtime(ntm); anghr = 90-(ntms.hour*5 + ntms.min/12)*6; angmin = 90-ntms.min*6; tm = ntm; tms = ntms; r = screen->r; c = divpt(addpt(r.min, r.max), 2); rad = Dx(r) < Dy(r) ? Dx(r) : Dy(r); rad /= 2; rad -= 8; draw(screen, screen->r, back, nil, ZP); for(i=0; i<12; i++) { fillarc(screen, c, rad, rad, segs2[i], ZP, -i*30+60, 30); arc(screen, c, rad, rad, thick, segs[i], ZP, -i*30+60, 30); } line(screen, c, circlept(c, (rad*3)/4, angmin), Enddisc, Enddisc, thick, minhand, ZP); line(screen, c, circlept(c, rad/2, anghr), Enddisc, Enddisc, thick, hrhand, ZP); flushimage(display, 1); } void eresized(int new) { if(new && getwindow(display, Refnone) < 0) fprint(2,"can't reattach to window"); redraw(screen); } void main(int, char**) { Event e; Mouse m; Menu menu; char *mstr[] = {"exit", 0}; int key, timer; int t, i; if (initdraw(0, 0, "clock") < 0) sysfatal("initdraw failed"); back = display->white; hrhand = allocimage(display, Rect(0,0,1,1), RGB24, 1, 0x555555FF); minhand = hrhand; for(i=0; i<12; i++){ segs[i] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, segsi[i]); segs2[i] = allocimagemix(display, segsi[i], DWhite); } redraw(screen); einit(Emouse); t = (30*1000); timer = etimer(0, t); menu.item = mstr; menu.lasthit = 0; for(;;) { key = event(&e); if(key == Emouse) { m = e.mouse; if(m.buttons & 4) { if(emenuhit(3, &m, &menu) == 0) exits(0); } } else if(key == timer) { redraw(screen); } } }