This repository has been archived by the owner on Oct 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.cpp
67 lines (58 loc) · 2.17 KB
/
draw.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "draw.h"
#include "settings.h"
#include <SDL2/SDL.h>
#define COLORE(color) \
color[0] * 0xFF, color[1] * 0xFF, color[2] * 0xFF, color[3] * 0xFF
void DrawCircle(SDL_Renderer *renderer, int32_t centreX, int32_t centreY, int32_t radius) {
const int32_t diameter = (radius * 2);
int32_t x = (radius - 1);
int32_t y = 0;
int32_t tx = 1;
int32_t ty = 1;
int32_t error = (tx - diameter);
while (x >= y) {
// Each of the following renders an octant of the circle
SDL_RenderDrawPoint(renderer, centreX + x, centreY - y);
SDL_RenderDrawPoint(renderer, centreX + x, centreY + y);
SDL_RenderDrawPoint(renderer, centreX - x, centreY - y);
SDL_RenderDrawPoint(renderer, centreX - x, centreY + y);
SDL_RenderDrawPoint(renderer, centreX + y, centreY - x);
SDL_RenderDrawPoint(renderer, centreX + y, centreY + x);
SDL_RenderDrawPoint(renderer, centreX - y, centreY - x);
SDL_RenderDrawPoint(renderer, centreX - y, centreY + x);
if (error <= 0) {
++y;
error += ty;
ty += 2;
}
if (error > 0) {
--x;
tx += 2;
error += (tx - diameter);
}
}
}
void RenderGriglia(SDL_Renderer *renderer, unsigned int SCREEN_WIDTH, unsigned int SCREEN_HEIGHT, int scala) {
for (unsigned int i = 0; i < SCREEN_WIDTH; i = i + scala) {
if (scala > 20) {
SDL_SetRenderDrawColor(renderer, COLORE(coloreGrigliaSecondario));
int precisione = (scala / 10);
for (unsigned int z = i + precisione; z < i + scala; z += precisione) {
SDL_RenderDrawLine(renderer, z, 0, z, SCREEN_HEIGHT);
}
}
SDL_SetRenderDrawColor(renderer, COLORE(coloreGrigliaPrimario));
SDL_RenderDrawLine(renderer, i, 0, i, SCREEN_HEIGHT);
}
for (unsigned int j = 0; j < SCREEN_HEIGHT; j = j + scala) {
if (scala > 20) {
SDL_SetRenderDrawColor(renderer, COLORE(coloreGrigliaSecondario));
int precisione = (scala / 10);
for (unsigned int k = j + precisione; k < j + scala; k += precisione) {
SDL_RenderDrawLine(renderer, 0, k, SCREEN_WIDTH, k);
}
}
SDL_SetRenderDrawColor(renderer, COLORE(coloreGrigliaPrimario));
SDL_RenderDrawLine(renderer, 0, j, SCREEN_WIDTH, j);
};
}