Public feed #887037

agiofws

public cpp v1 · immutable
Raw Edit
·published 2008-02-01 02:38 UTC
rendered paste body
#include <cmath>#include <string>#include <iostream>#include <unistd.h>#include "quickcg.h"#include <stdio.h>#include <time.h>#include <sstream>#include <fstream>using namespace QuickCG;using namespace std;int getValues(const char *path){string line;int trans;ifstream myfile (path);  myfile.is_open();  getline (myfile,line);  std::istringstream is;is.str(line);  if(is >> trans)  myfile.close();  return trans;}int getcurrentValues(const int  jkl  , int &Tr1 , int &Rc1 , int &Osec){time_t mytime;struct tm *mytm;mytime=time(NULL);mytm=localtime(&mytime);Osec = mytm->tm_sec;Tr1 =  getValues("/sys/class/net/wlan0/statistics/tx_packets");Rc1 =  getValues("/sys/class/net/wlan0/statistics/rx_packets");} int geTime(int &a , int &b , int &c){time_t mytime;struct tm *mytm;//int a ,b ,c;mytime=time(NULL);mytm=localtime(&mytime);a=mytm->tm_sec;b=mytm->tm_min;c=mytm->tm_hour;if (c>12) {c=c-12;}}int drawClock(int &a , int &b , int &c ){float Secs ,Mins, Hours;int radius = 116;Secs  =  (M_PI / 30.0 * a);Mins  =  (M_PI / 30.0 * b);Hours =  (M_PI / 6.0 * c + M_PI / 360 * b );drawLine(128, 128, 128 + rint(radius * 0.8 * sin (Secs)) , 128 + rint(radius * 0.8 * -cos (Secs)) , ColorRGB(0, 255, 0));drawLine(128, 128, 128 + radius * 0.7 * sin (Mins) , 128 + rint(radius * 0.7 * -cos (Mins)) , ColorRGB(255, 0, 0));drawLine(128, 128, 128 + radius / 2  * sin (Hours) , 128 + rint(radius / 2 * -cos (Hours)) , ColorRGB(0, 0, 255));}int rotate(const int diff , int &R , int &G , int &B , int &insett2 , long unsigned &width , long unsigned &height){int radius = 116;int insett;insett = 0.08 * radius;int m=30;int l,p,ll;double Angle;double Cos;double Sin;time_t mytime;struct tm *mytm;int a ,b ,c;void geTime(int &a, int &b, int &c);void drawClock(int &a, int &b, int &c);mytime=time(NULL);mytm=localtime(&mytime);a=mytm->tm_sec;b=mytm->tm_min;c=mytm->tm_hour;if (c>12) {c=c-12;}std::vector<ColorRGB> image;loadImage(image, width, height, "clock-face.png");for (p = 1; p < diff; p=p+1){for (l = 1; l < 72*2; l=l+1){ Angle = (l * M_PI / m)+p; Cos = cos (Angle); Sin = sin (Angle);drawLine( 128 + (radius - insett) * Cos  , 128 + (radius - insett) * Sin  , 128 + radius * Cos  , 128 + radius * Sin  , ColorRGB(R , G , B));}for (ll = 0; ll < 12; ll++){ Angle = (ll * M_PI / 6); Cos = cos (Angle); Sin = sin (Angle);drawLine( 128 + (radius - insett2) * Cos  , 128 + (radius - insett2) * Sin  , 128 + radius * Cos  , 128 + radius * Sin  , ColorRGB(0 , 255 , 0));}for (int x = 0; x < width; x++)for(int y = 0; y < height; y++)  {        pset(x, y, image[x+y*width]);            //pset(x, y, image[x][y]);    }redraw();//cls();//usleep(1000000);geTime(a,b,c);drawClock(a,b,c);redraw();cls();}}int main(){int ll , a ,b ,c ,newCurrentTX , newCurrentRX , currentTX , currentRX , currentNetime , Tr1 , Tr2 , Trate , Rc1 , Rc2 , Rrate , R ,G ,B , Osec , Nsec , jkl;int radius = 116;int insett;insett = 0.08 * radius;int insett2 = 0.15 * radius;int m=30;int l,p;double Angle;double Cos;double Sin;unsigned long width ,height;screen(256, 256, 0, "clock-calculate");std::vector<ColorRGB> image;loadImage(image, width, height, "clock-face.png");getcurrentValues(jkl  ,Tr1 ,Rc1 ,Osec );currentTX = Tr1;currentRX = Rc1;//currentNetime = Osec;while(!done()){for(int x = 0; x < width; x++)for(int y = 0; y < height; y++)  {        pset(x, y, image[x+y*width]);            //pset(x, y, image[x][y]);    }geTime(a,b,c);if(a==0 || a==10 || a==20 || a==30 || a==40 || a==50 || a==55){getcurrentValues(jkl  ,Tr1 ,Rc1 ,Osec );currentTX = Tr1;currentRX = Rc1;}for (l = 1; l < 72; l=l+1){ Angle = (l * M_PI / m)+p; Cos = cos (Angle); Sin = sin (Angle);drawLine( 128 + (radius - insett) * Cos  , 128 + (radius - insett) * Sin  , 128 + radius * Cos  , 128 + radius * Sin  , ColorRGB(R , G , B));}for (ll = 0; ll < 12; ll++){ Angle = (ll * M_PI / 6); Cos = cos (Angle); Sin = sin (Angle);drawLine( 128 + (radius - insett2) * Cos  , 128 + (radius - insett2) * Sin  , 128 + radius * Cos  , 128 + radius * Sin  , ColorRGB(0 , 255 , 0));}geTime(a,b,c);usleep(10000);drawClock(a,b,c);redraw();cls(); //if (a % 2) // oddif(a==5 || a==15   || a==25   || a==35 || a==45 || a==55 || a==59)  {  getcurrentValues(jkl  ,Tr1 ,Rc1 ,Osec );  newCurrentTX = Tr1;  newCurrentRX = Rc1;  Trate = newCurrentTX - currentTX;  Rrate = newCurrentRX - currentRX;cout << "currentTX:" << currentTX << endl;cout << "currentRX:" << currentRX << endl;cout << "newCurrentTX:" << newCurrentTX << endl;cout << "newCurrentRX:" << newCurrentRX << endl;cout << "Trate:" << Trate << endl;cout << "Rrate:" << Rrate << endl;if (Rrate > Trate){ rotate(Rrate, R, G, B , insett2 , width , height);R = 255; G = 0; B = 0;}if (Rrate < Trate){ rotate(Trate, R, G, B , insett2 , width , height);R = 0; G = 255; B = 0;}if (Trate == Rrate){  rotate(30, R, G, B , insett2 , width , height) ;R = 0; G = 0; B = 255;}}}sleep();}