Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <SDL.h>
- #include <iostream>
- #include <ctime>
- #include <cstdio>
- const int SCREEN_WIDTH = 700;
- const int SCREEN_HEIGHT = 800;
- const int IMAGE_WIDTH = 418;
- const int IMAGE_HEIGHT = 418;
- #define DELAY_BEFORE_EXIT 3000
- using namespace std;
- void lab_19_1() {
- SDL_Window* window = NULL;
- SDL_Surface* screenSurface = NULL;
- if (SDL_Init(SDL_INIT_VIDEO) < 0)
- {
- printf("SDL не смог запуститься! SDL_Error: %s\n", SDL_GetError());
- }
- else
- {
- window = SDL_CreateWindow(u8"Зиновьев Константин, 8 Вариант", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
- if (window == NULL)
- {
- printf("Окно не может быть создано! SDL_Error: %s\n", SDL_GetError());
- }
- else
- {
- screenSurface = SDL_GetWindowSurface(window);
- SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 255, 165, 0));
- SDL_Surface* image = SDL_LoadBMP("image.bmp");
- if (image != NULL) {
- SDL_Rect rect;
- rect.x = SCREEN_WIDTH - IMAGE_WIDTH;
- rect.y = 0;
- SDL_SetColorKey(image, SDL_TRUE, SDL_MapRGB(image->format, 255, 255, 255));
- SDL_BlitSurface(image, NULL, screenSurface, &rect);
- SDL_UpdateWindowSurface(window);
- }
- else {
- printf("Image error! SDL_Error: %s\n", SDL_GetError());
- }
- SDL_Delay(DELAY_BEFORE_EXIT);
- }
- }
- SDL_DestroyWindow(window);
- SDL_Quit();
- }
- #define LETTER_HEIGHT 50
- int draw_k_and_return_lastx(SDL_Renderer* renderer) {
- SDL_Point kletterPoint1;
- SDL_Point kletterPoint2;
- SDL_Point kletterPoint3;
- SDL_Point kletterPoint4;
- SDL_Point kletterPoint5;
- SDL_Point kletterPoint6;
- kletterPoint1.x = LETTER_HEIGHT;
- kletterPoint1.y = (SCREEN_HEIGHT / 2) - LETTER_HEIGHT;
- kletterPoint2.x = kletterPoint1.x;
- kletterPoint2.y = kletterPoint1.y + LETTER_HEIGHT;
- kletterPoint3.y = kletterPoint1.y + (LETTER_HEIGHT / 2);
- kletterPoint3.x = kletterPoint1.x;
- kletterPoint4.y = kletterPoint3.y - LETTER_HEIGHT / 2;
- kletterPoint4.x = kletterPoint3.x + LETTER_HEIGHT / 2;
- kletterPoint5.y = kletterPoint3.y + LETTER_HEIGHT / 2;
- kletterPoint5.x = kletterPoint3.x + LETTER_HEIGHT / 2;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
- SDL_RenderDrawLine(renderer, kletterPoint1.x, kletterPoint1.y, kletterPoint2.x, kletterPoint2.y);
- SDL_RenderDrawLine(renderer, kletterPoint3.x, kletterPoint3.y, kletterPoint4.x, kletterPoint4.y);
- SDL_RenderDrawLine(renderer, kletterPoint3.x, kletterPoint3.y, kletterPoint5.x, kletterPoint5.y);
- return kletterPoint5.x;
- }
- int draw_o_and_return_last_x(SDL_Renderer* renderer, int last_x) {
- int radius = LETTER_HEIGHT / 1.5;
- int countOfPoints = 10000;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
- double step = 2 * M_PI / countOfPoints;
- int max_x = INT32_MIN;
- for (float angle = 0; angle < 2 * M_PI; angle += step) {
- int x = (int)(last_x * 1.7 + radius * cos(angle));
- max_x = max(max_x, x);
- int y = (int)(SCREEN_HEIGHT / 2 - LETTER_HEIGHT / 2 + radius * sin(angle));
- SDL_RenderDrawPoint(renderer, x, y);
- }
- return max_x;
- }
- int draw_c_and_return_last_x(SDL_Renderer* renderer, int last_x) {
- int radius = LETTER_HEIGHT / 1.5;
- int countOfPoints = 10000;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
- double step = 2 * M_PI / countOfPoints;
- int max_x = INT32_MIN;
- int center_x = last_x * 1.3;
- for (float angle = 0; angle < 2 * M_PI; angle += step) {
- int x = (int)(center_x + radius * cos(angle));
- int y = (int)(SCREEN_HEIGHT / 2 - LETTER_HEIGHT / 2 + radius * sin(angle));
- if (x < center_x + 10) {
- max_x = max(max_x, x);
- SDL_RenderDrawPoint(renderer, x, y);
- }
- }
- cout << "max x is";
- cout << max_x;
- return max_x;
- }
- int draw_t_and_return_last_x(SDL_Renderer* renderer, int last_x) {
- SDL_Point tletterPoint1;
- SDL_Point tletterPoint2;
- SDL_Point tletterPoint3;
- SDL_Point tletterPoint4;
- tletterPoint1.x = LETTER_HEIGHT / 2 + last_x;
- tletterPoint1.y = (SCREEN_HEIGHT / 2) + LETTER_HEIGHT / 2.2;
- tletterPoint2.x = LETTER_HEIGHT / 2 + last_x;
- tletterPoint2.y = (SCREEN_HEIGHT / 2) - LETTER_HEIGHT * 2;
- tletterPoint3.x = tletterPoint1.x - LETTER_HEIGHT;
- tletterPoint3.y = tletterPoint2.y;
- tletterPoint4.x = tletterPoint1.x + LETTER_HEIGHT;
- tletterPoint4.y = tletterPoint2.y;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
- SDL_RenderDrawLine(renderer, tletterPoint1.x, tletterPoint1.y, tletterPoint2.x, tletterPoint2.y);
- SDL_RenderDrawLine(renderer, tletterPoint3.x, tletterPoint3.y, tletterPoint4.x, tletterPoint4.y);
- return tletterPoint4.x;
- }
- int draw_y_and_return_last_x(SDL_Renderer* renderer, int last_x) {
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
- int radius = LETTER_HEIGHT / 1.5;
- int countOfPoints = 10000;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
- double step = 2 * M_PI / countOfPoints;
- int max_x = INT32_MIN;
- int max_y = INT32_MIN;
- int center_x = last_x * 1.2;
- int center_y = SCREEN_HEIGHT / 2 - LETTER_HEIGHT * 2;
- for (float angle = 0; angle < 2 * M_PI; angle += step) {
- int x = (int)(center_x + radius * cos(angle));
- int y = (int)(center_y + radius * sin(angle));
- max_y = max(max_y, y);
- if (x < center_x + 10) {
- max_x = max(max_x, x);
- SDL_RenderDrawPoint(renderer, x, y);
- }
- }
- SDL_Point yletterPoint1;
- SDL_Point yletterPoint2;
- SDL_Point yletterPoint3;
- SDL_Point yletterPoint4;
- yletterPoint1.x = max_x;
- yletterPoint1.y = center_y - radius;
- yletterPoint2.x = yletterPoint1.x;
- yletterPoint2.y = yletterPoint1.y + LETTER_HEIGHT * 3;
- yletterPoint3.x = center_x + 10;
- yletterPoint3.y = center_y + radius;
- yletterPoint4.x = yletterPoint3.x - LETTER_HEIGHT * 1.7;
- yletterPoint4.y = yletterPoint3.y + LETTER_HEIGHT * 1.7;
- SDL_RenderDrawLine(renderer, yletterPoint1.x, yletterPoint1.y, yletterPoint2.x, yletterPoint2.y);
- SDL_RenderDrawLine(renderer, yletterPoint3.x, yletterPoint3.y, yletterPoint4.x, yletterPoint4.y);
- cout << "max x is";
- cout << max_x;
- return max_x;
- }
- void lab_20_1() {
- SDL_Window* window;
- SDL_Renderer* renderer;
- SDL_Init(SDL_INIT_VIDEO);
- window = SDL_CreateWindow("Zinoview, 2 - 1", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
- renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
- SDL_SetRenderDrawColor(renderer, 165, 165, 0, 255);
- SDL_RenderClear(renderer);
- int last_x = draw_k_and_return_lastx(renderer);
- last_x = draw_o_and_return_last_x(renderer, last_x);
- last_x = draw_c_and_return_last_x(renderer, last_x);
- last_x = draw_t_and_return_last_x(renderer, last_x);
- last_x = draw_y_and_return_last_x(renderer, last_x);
- SDL_RenderPresent(renderer);
- SDL_Delay(DELAY_BEFORE_EXIT);
- SDL_DestroyRenderer(renderer);
- SDL_DestroyWindow(window);
- SDL_Quit();
- }
- void lab_20_2() {
- int count_of_lines = -1;
- int space_between_lines = -1;
- do {
- cout << endl << "Count of lines(at least 1): ";
- cin >> count_of_lines;
- } while (count_of_lines < 1);
- do {
- cout << endl << "Space between lines in pxs(at least 1): ";
- cin >> space_between_lines;
- } while (space_between_lines < 1);
- int lines_left = count_of_lines;
- SDL_Window* window;
- SDL_Renderer* renderer;
- SDL_Init(SDL_INIT_VIDEO);
- window = SDL_CreateWindow("Zinoview, 2-2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
- renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
- SDL_RenderClear(renderer);
- for (int line = 0; line < count_of_lines; line++) {
- int start_x = line * space_between_lines;
- if (start_x > SCREEN_WIDTH) break;
- int start_y = SCREEN_HEIGHT;
- int end_x = 0;
- int end_y = SCREEN_HEIGHT - (line * space_between_lines);
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- SDL_RenderDrawLine(renderer, start_x, start_y, end_x, end_y);
- lines_left--;
- }
- int temp_lines_left = lines_left;
- for (int line = 0; line < temp_lines_left; line++) {
- int start_x = SCREEN_WIDTH - line * space_between_lines;
- if (start_x < 0) break;
- int start_y = 0;
- int end_x = SCREEN_WIDTH;
- int end_y = line * space_between_lines;
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- SDL_RenderDrawLine(renderer, start_x, start_y, end_x, end_y);
- lines_left--;
- }
- SDL_RenderPresent(renderer);
- SDL_Delay(DELAY_BEFORE_EXIT);
- SDL_DestroyRenderer(renderer);
- SDL_DestroyWindow(window);
- SDL_Quit();
- }
- double calculate_y(double x, double a, double b) {
- return a * x * x;
- }
- #define SPACE_BETWEEN_POINTS_IN_PX 20 // единичный отрезок в пикселях
- #define X_THRESHOLD_STEP_IN_PX 100
- #define Y_THRESHOLD_STEP_IN_PX 100
- void lab_20_3() {
- double a, b, x_min, x_max;
- cout << "Enter x_min: ";
- cin >> x_min;
- cout << "Enter x_max: ";
- cin >> x_max;
- cout << "Enter a: ";
- cin >> a;
- cout << "Enter b: ";
- cin >> b;
- int max_dividers_by_y = (SCREEN_HEIGHT / 2) / SPACE_BETWEEN_POINTS_IN_PX;
- int max_dividers_by_x = (SCREEN_WIDTH / 2) / SPACE_BETWEEN_POINTS_IN_PX;
- b = (int) b % max_dividers_by_y;
- x_min = (int) x_min % max_dividers_by_x;
- x_max = (int) x_max % max_dividers_by_x;
- cout << "dividers by y " << max_dividers_by_y << " dividers by x " << max_dividers_by_x << endl;
- cout << "Calculated b is " << b;
- SDL_Window* window;
- SDL_Renderer* renderer;
- SDL_Init(SDL_INIT_VIDEO);
- window = SDL_CreateWindow("Graph", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
- renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
- SDL_RenderClear(renderer);
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- SDL_RenderDrawLine(renderer, SCREEN_WIDTH / 2, 0, SCREEN_WIDTH / 2, SCREEN_HEIGHT); // axis y
- int xs = SCREEN_WIDTH / 2 - 3;
- int xk = SCREEN_WIDTH / 2 + 3;
- for (double y = 0; y < SCREEN_HEIGHT; y += SPACE_BETWEEN_POINTS_IN_PX) {
- SDL_RenderDrawLine(renderer, xs, y, xk, y); // y dividers
- }
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- SDL_RenderDrawLine(renderer, 0, SCREEN_HEIGHT / 2, SCREEN_WIDTH, SCREEN_HEIGHT / 2); // axis x
- int ys = SCREEN_HEIGHT / 2 - 3;
- int yk = SCREEN_HEIGHT / 2 + 3;
- for (double x = 0; x < SCREEN_WIDTH; x += SPACE_BETWEEN_POINTS_IN_PX) {
- SDL_RenderDrawLine(renderer, x, ys, x, yk); // x dividers
- }
- double threshold_y_min = SCREEN_HEIGHT / 2 - 10 * SPACE_BETWEEN_POINTS_IN_PX;
- double threshold_y_max = SCREEN_HEIGHT / 2 + 10 * SPACE_BETWEEN_POINTS_IN_PX;
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- for (double x = 0; x < SCREEN_WIDTH; x += X_THRESHOLD_STEP_IN_PX) {
- double xs = x;
- double xk = x + X_THRESHOLD_STEP_IN_PX / 2;
- SDL_RenderDrawLine(renderer, xs, threshold_y_min, xk, threshold_y_min); // y min treshold
- SDL_RenderDrawLine(renderer, xs, threshold_y_max, xk, threshold_y_max); // y max treshold
- }
- SDL_RenderPresent(renderer);
- double threshold_x_min = SCREEN_WIDTH / 2 + (x_min * SPACE_BETWEEN_POINTS_IN_PX);
- double threshold_x_max = SCREEN_WIDTH / 2 + (x_max * SPACE_BETWEEN_POINTS_IN_PX);
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- for (double y = 0; y < SCREEN_HEIGHT; y += Y_THRESHOLD_STEP_IN_PX) {
- double ys = y;
- double yk = y + Y_THRESHOLD_STEP_IN_PX / 2;
- SDL_RenderDrawLine(renderer, threshold_x_min, ys, threshold_x_min, yk); // x min treshold
- SDL_RenderDrawLine(renderer, threshold_x_max, ys, threshold_x_max, yk); // x max treshold
- }
- SDL_RenderPresent(renderer);
- double additional_x_for_broading = 0.0;
- for (double i = 0; i < SCREEN_WIDTH / 2; i+=0.3) {
- double x = i / SPACE_BETWEEN_POINTS_IN_PX;
- double y = SCREEN_HEIGHT / 2 - calculate_y(x, a, b) - b * SPACE_BETWEEN_POINTS_IN_PX;
- cout << y << endl;
- additional_x_for_broading += 0.1 / a;
- double screen_x_left = SCREEN_WIDTH / 2 - x - additional_x_for_broading;
- double screen_x_right = SCREEN_WIDTH / 2 + x + additional_x_for_broading;
- if (screen_x_right < threshold_x_min || screen_x_right > threshold_x_max || screen_x_left < threshold_x_min || screen_x_left > threshold_x_max || y < threshold_y_min || y > threshold_y_max) continue;
- SDL_RenderDrawPoint(renderer, screen_x_left, y);
- SDL_RenderDrawPoint(renderer, screen_x_right, y);
- }
- cout << endl << endl << "THE SECOND PART" << endl << endl;
- SDL_RenderPresent(renderer);
- SDL_Delay(DELAY_BEFORE_EXIT * 100);
- SDL_DestroyRenderer(renderer);
- SDL_DestroyWindow(window);
- SDL_Quit();
- }
- void draw_fallen_snow(SDL_Renderer* renderer, const int count) {
- SDL_Point* points = new SDL_Point[count];
- int range_x = SCREEN_WIDTH - 0 + 1;
- int range_y = SCREEN_HEIGHT - 0 + 1;
- for (int i = 0; i < count; i++) {
- SDL_Point point;
- int x = 0 + (rand() % range_x);
- int y = 0 + (rand() % range_y);
- points[i].x = x;
- points[i].y = y;
- }
- int range_extra_offset = 30 - 0 + 1;
- while (true) {
- for (int i = 0; i < count; i++) {
- SDL_Point point;
- int extra_offset = 0 + (rand() % range_extra_offset);
- int offset_by_y = extra_offset + 10;
- int new_y = points[i].y + offset_by_y;
- if (new_y > SCREEN_HEIGHT) new_y = new_y - SCREEN_HEIGHT;
- points[i].y = new_y;
- }
- SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
- SDL_RenderClear(renderer);
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
- SDL_RenderDrawPoints(renderer, points, count);
- SDL_RenderPresent(renderer);
- SDL_Delay(150);
- }
- }
- void lab_21_1() {
- srand(time(0));
- int countOfPointers;
- do {
- cout << "Enter points. Count of points should be positive(0 - to exit)" << endl;
- cout << "Enter cout of points: ";
- cin >> countOfPointers;
- if (countOfPointers == 0) break;
- if (countOfPointers > 0) {
- SDL_Window* window;
- SDL_Renderer* renderer;
- SDL_Init(SDL_INIT_VIDEO);
- window = SDL_CreateWindow("Zinoview - 3", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
- renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
- SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
- SDL_RenderClear(renderer);
- draw_fallen_snow(renderer, countOfPointers);
- SDL_DestroyRenderer(renderer);
- SDL_DestroyWindow(window);
- SDL_Quit();
- }
- } while (countOfPointers < 0);
- }
- #define CIRCLE_RADIUS 50
- #define START_X CIRCLE_RADIUS + 50
- #define START_Y CIRCLE_RADIUS + 50
- #define X_DEVIATION 3
- #define Y_DEVIATION 3
- void get_random_color(int* r, int* g, int* b) {
- (*r) = 0 + (rand() % 255);
- (*g) = 0 + (rand() % 255);
- (*b) = 0 + (rand() % 255);
- }
- int r = 0;
- int g = 0;
- int b = 0;
- void draw_circle(SDL_Renderer* renderer, double x0, double y0, bool is_random_color) {
- if(is_random_color) get_random_color(&r, &g, &b);
- double radius = CIRCLE_RADIUS;
- int countOfPoints = 300;
- SDL_SetRenderDrawColor(renderer, r, g, b, 255);
- double step = 2 * M_PI / countOfPoints;
- int max_x = INT32_MIN;
- for (float angle = 0; angle < 2 * M_PI; angle += step) {
- double x = x0 + radius * cos(angle);
- double y = y0 + radius * sin(angle);
- SDL_RenderDrawPoint(renderer, x, y);
- }
- }
- bool restart_if_is_out_of_bound(SDL_Renderer* renderer, double *curr_x, double *curr_y) {
- bool is_out_of_bound = (*curr_x) + CIRCLE_RADIUS > SCREEN_WIDTH || (*curr_x - CIRCLE_RADIUS) < 0 ||(* curr_y) < 0 || (*curr_y) + CIRCLE_RADIUS > SCREEN_HEIGHT || (*curr_y) - CIRCLE_RADIUS < 0;
- if (is_out_of_bound) {
- (*curr_x) = START_X;
- (*curr_y) = START_Y;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, (*curr_x), (*curr_y), true);
- SDL_RenderPresent(renderer);
- }
- return is_out_of_bound;
- }
- void lab_22_1() {
- srand(time(0));
- SDL_Window* window;
- SDL_Renderer* renderer;
- SDL_Init(SDL_INIT_VIDEO);
- window = SDL_CreateWindow("Zinoview, 2 - 1", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
- renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
- SDL_RenderClear(renderer);
- draw_circle(renderer, START_X, START_Y, false);
- SDL_RenderPresent(renderer);
- double curr_x = START_X;
- double curr_y = START_Y;
- SDL_Event event;
- bool quit = false;
- while(!quit)
- {
- SDL_PollEvent(&event);
- switch (event.type) {
- case SDL_QUIT: quit = true; break;
- case SDL_MOUSEBUTTONUP: {
- bool ignore_all_conditions = false;
- int mouse_x, mouse_Y;
- SDL_GetMouseState(&mouse_x, &mouse_Y);
- if (event.button.button == SDL_BUTTON_LEFT) {
- cout << "x is " << curr_x << " y is " << curr_y;
- bool is_plus_by_x = false;
- bool is_plus_by_y = false;
- if (curr_x < mouse_x) is_plus_by_x = true;
- if (curr_y < mouse_Y) is_plus_by_y = true;
- if (is_plus_by_x) {
- while (curr_x < mouse_x) {
- curr_x += X_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- if (restart_if_is_out_of_bound(renderer, &curr_x, &curr_y)) {
- ignore_all_conditions = true;
- break;
- }
- }
- }
- else {
- while (curr_x > mouse_x) {
- curr_x -= X_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- if (restart_if_is_out_of_bound(renderer, &curr_x, &curr_y)) {
- ignore_all_conditions = true;
- break;
- }
- }
- }
- if (ignore_all_conditions) break; // break from curr switch branch
- if (is_plus_by_y) {
- while (curr_y < mouse_Y) {
- curr_y += Y_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- if (restart_if_is_out_of_bound(renderer, &curr_x, &curr_y)) {
- ignore_all_conditions = true;
- break;
- }
- }
- }
- else {
- while (curr_y > mouse_Y) {
- curr_y -= Y_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- if (restart_if_is_out_of_bound(renderer, &curr_x, &curr_y)) {
- ignore_all_conditions = true;
- break;
- }
- }
- }
- }
- if (event.button.button == SDL_BUTTON_RIGHT) {
- bool curr_y_in_top_half = curr_y <= SCREEN_HEIGHT / 2 && curr_y > 0;
- bool curr_x_in_left_half = curr_x <= SCREEN_WIDTH / 2 && curr_x > 0;
- if (curr_y_in_top_half && curr_x_in_left_half) { // top left angle
- bool is_curr_x_more = false;
- bool is_curr_y_more = false;
- if (curr_x > START_X) is_curr_x_more = true;
- if (curr_y > START_Y) is_curr_x_more = true;
- while (curr_x > START_X) {
- curr_x -= X_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- while (curr_x < START_X) {
- curr_x += X_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- while (curr_y > START_Y) {
- curr_y -= Y_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- while (curr_y < START_Y) {
- curr_y += Y_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- }
- if (curr_y_in_top_half && !curr_x_in_left_half) { // top right angle
- while (curr_x > SCREEN_WIDTH - START_X) {
- curr_x -= X_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- while (curr_x < SCREEN_WIDTH - START_X) {
- curr_x += X_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- while (curr_y > START_Y) {
- curr_y -= Y_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- while (curr_y < START_Y) {
- curr_y += Y_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- }
- if (!curr_y_in_top_half && curr_x_in_left_half) { // bottom left angle
- while (curr_x > START_X) {
- curr_x -= X_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- while (curr_x < START_X) {
- curr_x += X_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- while (curr_y > SCREEN_HEIGHT - START_Y) {
- curr_y -= Y_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- while (curr_y < SCREEN_HEIGHT - START_Y) {
- curr_y += Y_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- }
- if (!curr_y_in_top_half && !curr_x_in_left_half) { // bottom right angle
- while (curr_x > SCREEN_WIDTH - START_X) {
- curr_x -= X_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- while (curr_x < SCREEN_WIDTH - START_X) {
- curr_x += X_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- while (curr_y > SCREEN_HEIGHT - START_Y) {
- curr_y -= Y_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- while (curr_y < SCREEN_HEIGHT - START_Y) {
- curr_y += Y_DEVIATION;
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
- SDL_RenderClear(renderer);
- draw_circle(renderer, curr_x, curr_y, false);
- SDL_RenderPresent(renderer);
- }
- }
- }
- break;
- }
- }
- }
- SDL_DestroyRenderer(renderer);
- SDL_DestroyWindow(window);
- SDL_Quit();
- }
- int main(int argc, char** argv)
- {
- int num_of_lab;
- do {
- cout << "Num of the task "
- << "\n 1 - Lab 19, 1 task"
- << "\n 2 - Lab 20, 1 task"
- << "\n 3 - Lab 20, 2 task"
- << "\n 4 - Lab 20, 3 task"
- << "\n 5 - Lab 21, 1 task: "
- << "\n 6 - Lab 22, 1 task: ";
- cin >> num_of_lab;
- switch (num_of_lab) {
- case 1: lab_19_1(); break;
- case 2: lab_20_1(); break;
- case 3: lab_20_2(); break;
- case 4: lab_20_3(); break;
- case 5: lab_21_1(); break;
- case 6: lab_22_1(); break;
- default:
- cout << "Num by " << num_of_lab << " cannot be found";
- break;
- }
- } while (num_of_lab != -1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement