Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://yadi.sk/d/0NrF8GExlTa0XA
- #include <FL/Fl.H>
- #include <FL/Fl_Window.H>
- #include <FL/Fl_Button.H>
- #include <FL/Fl_Input.H>
- #include <FL/Fl_Output.H>
- #include <FL/Fl_Text_Display.H>
- #include <math.h>
- #include <GL/glut.h>
- #include <pthread.h>
- #include <iostream>
- Fl_Output* inp;
- Fl_Text_Display* disp;
- Fl_Button* but[9][9];
- Fl_Button* one, * two, * three, * four, * five, * six, * seven, * eight, * nine, * nol, * plus, * minus, * inc, * del, * refresh, * ravno, * c, * ac, * bleft, * bsin, * bcos, * btg, * bctg, * barcsin, * barccos, * bpow, * bsqrt, * blog, * bln, * be, * bpt, * bfibo, * bfac, * bbes1, * bbes2, * graph;
- Fl_Button* extra, * closeextra, * zap, * bsh, * bch;
- Fl_Input* extraInp;
- Fl_Window* window2, * graphwin;
- Fl_Window* window;
- int window_1, window_2;
- bool b = false;
- int K = 0;
- int q, w;
- int k1 = 1;
- int p;
- int graphint;
- double val[100];
- int valInc = 0;
- int valInt = 0;
- int valI;
- int valIntMas[256];
- char buffer[0];
- char buffer2[256];
- int lastf = 0, lastff = 0, trig = 0, valC;
- int qqq;
- bool rg = false;
- double outvalue = 0, ex1 = 0, ex2, ex3;
- int result;
- int id1, id2;
- pthread_t thread1;
- int click = 0;
- bool first = false;
- void check() {
- for (int i = buffer[strlen(buffer) - 1]; i > 0; i--)
- {
- if (i > 0 && buffer[i - 1] == '.') {
- break;
- }
- else
- if (buffer[i] == '0')
- buffer[i] = '\0';
- }
- }
- void refreshfunc(Fl_Widget* o, void*) {
- if (window_1 != 0) {
- glutHideWindow();
- glutShowWindow();
- glutSetWindow(window_1);
- glutReshapeWindow(450, 450);
- glutPositionWindow(((glutGet(GLUT_SCREEN_WIDTH)) / 2) - 225, ((glutGet(GLUT_SCREEN_HEIGHT)) / 2) - 225);
- graph->label("@<-");
- click = 1;
- }
- }
- void last() {
- if (lastf == 0)
- val[0] += atof(inp->value());
- else if (lastf == 1)
- val[0] += atof(inp->value());
- else if (lastf == 2)
- val[0] -= atof(inp->value());
- else if (lastf == 3)
- val[0] *= atof(inp->value());
- else if (lastf == 4)
- val[0] /= atof(inp->value());
- }
- void call_ac(Fl_Widget* o, void*) {
- val[0] = 0;
- lastf = 0;
- inp->value("");
- }
- bool tochka = false;
- void add_num(Fl_Widget* o, void*) {
- Fl_Button* button = (Fl_Button*)o;
- if (button->label() == ".") {
- sprintf(buffer2, "%s", inp->value());
- for (int i = 0; i < strlen(buffer2); i++)
- {
- if (buffer2[i] == '.') {
- tochka = true;
- break;
- }
- }
- }
- if (tochka == false or button->label() != ".") {
- if ((inp->value()) == 0 && (button->labelsize() != 16))
- sprintf(buffer2, "%s", button->label());
- else
- sprintf(buffer2, "%s%s", inp->value(), button->label());
- inp->value(buffer2);
- }
- tochka = false;
- }
- void del_num(Fl_Widget* o, void*) {
- sprintf(buffer2, "%s", inp->value());
- buffer2[strlen(buffer2) - 1] = 0;
- inp->value(buffer2);
- }
- void call_plus(Fl_Widget* o, void*) {
- Fl_Button* button = (Fl_Button*)o;
- if (button->label() == "-" && atof(inp->value()) == 0) {
- sprintf(buffer2, "%s", button->label());
- inp->value(buffer2);
- }
- else {
- if (button->label() != "cos" && button->label() != "sin" && button->label() != "tg" && button->label() != "ctg" && button->label() != "arcsin" && button->label() != "arccos" && button->label() != "Calc pow" && button->label() != "sqrt" && button->label() != "Calc log" && button->label() != "ln" && button->label() != "factorial" && button->label() != "bessel-1" && button->label() != "bessel-2" && button->label() != "exp" && button->label() != "fibonacci" && button->label() != "sh" && button->label() != "ch") {
- last();
- inp->value("");
- }
- if (button->label() == "+")
- lastf = 1;
- else if (button->label() == "-")
- lastf = 2;
- else if (button->label() == "X")
- lastf = 3;
- else if (button->label() == "/")
- lastf = 4;
- if (button->label() == "cos") {
- sprintf(buffer, "%f", cos(atof(inp->value())));
- check();
- inp->value(buffer);
- graphint = 2;
- }
- else if (button->label() == "sin") {
- sprintf(buffer, "%f", sin(atof(inp->value())));
- check();
- inp->value(buffer);
- graphint = 1;
- }
- else if (button->label() == "tg") {
- sprintf(buffer, "%f", sin(atof(inp->value())) / cos(atof(inp->value())));
- check();
- inp->value(buffer);
- graphint = 3;
- }
- else if (button->label() == "ctg") {
- sprintf(buffer, "%f", cos(atof(inp->value())) / sin(atof(inp->value())));
- check();
- inp->value(buffer);
- graphint = 4;
- }
- else if (button->label() == "arcsin") {
- sprintf(buffer, "%f", asin(atof(inp->value())));
- check();
- inp->value(buffer);
- graphint = 5;
- }
- else if (button->label() == "arccos") {
- sprintf(buffer, "%f", acos(atof(inp->value())));
- check();
- inp->value(buffer);
- graphint = 6;
- }
- else if (button->label() == "Calc pow") {
- sprintf(buffer, "%f", pow(atof(inp->value()), atof(extraInp->value())));
- check();
- inp->value(buffer);
- }
- else if (button->label() == "sqrt") {
- sprintf(buffer, "%f", sqrt(atof(inp->value())));
- check();
- inp->value(buffer);
- }
- else if (button->label() == "Calc log") {
- sprintf(buffer, "%f", (log10(atof(inp->value()))) / (log10(atof(extraInp->value()))));
- check();
- inp->value(buffer);
- }
- else if (button->label() == "ln") {
- sprintf(buffer, "%f", log(atof(inp->value())));
- check();
- inp->value(buffer);
- graphint = 7;
- }
- else if (button->label() == "factorial") {
- ex1 = 1;
- for (ex2 = 1; ex2 < atof(inp->value()) + 1; ex2++)
- ex1 *= ex2;
- sprintf(buffer, "%f", ex1);
- inp->value(buffer);
- }
- else if (button->label() == "bessel-1") {
- sprintf(buffer, "%f", jn((atoi(extraInp->value())), (atoi(inp->value()))));
- check();
- inp->value(buffer);
- graphint = 9;
- }
- else if (button->label() == "bessel-2") {
- sprintf(buffer, "%f", yn((atoi(extraInp->value())), (atoi(inp->value()))));
- check();
- inp->value(buffer);
- }
- else if (button->label() == "exp") {
- sprintf(buffer, "%f", exp((atof(inp->value()))));
- check();
- inp->value(buffer);
- }
- else if (button->label() == "fibonacci") {
- int a = atoi(inp->value());
- int M[a];
- M[0] = 0;
- M[1] = 1;
- for (int i = 2; i <= a; i++)
- M[i] = M[i - 2] + M[i - 1];
- inp->value("");
- for (int i = 0; i <= a; i++) {
- sprintf(buffer, "%s %i", inp->value(), M[i]);
- check();
- inp->value(buffer);
- }
- }
- else if (button->label() == "sh") {
- sprintf(buffer, "%f", sinh(atoi(inp->value())));
- check();
- inp->value(buffer);
- graphint = 11;
- }
- else if (button->label() == "ch") {
- sprintf(buffer, "%f", cosh(atoi(inp->value())));
- check();
- inp->value(buffer);
- graphint = 12;
- }
- }
- }
- float angle = 0.0f;
- float x = -320.0, n = 320.0, y;
- int count = 0;
- float* X;
- float* Y;
- double fff;
- int type = 3;
- void display()
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3f(0.0, 0.0, 0.0);
- glBegin(GL_LINES);
- glVertex2f(-600, 0);
- glVertex2f(600, 0);
- glEnd();
- glBegin(GL_LINES);
- glVertex2f(0, 600);
- glVertex2f(0, -600);
- glEnd();
- glBegin(GL_LINES);
- int k = -1;
- glBegin(GL_LINES);
- for (double i = 0; i < 600; i += 12 - M_PI / 5) {
- k++;
- if (k % 5 == 0) {
- glVertex2f(i, -16);
- glVertex2f(i, 16);
- }
- else {
- glVertex2f(i, -5);
- glVertex2f(i, 5);
- }
- }
- glEnd();
- k = -1;
- glBegin(GL_LINES);
- for (double i = 0; i > -600; i -= 12 + M_PI / 5) {
- k++;
- if (k % 5 == 0) {
- glVertex2f(i, -16);
- glVertex2f(i, 16);
- }
- else {
- glVertex2f(i, -5);
- glVertex2f(i, 5);
- }
- }
- glEnd();
- k = -1;
- glBegin(GL_LINES);
- for (double i = -600; i < 600; i += 24) {
- k++;
- if (k % 5 == 0) {
- glVertex2f(-16, i);
- glVertex2f(16, i);
- }
- else {
- glVertex2f(-5, i);
- glVertex2f(5, i);
- }
- }
- glEnd();
- glBegin(GL_LINE_STRIP);
- glColor3f(1.0, 0.0, 0.0);
- if (graphint == 1)
- for (int i = -600; i <= 600; i++) {
- float y = 120 * sin((i * M_PI / 180));
- glVertex2d(i, y);
- }
- else if (graphint == 2)
- for (int i = -600; i <= 600; i++) {
- float y = 120 * cos((i * M_PI / 180));
- glVertex2d(i, y);
- }
- else if (graphint == 3)
- for (int i = -600; i <= 600; i++) {
- float y = 120 * tan((i * M_PI / 180));
- glVertex2d(i, y);
- }
- else if (graphint == 4)
- for (int i = -600; i <= 600; i++) {
- float y = 120 * cos((i * M_PI / 180)) / sin((i * M_PI / 180));
- glVertex2d(i, y);
- }
- else if (graphint == 5)
- for (int i = -600; i <= 600; i++) {
- float y = 120 * asin((i * M_PI / 180));
- glVertex2d(i, y);
- }
- else if (graphint == 6)
- for (int i = -600; i <= 600; i++) {
- float y = 120 * acos((i * M_PI / 180));
- glVertex2d(i, y);
- }
- else if (graphint == 7)
- for (int i = -600; i <= 600; i++) {
- float y = 120 * log((i * M_PI / 180));
- glVertex2d(i, y);
- }
- else if (graphint == 8)
- for (int i = -600; i <= 600; i++) {
- float y = 120 * log10(i * M_PI / 180);
- glVertex2d(i, y);
- }
- else if (graphint == 9)
- for (int i = -600; i <= 600; i++) {
- float y = 120 * j0(i * M_PI / 180);
- glVertex2d(i, y);
- }
- else if (graphint == 10)
- for (int i = -600; i <= 600; i++) {
- float y = 120 * j1(i * M_PI / 180);
- glVertex2d(i, y);
- }
- else if (graphint == 11)
- for (int i = -600; i <= 600; i++) {
- float y = 0.120 * sinh(i * M_PI / 180);
- glVertex2d(i, y);
- }
- else if (graphint == 12)
- for (int i = -600; i <= 600; i++) {
- float y = 0.120 * cosh(i * M_PI / 180);
- glVertex2d(i, y);
- }
- glEnd();
- glFlush();
- }
- void closewindow(Fl_Widget* o, void*) {
- delete closeextra;
- delete extra;
- delete extraInp;
- window->resize(window->x(), window->y(), 415, 270);
- rg = false;
- }
- bool b1b2 = false;
- void* thread_func(void* arg) {
- //glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
- glutMainLoop();
- }
- void addwindow2(Fl_Widget* o, void*) {
- if (first == false)
- {
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
- glutInitWindowSize(450, 450);
- glutInitWindowPosition(((glutGet(GLUT_SCREEN_WIDTH)) / 2) - 225, ((glutGet(GLUT_SCREEN_HEIGHT)) / 2) - 225);
- window_1 = glutCreateWindow("Graphic");
- glClearColor(1.0, 1.0, 1.0, 1.0);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-600.0, 600.0, -600.0, 600.0, -1.0, 1.0);
- glutDisplayFunc(display);
- result = pthread_create(&thread1, NULL, thread_func, &id1);
- first = true;
- graph->label("@<-");
- }
- if (click == 0)
- click = 1;
- else if (click == 1)
- {
- click = 2;
- glutHideWindow();
- graph->label("@->");
- }
- else if (click == 2)
- {
- glutShowWindow();
- graph->label("@<-");
- click = 1;
- }
- }
- void addwindow(Fl_Widget* o, void*) {
- if (rg == true) {
- delete closeextra;
- delete extra;
- delete extraInp;
- }
- Fl_Button* button = (Fl_Button*)o;
- window->resize(window->x(), window->y(), 415, 370);
- window->begin();
- closeextra = new Fl_Button(10, 327, 395, 36, "@+58");
- extraInp = new Fl_Input(140, 282, 85, 33);
- if (button->label() == "pow") {
- extraInp->label("power");
- extra = new Fl_Button(240, 282, 90, 33, "Calc pow");
- }
- else if (button->label() == "log") {
- graphint = 8;
- extraInp->label("basis");
- extra = new Fl_Button(240, 282, 90, 33, "Calc log");
- }
- else if (button->label() == "bessel-1") {
- graphint = 9;
- extraInp->label("order");
- extra = new Fl_Button(240, 282, 90, 33, "bessel-1");
- }
- else if (button->label() == "bessel-2") {
- graphint = 10;
- extraInp->label("order");
- extra = new Fl_Button(240, 282, 90, 33, "bessel-2");
- }
- extra->color(43);
- window->end();
- window->redraw();
- extra->callback(call_plus);
- closeextra->callback(closewindow);
- rg = true;
- }
- void call_ravno(Fl_Widget* o, void*) {
- last();
- sprintf(buffer, "%f", val[0]);
- check();
- inp->value(buffer);
- }
- int main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- window = new Fl_Window(415, 270, "Calculator 3000");
- window->begin();
- ravno = new Fl_Button(180, 220, 45, 40, "=");
- ravno->color(47);
- nol = new Fl_Button(10, 220, 105, 40, "0");
- nol->color(42);
- one = new Fl_Button(10, 175, 50, 40, "1");
- one->color(42);
- two = new Fl_Button(65, 175, 50, 40, "2");
- two->color(42);
- three = new Fl_Button(120, 175, 50, 40, "3");
- three->color(42);
- four = new Fl_Button(10, 130, 50, 40, "4");
- four->color(42);
- five = new Fl_Button(65, 130, 50, 40, "5");
- five->color(42);
- six = new Fl_Button(120, 130, 50, 40, "6");
- six->color(42);
- seven = new Fl_Button(10, 85, 50, 40, "7");
- seven->color(42);
- eight = new Fl_Button(65, 85, 50, 40, "8");
- eight->color(42);
- nine = new Fl_Button(120, 85, 50, 40, "9");
- nine->color(42);
- c = new Fl_Button(65, 55, 50, 25, "c");
- c->color(106);
- c->labelcolor(FL_WHITE);
- ac = new Fl_Button(10, 55, 50, 25, "ac");
- ac->color(106);
- ac->labelcolor(FL_WHITE);
- bleft = new Fl_Button(120, 55, 50, 25, "@<-");
- bleft->color(106);
- bleft->labelcolor(FL_WHITE);
- refresh = new Fl_Button(330, 80, 45, 30, "R");
- refresh->color(43);
- refresh->labelsize(16);
- plus = new Fl_Button(180, 80, 45, 30, "+");
- plus->color(51);
- plus->labelsize(18);
- minus = new Fl_Button(180, 115, 45, 30, "-");
- minus->color(51);
- minus->labelsize(28);
- minus->labelcolor(8);
- inc = new Fl_Button(180, 150, 45, 30, "X");
- inc->color(51);
- del = new Fl_Button(180, 185, 45, 30, "/");
- del->color(51);
- disp = new Fl_Text_Display(259, 75, 65, 10);
- disp->label("TURBO CALC 3000 PRO №1");
- disp->box(FL_NO_BOX);
- disp->labeltype(FL_ENGRAVED_LABEL);
- inp = new Fl_Output(10, 11, 396, 41);
- inp->color(51);
- inp->labeltype(FL_EMBOSSED_LABEL);
- inp->align(10);
- inp->textsize(18);
- bsin = new Fl_Button(230, 80, 45, 30, "sin");
- bsin->color(44);
- bcos = new Fl_Button(230, 115, 45, 30, "cos");
- bcos->color(43);
- btg = new Fl_Button(230, 150, 45, 30, "tg");
- btg->color(43);
- bctg = new Fl_Button(230, 185, 45, 30, "ctg");
- bctg->color(43);
- bfibo = new Fl_Button(230, 220, 70, 18, "fibonacci");
- bfibo->color(54);
- bfibo->labelsize(12);
- bfac = new Fl_Button(230, 242, 70, 18, "factorial");
- bfac->color(55);
- bfac->labelsize(12);
- bbes1 = new Fl_Button(305, 220, 70, 18, "bessel-1");
- bbes1->color(55);
- bbes1->labelsize(12);
- bbes2 = new Fl_Button(305, 242, 70, 18, "bessel-2");
- bbes2->color(55);
- bbes2->labelsize(12);
- bsqrt = new Fl_Button(280, 185, 45, 30, "sqrt");
- bsqrt->color(53);
- bpow = new Fl_Button(280, 150, 45, 30, "pow");
- bpow->color(53);
- barcsin = new Fl_Button(280, 80, 45, 30, "arcsin");
- barcsin->color(43);
- barcsin->labelsize(12);
- barccos = new Fl_Button(280, 115, 45, 30, "arccos");
- barccos->color(43);
- barccos->labelsize(12);
- blog = new Fl_Button(330, 115, 45, 30, "log");
- bln = new Fl_Button(330, 150, 45, 30, "ln");
- be = new Fl_Button(330, 185, 45, 30, "exp");
- zap = new Fl_Button(120, 220, 50, 40, ".");
- zap->labelsize(22);
- zap->color(42);
- graph = new Fl_Button(383, 80, 23, 100);
- graph->label("@->");
- bsh = new Fl_Button(383, 185, 23, 35);
- bsh->label("sh");
- bch = new Fl_Button(383, 225, 23, 35);
- bch->label("ch");
- window->end();
- ravno->shortcut('=');
- nol->shortcut('0');
- one->shortcut('1');
- two->shortcut('2');
- three->shortcut('3');
- four->shortcut('4');
- five->shortcut('5');
- six->shortcut('6');
- seven->shortcut('7');
- eight->shortcut('8');
- nine->shortcut('9');
- refresh->shortcut('r');
- plus->shortcut('+');
- minus->shortcut('-');
- inc->shortcut('*');
- del->shortcut('/');
- nol->callback(add_num);
- one->callback(add_num);
- two->callback(add_num);
- three->callback(add_num);
- four->callback(add_num);
- five->callback(add_num);
- six->callback(add_num);
- seven->callback(add_num);
- eight->callback(add_num);
- nine->callback(add_num);
- plus->callback(call_plus);
- minus->callback(call_plus);
- inc->callback(call_plus);
- del->callback(call_plus);
- bcos->callback(call_plus);
- bsin->callback(call_plus);
- btg->callback(call_plus);
- bctg->callback(call_plus);
- barcsin->callback(call_plus);
- barccos->callback(call_plus);
- bsqrt->callback(call_plus);
- blog->callback(addwindow);
- bln->callback(call_plus);
- bpow->callback(addwindow);
- ravno->callback(call_ravno);
- ac->callback(call_ac);
- bfac->callback(call_plus);
- bbes1->callback(addwindow);
- bbes2->callback(addwindow);
- be->callback(call_plus);
- bfibo->callback(call_plus);
- bleft->callback(del_num);
- c->callback(del_num);
- refresh->callback(refreshfunc);
- bsh->callback(call_plus);
- bch->callback(call_plus);
- graph->callback(addwindow2);
- zap->callback(add_num);
- window->show();
- return Fl::run();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement