Browse Source

Implemented cleanup

main
Devine Lu Linvega 6 years ago
parent
commit
93bd25b635
  1. 1
      README.md
  2. 77
      nasu.c

1
README.md

@ -27,6 +27,7 @@ To resume working on a tileset:
### General
- `~` Fix
- `1-7` Patterns
- `TAB` Cycle between colors
- `H` Toggle Guides

77
nasu.c

@ -36,13 +36,14 @@ char* modes[] = {
"full",
"hori",
"veri",
"exes"};
"exes",
"fixe"};
unsigned char buffer[SZ];
int colors[] = {color1, color2, color3, color4, color0};
int WIDTH = 8 * HOR * ZOOM + PAD * 2;
int HEIGHT = 8 * VER * ZOOM + PAD * 2;
int FPS = 30;
int FPS = 15;
int GUIDES = 1;
SDL_Window* gWindow = NULL;
SDL_Renderer* gRenderer = NULL;
@ -107,12 +108,27 @@ redraw(uint32_t* dst)
SDL_RenderPresent(gRenderer);
}
int
get(int x, int y)
{
int ch1, ch2;
int id = (x / 8) + (y / 8) * HOR;
int row = (y % 8) + (id * 16);
int px = x % 8;
if(row < 0 || row > SZ - 8)
return 0;
ch1 = (buffer[row] >> (7 - px)) & 1;
ch2 = (buffer[row + 8] >> (7 - px)) & 1;
return ch1 && !ch2 ? 1 : !ch1 && ch2 ? 2 : ch1 && ch2 ? 3 : 0;
}
void
write(int tx, int ty, int px, int py, int color)
put(int x, int y, int color)
{
int id = tx + ty * HOR;
int row = py + (id * 16);
if(row > SZ - 8)
int id = (x / 8) + (y / 8) * HOR;
int row = (y % 8) + (id * 16);
int px = x % 8;
if(x < 0 || y < 0 || x > 8 * HOR || y > 8 * VER || row > SZ - 8)
return;
if(color == 0) {
buffer[row] &= ~(1UL << (7 - px));
@ -129,12 +145,23 @@ write(int tx, int ty, int px, int py, int color)
}
}
void
edit(int x, int y, int color)
int
jagg(int x, int y)
{
if(x < 0 || y < 0 || x > 8 * HOR || y > 8 * VER)
return;
write(x / 8, y / 8, x % 8, y % 8, color);
int n = get(x, y + 1);
int e = get(x + 1, y);
int s = get(x, y - 1);
int w = get(x - 1, y);
int h = get(x, y);
if(h == n && h == e && h != s && h != w)
return 1;
if(h == e && h == s && h != w && h != n)
return 1;
if(h == s && h == w && h != n && h != e)
return 1;
if(h == w && h == n && h != e && h != s)
return 1;
return 0;
}
int
@ -156,7 +183,7 @@ patt(int x, int y, int mode, int size)
}
void
fill(Brush* b, int mode, int size, Point p0, int color)
fill(int mode, int size, Point p0, int color)
{
int x, y;
Point p;
@ -164,9 +191,8 @@ fill(Brush* b, int mode, int size, Point p0, int color)
for(y = -size / 2; y < size; ++y) {
setpt(&p, p0.x + x, p0.y + y);
if(patt(p.x, p.y, mode, size) && dispt(&p0, &p) < size)
edit(p.x, p.y, color);
put(p.x, p.y, color);
}
b->edit = 1;
redraw(pixels);
}
@ -177,7 +203,7 @@ line(Point* p0, Point* p1, int color)
int dy = -abs(p1->y - p0->y), sy = p0->y < p1->y ? 1 : -1;
int err = dx + dy, e2;
for(;;) {
edit(p0->x, p0->y, color);
put(p0->x, p0->y, color);
if(p0->x == p1->x && p0->y == p1->y)
break;
e2 = 2 * err;
@ -193,6 +219,20 @@ line(Point* p0, Point* p1, int color)
redraw(pixels);
}
void
fixe(int size, Point p0)
{
int x, y;
Point p;
for(x = -size / 2; x < size; ++x)
for(y = -size / 2; y < size; ++y) {
setpt(&p, p0.x + x, p0.y + y);
if(jagg(p.x, p.y))
put(p.x, p.y, 0);
}
redraw(pixels);
}
void
update(Brush* b)
{
@ -305,8 +345,10 @@ domouse(SDL_Event* event, Brush* b)
(event->motion.y - PAD) / ZOOM);
if(b->mode == 0)
line(&b->prev, &b->pos, b->erase ? 0 : b->color);
else if(b->mode == 7)
fixe(b->size, b->pos);
else
fill(b, b->mode, b->size, b->pos, b->erase ? 0 : b->color);
fill(b->mode, b->size, b->pos, b->erase ? 0 : b->color);
setpt(&b->prev, b->pos.x, b->pos.y);
}
break;
@ -336,6 +378,9 @@ dokey(SDL_Event* event, Brush* b)
case SDLK_n:
create();
break;
case SDLK_BACKQUOTE:
b->mode = 7;
break;
case SDLK_1:
b->mode = 0;
break;

Loading…
Cancel
Save