From 29b6cf4c3e95fb3dc189a67b1ff38dc812413f21 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 23 Sep 2020 09:12:46 -0700 Subject: [PATCH] Cleanup --- nasu6.c | 178 +++++--------------------------------------------------- 1 file changed, 14 insertions(+), 164 deletions(-) diff --git a/nasu6.c b/nasu6.c index f57b66a..7224c3c 100644 --- a/nasu6.c +++ b/nasu6.c @@ -24,7 +24,8 @@ typedef struct Brush { static int SCREEN_WIDTH = 512; static int SCREEN_HEIGHT = 512; static int FPS = 30; -int ZOOM = 1; +int ZOOM = 4; +int clr = 0xFF0000; uint32_t* pixels; @@ -44,63 +45,17 @@ setpt(Point* p, int x, int y) /* noodle */ -int -patt(int mode, int size, Point p) -{ - if(mode == 1) - return ((p.x + p.y) % 4) == 0 && ((p.y - p.x) % 4) == 0; - if(mode == 2) - return ((p.x + p.y) % 2) == 0 && ((p.y - p.x) % 2) == 0; - if(mode == 3) - return 1; - if(mode == 4) - return p.y % size == 0; - if(mode == 5) - return p.x % size == 0; - if(mode == 6) - return (p.x + p.y) % size == 0 || (p.x - p.y) % size == 0; - return 0; -} - -void -pixel(uint32_t* dst, Point p, int color) -{ - dst[p.y * SCREEN_WIDTH + p.x] = color; -} - -void -line(uint32_t* dst, Point p0, Point p1, int color) -{ - double dx = abs(p1.x - p0.x), sx = p0.x < p1.x ? 1 : -1; - double dy = -abs(p1.y - p0.y), sy = p0.y < p1.y ? 1 : -1; - double err = dx + dy, e2; - for(;;) { - pixel(dst, p0, color); - if(p0.x == p1.x && p0.y == p1.y) - break; - e2 = 2 * err; - if(e2 >= dy) { - err += dy; - p0.x += sx; - } - if(e2 <= dx) { - err += dx; - p0.y += sy; - } - } -} - void -fill(uint32_t* dst, int mode, int size, Point p0, int color) +pixel(uint32_t* dst, Point p, int c) { int x, y; - Point p; - for(x = 0; x < size; ++x) - for(y = 0; y < size; ++y) { - setpt(&p, p0.x + x, p0.y + y); - if(patt(mode, size, p)) - pixel(dst, p, color); + p.x *= ZOOM; + p.y *= ZOOM; + for(x = 0; x < ZOOM; ++x) { + for(y = 0; y < ZOOM; ++y) { + dst[(p.y + y) * SCREEN_WIDTH + (p.x + x)] = c; } + } } void export(uint32_t* dst) @@ -108,67 +63,6 @@ void export(uint32_t* dst) /* TODO: chr file export */ } -void -title(Brush* b) -{ - /* TODO: Format a title that includes brush mode, brush size, canvas size and offset */ - printf("mode:%d size:%d\n", b->mode, b->size); - if(b->mode == 0) - SDL_SetWindowTitle(gWindow, "noodle(line)"); - else if(b->mode == 1) - SDL_SetWindowTitle(gWindow, "noodle(tone1)"); - else if(b->mode == 2) - SDL_SetWindowTitle(gWindow, "noodle(tone2)"); - else if(b->mode == 3) - SDL_SetWindowTitle(gWindow, "noodle(full)"); - else - SDL_SetWindowTitle(gWindow, "noodle(other)"); -} - -void -move(Point* p, int x, int y) -{ - int req = 0; - if(p->x != x) { - setpt(p, x, p->y); - req = 1; - } - if(p->y != y) { - setpt(p, p->x, y); - req = 1; - } - /* TODO MOVE DRAWING - if(req) - debug(b); - */ -} - -void -select(Brush* b, int m, int s) -{ - int req = 0; - if(b->mode != m) { - b->mode = m; - req = 1; - } - if(b->size != s) { - b->size = s; - req = 1; - } - if(req) - title(b); -} - -void -zoom(void) -{ -} - -void -clean(void) -{ -} - /* SDL */ int @@ -258,10 +152,7 @@ handle_mouse(SDL_Event* event, Brush* b) case SDL_MOUSEMOTION: if(b->down) { setpt(&b->pos, event->motion.x, event->motion.y); - if(b->mode == 0) - line(pixels, b->prev, b->pos, b->erase ? 0xffffff : 0x000000); - else - fill(pixels, b->mode, b->size, b->pos, b->erase ? 0xffffff : 0x000000); + pixel(pixels, b->pos, 0xFFFFFF); setpt(&b->prev, b->pos.x, b->pos.y); } break; @@ -279,56 +170,18 @@ handle_keypress(SDL_Event* event, Brush* b, Point* o) case SDLK_e: export(pixels); break; - /* move */ - case SDLK_w: - move(o, o->x, o->y--); - break; - case SDLK_a: - move(o, o->x--, o->y); - break; - case SDLK_s: - move(o, o->x, o->y++); - break; - case SDLK_d: - move(o, o->x++, o->y); - break; - case SDLK_q: - move(o, 0, 0); - break; /* Mode */ case SDLK_1: - select(b, 0, b->size); + clr = 0; break; case SDLK_2: - select(b, 1, b->size); + clr = 1; break; case SDLK_3: - select(b, 2, b->size); + clr = 2; break; case SDLK_4: - select(b, 3, b->size); - break; - case SDLK_5: - select(b, 4, b->size); - break; - case SDLK_6: - select(b, 5, b->size); - break; - case SDLK_7: - select(b, 6, b->size); - break; - /* brush */ - case SDLK_z: - select(b, b->mode, b->size - 1); - break; - case SDLK_x: - select(b, b->mode, b->size + 1); - break; - /* Special */ - case SDLK_BACKQUOTE: - zoom(); - case SDLK_SPACE: - clean(); + clr = 3; break; } } @@ -404,9 +257,6 @@ main(int argc, char** argv) load(f); - select(&brush, 0, 10); - move(&offset, 0, 0); - /* main game loop */ while(1) {