// Analog Clock @cid "YGac"; @name "analogClock"; @dbname "analogClock"; #define pi 3.1415926535 int osx = 80, osy = 80, omx = 80, omy = 80, ohx = 80, ohy = 80; /*********************************** * Menu code * ***********************************/ openmenu(); int runmenu(); closemenu(); selItem(int); showAbout(); runAbout(); openmenu() { saveg(); textalign(00); rect(0, 0, 0, 160, 15, 0); frame2(1, 1, 1, 158, 13, 1, 2); textattr(1, 0, 0); rect(1, 5, 1, 36, 15, 0); text(7, 1, "Menu"); textattr(1, 1, 0); rect(0, 5, 14, 50, 40, 0); frame(1, 6, 14, 49, 36, 0); line(1, 6, 37, 48, 37); line(1, 50, 15, 50, 35); text(8, 14, "About"); text(8, 25, "Quit"); } runmenu() { int run = 1, oldMenuSel, menuSel; do { switch(event(1)) { case 2: // pen down if((penx() > 50)||(peny() > 36)||(peny() < 15)) run = 0; else { menuSel = oldMenuSel = (peny() - 15) / 11; selItem(menuSel); } break; case 3: // pen up if((penx() > 48)||(peny() < 15)||(peny() > 35)) { selItem(menuSel); break; } else if(menuSel == 0) { showAbout(); runAbout(); run = 0; } else return 0; break; case 4: // pen move if((((peny() - 15) / 11) > 1)||(((peny() - 15) / 11) < 0)) break; oldMenuSel = menuSel; menuSel = (peny() - 15) / 11; if(oldMenuSel != menuSel) { selItem(oldMenuSel); selItem(menuSel); } break; default: run = 0; break; } } while(run); return 1; } closemenu() { textalign(02); textattr(0, 2, 0); restoreg(); } // (un)Highlight menu item selItem(int i) { rect(3, 6, 14 + 11 * i, 49, 25 + 11 * i, 0); } showAbout() { int i; string msg[12]; msg[0] = "This program was written for"; msg[1] = "the open-source community."; msg[2] = ""; msg[3] = "Its distributed under the"; msg[4] = "MIT licensing agreement."; msg[5] = ""; msg[6] = "It uses no external libraries except"; msg[7] = "the built-in PocketC libraries."; rect(0, 0, 0, 160, 160, 0); frame2(1, 2, 2, 158, 158, 3, 2); rect(1, 2, 2, 158, 15, 2); textattr(1, 0, 0); textalign(01); text(80, 2, "About this clock"); frame(1, 5, 143, 38, 155, 4); textalign(00); textattr(0, 1, 0); text( 11, 143, "Done" ); for(i = 0; i < 8; i++) text(8, 20 + i * 10, msg[i]); } runAbout() { int run = 1, pdwn = 0; do { switch(event(0)) { //5, 143, 38, 155 case 2: if((penx() > 4)&&(penx() < 39)&&(peny() > 142)&&(penx() < 156)) { rect(3, 5, 143, 38, 155, 4); pdwn = 1; } break; case 3: if((penx() > 4)&&(penx() < 39)&&(peny() > 142)&&(penx() < 156)&&pdwn) run = 0; pdwn = 0; break; case 4: if(pdwn == 1) { if((penx() < 5)||(penx() > 38)||(peny() < 141)||(penx() > 155)) { rect(3, 5, 143, 38, 155, 4); pdwn = 2; } } else if((pdwn == 2)&&((penx() > 4)&&(penx() < 39)&&(peny() > 142)&&(penx() < 156))) { rect(3, 5, 143, 38, 155, 4); pdwn = 1; } break; } } while(run); } /*********************************** * Main code * ***********************************/ init(); redraw(); drawtime(); drawclock(); main() { int run = 1; init(); do { redraw(); switch(event(85)) { case 3: if((penx() > 65)||(peny() > 13)) break; case 11: openmenu(); run = runmenu(); closemenu(); break; } } while(run); exit(); } redraw() { drawtime(); drawclock(); } drawclock() { int tm, mn, sc; float hr; int sx, sy, mx, my, hx, hy; tm = time(2); mn = (tm / 100) % 100; hr = tm / 10000 + (float)((float)mn / 60); sc = tm % 100; sx = 80 + 47 * cos((float)(sc * (pi / 30)) - pi/2); sy = 87 + 47 * sin((float)(sc * (pi / 30)) - pi/2); mx = 80 + 47 * cos((float)(mn * (pi / 30)) - pi/2); my = 87 + 47 * sin((float)(mn * pi / 30) - pi/2); hx = 80 + 32 * cos((float)(hr * pi / 6) - pi/2); hy = 87 + 32 * sin((float)(hr * pi / 6) - pi/2); line(0, 80, 87, ohx, ohy); line(0, 80, 87, omx, omy); line(0, 80, 87, osx, osy); line(1, 80, 87, hx, hy); line(1, 80, 87, mx, my); line(1, 80, 87, sx, sy); ohx = hx; ohy = hy; omx = mx; omy = my; osx = sx; osy = sy; } drawtime() { int tme; string hr, min, sec; tme = time(2); hr = (tme / 10000) % 12; if(hr == "0") hr = "12"; if((tme / 100) % 100 < 10) min = "0" + (tme / 100) % 100; else min = (tme / 100) % 100; if(tme % 100 < 10) sec = "0" + tme % 100; else sec = tme % 100; text(160, 3, " " + hr + ":" + min + ":" + sec + " "); } init() { int i, x, y; int tm, hr, mn, sc; graph_on(); title("Analog Clock"); textalign(11); textattr(0, 1, 0); for(i = 1; i < 13; i++) { x = 80 + 50 * cos((float)(i * (float)(pi / (float)6)) - (float)pi/2); y = 87 + 50 * sin((float)(i * (float)(pi / (float)6)) - (float)pi/2); pixel(1, x, y); x = 80 + 60 * cos((float)(i * (float)(pi / (float)6)) - (float)pi/2); y = 87 + 60 * sin((float)(i * (float)(pi / (float)6)) - (float)pi/2); text(x, y, i); } hookmenu(1); textalign(02); textattr(0, 2, 0); drawtime(); frame(1, 29, 36, 131, 138, 50); frame(1, 15, 22, 145, 153, 65); frame2(1, 15, 22, 145, 153, 3, 1); }