SHARE
TWEET

Untitled




Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- #include <iostream> // input/output
- #include <windows.h> // nudojam Sleep i GetStdHandle funkcijom
- #include <cmath> // naudojam sinusam kosinusam
- #include <ctime> // naudojam laikui gauti
- #define CEN_X 30 // laikrodzio centro X koordinate
- #define CEN_Y 15 // laikrodzio centro Y koordinate
- #define SIM_S "-" // kaip atrodys rodykles
- #define SIM_M "x"
- #define SIM_H "O"
- #define PI 3.14159265
- using namespace std;
- void gotoxy(int x, int y) // funkcija, kuri nukelia konsoles zymekli i xy koordinates (ne as rasiau)
- {
- COORD coord;
- coord.X = x;
- coord.Y = y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
- }
- void getxypolar(double r, double laips, int &x, int &y);
- void printcircle(double r, int xc, int yc);
- void printdigits(double r, int xc, int yc);
- void printdigitsanim(double r, int xc, int yc, double laips);
- void printarr(double l, int xc, int yc, double laips, char simb[]);
- int main()
- {
- time_t seconds;
- long lasts;
- for(;;){
- seconds = time(NULL); // gaunam laika nuo UNIX sistemos pradzios (1970-01-01 00:00)
- if(seconds!=lasts){ // ar praejo sekunde?
- system("cls");
- printcircle(14.0,CEN_X,CEN_Y); // skaiciai :D
- printdigits(12.0,CEN_X,CEN_Y); // ciferblatas (zinau kad sumaisyta :D)
- int hour, min, sek;
- hour=((seconds/3600)+3)%24; // +3 laiko zona LT (vasaros laikas)
- min=(seconds/60)%60;
- sek=seconds%60;
- printarr(12.0,30,15,sek*6,SIM_S); // sekundziu rodykle
- //printdigitsanim(12.0,CEN_X,CEN_Y,sek*6); // sekundes ratu
- printarr(10.0,CEN_X,CEN_Y,min*6+sek*0.1,SIM_M); // min rodykle
- printarr(5.0,CEN_X,CEN_Y,(hour%12)*30+min*0.5,SIM_H); // val rodykle
- gotoxy(0,0);
- cout << hour;
- if(min<10)cout <<":0"<<min; // digital laikrodzio formavimas
- else cout <<":"<<min;
- if(sek<10)cout <<":0"<<sek;
- else cout <<":"<<sek;
- lasts=seconds;
- Sleep(100); // taupom pc resursus
- }
- else Sleep(100);
- }
- system("PAUSE");
- return EXIT_SUCCESS;
- }
- void getxypolar(double r, double laips, int &x, int &y){ // apskaiciuoja x ir y koordinates is poliniu c formules
- double xco = r*cos(laips*PI/180);
- x= int(xco);
- double yco = r*sin(laips*PI/180);
- y= int(yco);
- }
- void printdigits(double r, int xc, int yc){ // ciferblatas
- double xco, yco;
- int x, y;
- for(double i=0;i<360;i++){
- getxypolar(r,i,x,y);
- gotoxy(x+xc, y+yc);
- cout << ".";
- }
- }
- void printdigitsanim(double r, int xc, int yc, double laips){ // ratu einancis sekundes
- double xco, yco;
- int x, y;
- for(double i=0;i<laips;i++){
- getxypolar(r,i-90,x,y);
- gotoxy(x+xc, y+yc);
- cout << ".";
- }
- }
- void printcircle(double r, int xc, int yc){ //skaiciai (valandos)
- double xco, yco;
- int x, y, u=1;
- for(double i=30;i<=360;i+=30){
- getxypolar(r,i-90,x,y);
- gotoxy(x+xc, y+yc);
- cout << u;
- u++;
- }
- }
- void printarr(double l, int xc, int yc, double laips, char simb[]){ // rodykliu spausdinimo funkcija
- double xco, yco;
- int x, y;
- for(double i=0;i<l;i++){
- getxypolar(i,laips-90,x,y);
- gotoxy(x+xc, y+yc);
- cout << simb;
- }
- }
RAW Paste Data