From aca708aa91f9db51a69f27e3e855b24144bd26ed Mon Sep 17 00:00:00 2001 From: Juan Manuel Tomas Date: Thu, 20 Jan 2022 05:18:00 -0300 Subject: Make mask brush a circle --- main.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 9d53b94..407a1cd 100644 --- a/main.c +++ b/main.c @@ -4,9 +4,12 @@ #include "platform.c" void PaintMask(float *mask, float x, float y, float color, float size) { - for (int j = y - size / 2; j < y + size / 2; j++) { - for (int i = x - size / 2; i < x + size / 2; i++) { - if (i > 0 && i < WINDOW_W && j > 0 && j < WINDOW_H) { + for (int j = y - size; j < y + size; j++) { + for (int i = x - size; i < x + size; i++) { + float dj = y - j; + float di = x - i; + if (i > 0 && i < WINDOW_W && j > 0 && j < WINDOW_H + && dj * dj + di * di <= size * size / 2) { size_t index = i + j * WINDOW_W; mask[index] = color; } @@ -41,7 +44,7 @@ void GameMain() { } int mouse_x, mouse_y; Uint32 mouse_state = SDL_GetMouseState(&mouse_x, &mouse_y); - float size = 100; + float size = 20; if (mouse_state & SDL_BUTTON_LMASK) { PaintMask(mask, mouse_x, WINDOW_H - mouse_y, 1.0, size); } else if (mouse_state & SDL_BUTTON_RMASK) { -- cgit v1.2.3