Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ФАЙЛ 1
- // 75 75 50 0 255 0
- // ФАЙЛ 2
- // 125 125 75 0 255 0
- // ФАЙЛ 3
- // 75 75 50
- // 60 60 28
- // 0 255 0
- // ConsoleApplication1.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <windows.h>
- #include <windowsx.h>
- #include <conio.h>
- #include <iostream>
- struct Circle {
- int centerX, centerY;
- int radius;
- };
- int isValidCircle(struct Circle* circle, RECT* rt) {
- if (circle->centerX - circle->radius < 0 || circle->centerY - circle->radius < 0 ||
- circle->centerX + circle->radius > rt->right || circle->centerY + circle->radius > rt->bottom) {
- printf_s("Error: Out of window.");
- return false;
- }
- return true;
- }
- void drowUnpaintedCircle(HDC* hdc, RECT* rt, FILE* input) {
- struct Circle circle;
- fscanf_s(input, "%d %d %d", &circle.centerX, &circle.centerY, &circle.radius);
- if (!isValidCircle(&circle, rt)) return;
- // Создаем перо и говорим, что будем рисовать этим пером
- int color[3];
- fscanf_s(input, "%d %d %d", &color[0], &color[1], &color[2]);
- HPEN pen = SelectPen(*hdc, CreatePen(PS_SOLID, 1, RGB(color[0], color[1], color[2])));
- HBRUSH brush = SelectBrush(*hdc, CreateSolidBrush(RGB(0, 0, 0))); // Фон
- Ellipse(*hdc, circle.centerX - circle.radius, circle.centerY - circle.radius, circle.centerX + circle.radius, circle.centerY + circle.radius);
- // удаляем красное перо
- DeletePen(pen);
- // удаляем зеленую кисть
- DeleteBrush(brush);
- }
- void drowPaintedCircle(HDC* hdc, RECT* rt, FILE* input) {
- struct Circle circle;
- fscanf_s(input, "%d %d %d", &circle.centerX, &circle.centerY, &circle.radius);
- if (!isValidCircle(&circle, rt)) return;
- // Создаем перо и говорим, что будем рисовать этим пером
- int color[3];
- fscanf_s(input, "%d %d %d", &color[0], &color[1], &color[2]);
- HPEN pen = SelectPen(*hdc, CreatePen(PS_SOLID, 1, RGB(color[0], color[1], color[2])));
- HBRUSH brush = SelectBrush(*hdc, CreateSolidBrush(RGB(color[0], color[1], color[2]))); // Фон
- Ellipse(*hdc, circle.centerX - circle.radius, circle.centerY - circle.radius, circle.centerX + circle.radius, circle.centerY + circle.radius);
- // удаляем красное перо
- DeletePen(pen);
- // удаляем зеленую кисть
- DeleteBrush(brush);
- }
- void drowTwoCircle(HDC* hdc, RECT* rt, FILE* input) {
- struct Circle circle;
- fscanf_s(input, "%d %d %d", &circle.centerX, &circle.centerY, &circle.radius);
- if (!isValidCircle(&circle, rt)) return;
- struct Circle circle2;
- fscanf_s(input, "%d %d %d", &circle2.centerX, &circle2.centerY, &circle2.radius);
- if (!isValidCircle(&circle, rt)) return;
- double distance = sqrt((circle.centerX - circle2.centerX) * (circle.centerX - circle2.centerX) +
- (circle.centerY - circle2.centerY) * (circle.centerY - circle2.centerY));
- if (circle.radius < (circle2.radius + distance)) {
- printf("Ne vlozen!");
- return;
- }
- HBRUSH brush;
- int color[3];
- fscanf_s(input, "%d %d %d", &color[0], &color[1], &color[2]);
- HPEN pen = SelectPen(*hdc, CreatePen(PS_SOLID, 1, RGB(color[0], color[1], color[2])));
- brush = SelectBrush(*hdc, CreateSolidBrush(RGB(color[0], color[1], color[2]))); // Фон
- Ellipse(*hdc, circle.centerX - circle.radius, circle.centerY - circle.radius, circle.centerX + circle.radius, circle.centerY + circle.radius);
- brush = SelectBrush(*hdc, CreateSolidBrush(RGB(0, 0, 0))); // Фон
- Ellipse(*hdc, circle2.centerX - circle2.radius, circle2.centerY - circle2.radius, circle2.centerX + circle2.radius, circle2.centerY + circle2.radius);
- }
- void main() {
- setlocale(LC_ALL, "Russian");
- // получаем идентификатор окна
- HWND hwnd = GetConsoleWindow();
- // получаем контекст отображения
- HDC hdc = GetDC(hwnd);
- RECT rt;
- // получаем размер окна
- GetClientRect(hwnd, &rt);
- printf("Choose programm (1, 2, 3):");
- int answer = _getch();
- FILE* input;
- switch (answer) {
- case '1':
- system("cls");
- input = fopen("1.txt", "r");
- drowUnpaintedCircle(&hdc, &rt, input);
- break;
- case '2':
- system("cls");
- input = fopen("2.txt", "r");
- drowPaintedCircle(&hdc, &rt, input);
- break;
- case '3':
- system("cls");
- input = fopen("3.txt", "r");
- drowTwoCircle(&hdc, &rt, input);
- break;
- default:
- printf("Not found!");
- break;
- }
- _getch();
- // освобождаем контекст отображения
- ReleaseDC(hwnd, hdc);
- return;
- }
Advertisement