Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _win32_winnt 0x500
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <conio.h>
- #include <windows.h>
- using namespace std;
- int menu();
- void drawGraph();
- void drawImage();
- HANDLE hStdOut;
- HWND hwnd;
- HDC hdc;
- POINT pointTop;
- POINT pointBottom;
- POINT pointLeft;
- POINT pointRight;
- int main()
- {
- SetConsoleTitleA("Lab Graphics");
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdOut, BACKGROUND_BLUE | FOREGROUND_RED);
- system("CLS");
- int answer = menu();
- switch (answer)
- {
- case 0: drawImage(); break;
- case 1: cout << "2" << endl; break;
- case 2: cout << "3" << endl; break;
- case 3: cout << "4" << endl; return 0;
- }
- system("pause");
- return 0;
- }
- int menu() {
- int key = 0;
- int code;
- do {
- system("cls");
- key = (key + 4) % 4;
- if (key == 0)
- {
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdOut, 228);
- cout << "-> Draw a picture" << endl;
- }
- else
- {
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdOut, 28);
- cout << " Draw a picture" << endl;
- }
- if (key == 1)
- {
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdOut, 228);
- cout << "-> Draw a graph" << endl;
- }
- else
- {
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdOut, 28);
- cout << " Draw a graph" << endl;
- }
- if (key == 2)
- {
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdOut, 228);
- cout << "-> Draw a picture step-by-step" << endl;
- }
- else
- {
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdOut, 28);
- cout << " Draw a picture step-by-step" << endl;
- }
- if (key == 3)
- {
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdOut, 228);
- cout << "-> Exit" << endl;
- }
- else
- {
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdOut, 28);
- cout << " Exit" << endl;
- }
- code = _getch();
- if (code == 80) key++;
- if (code == 72) key--;
- } while (code != 13);
- system("cls");
- return key;
- }
- void drawImage() {
- pointTop.x = 500;
- pointTop.y = 35;
- pointRight.x = 580;
- pointRight.y = 315;
- pointBottom.x = 500;
- pointBottom.y = 570;
- pointLeft.x = 420;
- pointLeft.y = 315;
- POINT *rhomb = new POINT[4];
- rhomb[0] = pointTop;
- rhomb[1] = pointRight;
- rhomb[2] = pointBottom;
- rhomb[3] = pointLeft;
- HWND hwnd = GetConsoleWindow();
- HDC hdc = GetDC(hwnd); //получаем DC(контекст устройства) для рисования
- HPEN hpen1; //объявляем объект перо
- HGDIOBJ hpenOld, hbrushOld;
- HBRUSH hbrush; //объявляем кисть
- hpen1 = CreatePen(PS_SOLID, 2, RGB(0, 0, 255)); //логическое перо с заданным стилем, шириной и цветом
- hpenOld = (HPEN)SelectObject(hdc, hpen1);
- MoveToEx(hdc, 500, 15, NULL);//устанавливает текущей позицией указанную точку
- LineTo(hdc, 590, 315);
- LineTo(hdc, 500, 585);
- LineTo(hdc, 410, 315);
- LineTo(hdc, 500, 15);
- hpen1 = CreatePen(PS_SOLID, 7, RGB(255, 255, 255)); //логическое перо с заданным стилем, шириной и цветом
- hpenOld = (HPEN)SelectObject(hdc, hpen1);
- hbrush = CreateSolidBrush(RGB(0, 0, 255));
- hbrushOld = (HBRUSH)SelectObject(hdc, hbrush);
- Polygon(hdc, rhomb, 4);
- MoveToEx(hdc, 495, 240, NULL);
- hpen1 = CreatePen(PS_SOLID, 8, RGB(255, 255, 255)); //логическое перо с заданным стилем, шириной и цветом
- hpenOld = (HPEN)SelectObject(hdc, hpen1);
- LineTo(hdc, 495, 345);//вертикальная вниз
- LineTo(hdc, 482, 355);//петля(влево вниз)
- LineTo(hdc, 470, 345);//петля(влево вверх)
- LineTo(hdc, 482, 335);//петля(вправо вверх)
- LineTo(hdc, 508, 355);//петля(вправо вниз)
- LineTo(hdc, 515, 355);
- LineTo(hdc, 523, 352);//ду спра
- LineTo(hdc, 541, 335);//га ва
- LineTo(hdc, 547, 325);
- LineTo(hdc, 549, 315);
- LineTo(hdc, 550, 290);//pryamaya na duge
- LineTo(hdc, 550, 276);
- LineTo(hdc, 536, 255);//вертикальная вверх
- LineTo(hdc, 525, 245);//дуга
- LineTo(hdc, 510, 239);//вверху
- LineTo(hdc, 480, 242);//горизонтальная влево
- LineTo(hdc, 471, 253);//конечная дуга
- LineTo(hdc, 464, 267);//справа налево
- LineTo(hdc, 464, 275);
- DeleteObject(hpen1);
- getchar();
- }
- void strelka(double x, double y, double size, bool scale)
- {
- if (scale == 0) {
- MoveToEx(hdc, x, y + size, NULL);
- LineTo(hdc, x, y - size);
- LineTo(hdc, x + size, y);
- LineTo(hdc, x, y + size);
- }
- else {
- MoveToEx(hdc, x - size, y, NULL);
- LineTo(hdc, x, y - size);
- LineTo(hdc, x + size, y);
- LineTo(hdc, x - size, y);
- }
- }
- WORD colorConvertTo(int ForgC, int BackC)
- {
- return ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
- }
- WORD workWindowAttributes = colorConvertTo(15, 9); //158
- void drawGraph() {
- double x, y;
- HDC dc = GetDC(hwnd);
- RECT clientRect; // координаты прямоугольника
- GetClientRect(hwnd, &clientRect);
- HPEN Pen = CreatePen(PS_SOLID, 3, RGB(255, 0, 0));
- HPEN PenCross = CreatePen(PS_SOLID, 3, RGB(255, 255, 255));
- SelectObject(hdc, Pen);
- int xScale = 50, yScale = 50;
- double sizeW = 900;
- double sizeH = 600;
- char *number = new char[15];
- double sizeStrelka = 6;
- SelectObject(hdc, PenCross);
- MoveToEx(hdc, 30, sizeH / 2, NULL);
- LineTo(hdc, sizeW - 30, sizeH / 2);
- strelka(sizeW - 30, sizeH / 2, 5, 0);
- MoveToEx(hdc, sizeW / 2, 40, NULL);
- LineTo(hdc, sizeW / 2, sizeH);
- strelka(sizeW / 2, 40, 5, 1);
- int xO = sizeW / 2, yO = sizeH / 2;
- //metki
- HDC THDC = GetDC(GetConsoleWindow());
- SetBkMode(THDC, TRANSPARENT);
- SetTextColor(THDC, RGB(255, 255, 255));
- SetConsoleTextAttribute(hStdOut, workWindowAttributes);
- strcpy(number, "X");
- TextOut(THDC, sizeW - 10, sizeH / 2, number, strlen(number));
- strcpy(number, "Y");
- TextOut(THDC, sizeW / 2 + 10, 20, number, strlen(number));
- strcpy(number, "y=e^x");
- TextOut(THDC, sizeW / 2 + 60, 20, number, strlen(number));
- for (int i = 50; i <= sizeH; i += yScale)
- {
- MoveToEx(hdc, sizeW / 2 - 10, i, NULL);
- LineTo(hdc, sizeW / 2 + 10, i);
- _itoa(-(i / 50) + 6, number, 10);
- TextOut(THDC, sizeW / 2 + 15, i, number, strlen(number));
- }
- for (int i = 50; i <= sizeW - 30; i += xScale)
- {
- MoveToEx(hdc, i, sizeH / 2 - 10, NULL);
- LineTo(hdc, i, sizeH / 2 + 10);
- _itoa((i / 50) - 9, number, 10);
- TextOut(THDC, i + 5, sizeH / 2 - 25, number, strlen(number));
- }
- SelectObject(hdc, Pen);
- float xBeg = -9, xEnd = 1.6;
- while ((exp(xBeg))*yScale + yO <= 40)
- {
- xBeg += 0.01;
- }
- MoveToEx(hdc, xO + xScale * xBeg, yO + yScale * -exp(xBeg), NULL);
- for (x = xBeg; x <= xEnd; x += 0.01)
- {
- LineTo(hdc, xO + xScale * x, yO + yScale * -exp(x));
- }
- DeleteObject(Pen);
- DeleteObject(PenCross);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement