Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "draw.h"
- #include "stdafx.h"
- #define RGB32(r, g, b) static_cast<uint32_t>((((static_cast<uint32_t>(b) << 8) | g) << 8) | r)
- void put_pixel32(SDL_Surface* surface, int x, int y, Uint32 pixel)
- {
- assert(NULL != surface);
- assert(x < SCREEN_WIDTH);
- assert(y < SCREEN_HEIGHT);
- Uint32* pixels = (Uint32*)surface->pixels;
- pixels[(y * surface->w) + x] = pixel;
- }
- Uint32 get_pixel32(SDL_Surface* surface, int x, int y)
- {
- assert(NULL != surface);
- assert(x < SCREEN_WIDTH);
- assert(y < SCREEN_HEIGHT);
- Uint32* pixels = (Uint32*)surface->pixels;
- return pixels[(y * surface->w) + x];
- }
- void draw_horizontal_line(SDL_Surface* s, int start_x, int final_x, int y, int color)
- {
- int hatch_frequncy = (SCREEN_WIDTH / (AMOUNT_HATCHS + 1));
- for (int x = start_x; x < final_x; x++)
- {
- put_pixel32(s, x, y, color);
- }
- }
- void draw_vertical_line(SDL_Surface* s, int start_y, int final_y, int x, int color)
- {
- int max = (start_y > final_y) ? start_y : final_y;
- int min = (start_y < final_y) ? start_y : final_y;
- for (int y = min; y < max; y++)
- {
- put_pixel32(s, x, y, color);
- }
- }
- void draw_horizontal_hatches(SDL_Surface* s, int start_y, int final_y, int x)
- {
- int hatch_frequncy = (SCREEN_HEIGHT / (AMOUNT_HATCHS + 1));
- for (int y = start_y; y < final_y; y++)
- {
- if (y % hatch_frequncy == 0)
- draw_horizontal_line(s, x - HATCH_LEN, x + HATCH_LEN, y, RGB(255, 255, 255));
- }
- }
- void draw_vertical_hatches(SDL_Surface* s, int start_x, int final_x, int y)
- {
- int hatch_frequncy = (SCREEN_HEIGHT / (AMOUNT_HATCHS + 1));
- for (int x = start_x; x < final_x; x++)
- {
- if (x % hatch_frequncy == 0)
- draw_vertical_line(s, y - HATCH_LEN, y + HATCH_LEN, x, RGB(255, 255, 255));
- }
- }
- void draw_angular_line(SDL_Surface* s, int start_x, int final_x, int start_y, int final_y, int color)
- {
- int amount_iterations = 8;
- int delta_y = (final_y - start_y) / amount_iterations;
- int delta_x = (final_x - start_x) / amount_iterations;
- for (int i = 0; i < amount_iterations; i++)
- {
- put_pixel32(s, start_x, start_y, color);
- start_x += delta_x;
- start_y += delta_y;
- }
- }
- void draw_first_graphic(SDL_Surface* s)
- {
- int cur_x;
- int cur_y;
- int prev_x = SCREEN_WIDTH / 2;
- int prev_y = SCREEN_HEIGHT / 2;
- for (int x = 0; x < 15; x++)
- {
- cur_x = (SCREEN_WIDTH / 2) - x * 6;
- cur_y = (SCREEN_HEIGHT / 2) - (3 * x * x);
- put_pixel32(s, cur_x, cur_y, RGB(240, 0, 178));
- draw_angular_line(s, prev_x, cur_x, prev_y, cur_y, RGB(240, 0, 178));
- prev_x = cur_x;
- prev_y = cur_y;
- }
- prev_x = SCREEN_WIDTH / 2;
- prev_y = SCREEN_HEIGHT / 2;
- for (int x = 0; x < 15; x++)
- {
- cur_x = (SCREEN_WIDTH / 2) + x * 6;
- cur_y = (SCREEN_HEIGHT / 2) - (3 * x * x);
- put_pixel32(s, cur_x, cur_y, RGB(240, 0, 178));
- draw_angular_line(s, prev_x, cur_x, prev_y, cur_y, RGB(240, 0, 178));
- prev_x = cur_x;
- prev_y = cur_y;
- }
- }
- void draw_second_graphic(SDL_Surface* s)
- {
- draw_horizontal_line(s, 0, 450, 500, RGB(0, 0, 178));
- draw_horizontal_line(s, 490, 1000, 500, RGB(0, 0, 178));
- draw_vertical_line(s, 470, 0, 470, RGB(0, 0, 178));
- draw_vertical_line(s, 470, 0, 480, RGB(0, 0, 178));
- int y = 470;
- for (int x = 470; x > 450;) {
- put_pixel32(s, x, y, RGB(0, 0, 178));
- if (x < 460) {
- x -= 2;
- y += 1;
- }
- else {
- y += 2;
- x -= 1;
- }
- }
- y = 470;
- for (int x = 480; x < 490;) {
- put_pixel32(s, x, y, RGB(0, 0, 178));
- if (x < 485) {
- x += 1;
- y += 3;
- }
- else {
- y += 2;
- x += 2;
- }
- }
- }
- void draw(SDL_Surface* s, SDL_Renderer* gRenderer)
- {
- int y;
- int x;
- draw_horizontal_line(s, 0, SCREEN_WIDTH, SCREEN_HEIGHT / 2, RGB(255, 255, 255));
- draw_vertical_line(s, 0, SCREEN_HEIGHT, SCREEN_WIDTH / 2, RGB(255, 255, 255));
- draw_horizontal_hatches(s, 0, SCREEN_HEIGHT, SCREEN_WIDTH / 2);
- draw_vertical_hatches(s, 0, SCREEN_HEIGHT, SCREEN_WIDTH / 2);
- draw_first_graphic(s);
- draw_second_graphic(s);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement