From 7207d01f1214cc139f861a650d9b32229df83b30 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 23 Sep 2020 10:47:25 -0700 Subject: [PATCH] Added padding --- nasu6.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/nasu6.c b/nasu6.c index dc98cd2..42ce00e 100644 --- a/nasu6.c +++ b/nasu6.c @@ -1,6 +1,8 @@ #include #include +#define PAD 32 + typedef struct Point { int x; int y; @@ -21,8 +23,8 @@ typedef struct Brush { Point prev; } Brush; -static int SCREEN_WIDTH = 512; -static int SCREEN_HEIGHT = 512; +static int SCREEN_WIDTH = 512 + PAD * 2; +static int SCREEN_HEIGHT = 512 + PAD * 2; static int FPS = 30; int ZOOM = 4; int clr = 0xFF0000; @@ -51,14 +53,30 @@ divpt(Point* p, int v) return p; } +Point* +mulpt(Point* p, int v) +{ + p->x *= v; + p->y *= v; + return p; +} + +Point* +addpt(Point* p, int v) +{ + p->x += v; + p->y += v; + return p; +} + /* noodle */ void pixel(uint32_t* dst, Point p, int c) { int x, y; - p.x *= ZOOM; - p.y *= ZOOM; + mulpt(&p, ZOOM); + addpt(&p, PAD); for(x = 0; x < ZOOM; ++x) { for(y = 0; y < ZOOM; ++y) { dst[(p.y + y) * SCREEN_WIDTH + (p.x + x)] = c; @@ -91,7 +109,7 @@ init_array(void) for(i = 0; i < SCREEN_HEIGHT; i++) for(j = 0; j < SCREEN_WIDTH; j++) - pixels[i * SCREEN_WIDTH + j] = 0xffffff; + pixels[i * SCREEN_WIDTH + j] = 0x000000; return 1; } @@ -160,6 +178,7 @@ handle_mouse(SDL_Event* event, Brush* b) case SDL_MOUSEMOTION: if(b->down) { setpt(&b->pos, event->motion.x, event->motion.y); + addpt(&b->pos, -PAD); divpt(&b->pos, ZOOM); pixel(pixels, b->pos, 0xFFFFFF); setpt(&b->prev, b->pos.x, b->pos.y);